Repository Public
1import Foundation2import WorkspaceCore34/// `nexterm://` URLs (registered in Info.plist) for notifications, scripts and other apps.5/// nexterm://pane/<pane-uuid> reveal a pane6/// nexterm://ssh/<alias>?tmux=<name> connect to a configured host in a new tab7/// nexterm://claude?dir=<path> start a Claude session (optional directory)8/// nexterm://mission-control open Mission Control9/// Only configured host aliases are accepted; nothing in a URL is ever passed to a shell.10enum DeepLink: Equatable {11 case pane(PaneID)12 case ssh(alias: String, tmux: String?)13 case claude(directory: String?)14 case missionControl1516 init?(url: URL) {17 guard url.scheme?.lowercased() == "nexterm" else { return nil }18 let host = url.host?.lowercased() ?? ""19 let path = url.pathComponents.filter { $0 != "/" }20 let query = Dictionary((URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems ?? []).compactMap { i in i.value.map { (i.name, $0) } }, uniquingKeysWith: { a, _ in a })21 switch host {22 case "pane":23 guard let raw = path.first, let uuid = UUID(uuidString: raw) else { return nil }24 self = .pane(PaneID(rawValue: uuid))25 case "ssh":26 guard let alias = path.first, !alias.isEmpty, alias.count < 128 else { return nil }27 self = .ssh(alias: alias, tmux: query["tmux"])28 case "claude":29 self = .claude(directory: query["dir"])30 case "mission-control":31 self = .missionControl32 default:33 return nil34 }35 }36}3738extension WorkspaceController {39 func handle(_ link: DeepLink) {40 let window = keyWindow ?? ensurePrimaryWindow()41 switch link {42 case .pane(let id): reveal(pane: id)43 case .ssh(let alias, let tmux):44 guard let host = hosts.values.first(where: { $0.alias == alias }) else { return }45 if let tmux, !tmux.isEmpty { newSSHSession(host: host, in: window, tmux: tmux) } else { newSSHSession(host: host, in: window) }46 case .claude(let directory):47 var dir = directory48 if let d = dir, !FileManager.default.fileExists(atPath: d) { dir = nil }49 newClaudeSession(in: window, directory: dir)50 case .missionControl:51 missionControlOpenRequested = true52 }53 }54}55