mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00

Fixes #5256 This updates the macOS apprt to implement the `OPEN_URL` apprt action to use the NSWorkspace APIs instead of the `open` command line utility. As part of this, we removed the `ghostty_config_open` libghostty API and instead introduced a new `ghostty_config_open_path` API that returns the path to open, and then we use the `NSWorkspace` APIs to open it (same function as the `OPEN_URL` action).
30 lines
1.4 KiB
Swift
30 lines
1.4 KiB
Swift
import AppKit
|
|
import UniformTypeIdentifiers
|
|
|
|
extension NSWorkspace {
|
|
/// Returns the URL of the default text editor application.
|
|
/// - Returns: The URL of the default text editor, or nil if no default text editor is found.
|
|
var defaultTextEditor: URL? {
|
|
defaultApplicationURL(forContentType: UTType.plainText.identifier)
|
|
}
|
|
|
|
/// Returns the URL of the default application for opening files with the specified content type.
|
|
/// - Parameter contentType: The content type identifier (UTI) to find the default application for.
|
|
/// - Returns: The URL of the default application, or nil if no default application is found.
|
|
func defaultApplicationURL(forContentType contentType: String) -> URL? {
|
|
return LSCopyDefaultApplicationURLForContentType(
|
|
contentType as CFString,
|
|
.all,
|
|
nil
|
|
)?.takeRetainedValue() as? URL
|
|
}
|
|
|
|
/// Returns the URL of the default application for opening files with the specified file extension.
|
|
/// - Parameter ext: The file extension to find the default application for.
|
|
/// - Returns: The URL of the default application, or nil if no default application is found.
|
|
func defaultApplicationURL(forExtension ext: String) -> URL? {
|
|
guard let uti = UTType(filenameExtension: ext) else { return nil}
|
|
return defaultApplicationURL(forContentType: uti.identifier)
|
|
}
|
|
}
|