macOS: switch to using URL instead of String

pull/7292/head
Bryan Lee 2025-05-09 10:48:58 +08:00
parent 3043012c1b
commit 800054874e
No known key found for this signature in database
GPG Key ID: AA16937A2AEBADF1
1 changed files with 10 additions and 13 deletions

View File

@ -36,30 +36,27 @@ class ServiceProvider: NSObject {
error.pointee = Self.errorNoString
return
}
let filePaths = objs.map { $0.path }.compactMap { $0 }
let urlObjects = objs.map { $0 as URL }
openTerminal(filePaths, target: target)
openTerminal(urlObjects, target: target)
}
private func openTerminal(_ paths: [String], target: OpenTarget) {
private func openTerminal(_ urls: [URL], target: OpenTarget) {
guard let delegateRaw = NSApp.delegate else { return }
guard let delegate = delegateRaw as? AppDelegate else { return }
let terminalManager = delegate.terminalManager
for path in paths {
// We only open in directories.
var isDirectory = ObjCBool(true)
guard FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory) else { continue }
var workingDirectory = path
if !isDirectory.boolValue {
workingDirectory = (path as NSString).deletingLastPathComponent
guard FileManager.default.fileExists(atPath: workingDirectory, isDirectory: &isDirectory), isDirectory.boolValue else { continue }
let uniqueCwds: Set<URL> = Set(
urls.map { url -> URL in
// We only open in directories.
url.hasDirectoryPath ? url : url.deletingLastPathComponent()
}
)
for cwd in uniqueCwds {
// Build our config
var config = Ghostty.SurfaceConfiguration()
config.workingDirectory = workingDirectory
config.workingDirectory = cwd.path(percentEncoded: false)
switch (target) {
case .window: