From 557de6d633ac203fa86d59e1705002cf25466312 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Mon, 5 May 2025 13:34:51 +1000 Subject: [PATCH 01/13] chore: add handler and router for `coder` scheme URIs --- .../Coder-Desktop/Coder_DesktopApp.swift | 19 +++- Coder-Desktop/Coder-Desktop/Info.plist | 15 +++ Coder-Desktop/Coder-Desktop/URLHandler.swift | 97 +++++++++++++++++ .../Coder-DesktopTests/CoderRouterTests.swift | 103 ++++++++++++++++++ Coder-Desktop/Resources/1024.png | Bin 0 -> 18138 bytes Coder-Desktop/project.yml | 5 + 6 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 Coder-Desktop/Coder-Desktop/URLHandler.swift create mode 100644 Coder-Desktop/Coder-DesktopTests/CoderRouterTests.swift create mode 100644 Coder-Desktop/Resources/1024.png diff --git a/Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift b/Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift index d9cd6493..4d787355 100644 --- a/Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift +++ b/Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift @@ -17,8 +17,8 @@ struct DesktopApp: App { Window("Sign In", id: Windows.login.rawValue) { LoginForm() .environmentObject(appDelegate.state) - } - .windowResizability(.contentSize) + }.handlesExternalEvents(matching: Set()) // Don't handle deep links + .windowResizability(.contentSize) SwiftUI.Settings { SettingsView() .environmentObject(appDelegate.vpn) @@ -30,7 +30,7 @@ struct DesktopApp: App { .environmentObject(appDelegate.state) .environmentObject(appDelegate.fileSyncDaemon) .environmentObject(appDelegate.vpn) - } + }.handlesExternalEvents(matching: Set()) // Don't handle deep links } } @@ -40,6 +40,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let vpn: CoderVPNService let state: AppState let fileSyncDaemon: MutagenDaemon + let urlHandler: URLHandler override init() { vpn = CoderVPNService() @@ -65,6 +66,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { await fileSyncDaemon.tryStart() } self.fileSyncDaemon = fileSyncDaemon + urlHandler = URLHandler(state: state, vpn: vpn) } func applicationDidFinishLaunching(_: Notification) { @@ -134,6 +136,17 @@ class AppDelegate: NSObject, NSApplicationDelegate { return true } + func application(_: NSApplication, open urls: [URL]) { + guard let url = urls.first else { + // We only accept one at time, for now + return + } + do { try urlHandler.handle(url) } catch { + // TODO: Push notification + print(error.description) + } + } + private func displayIconHiddenAlert() { let alert = NSAlert() alert.alertStyle = .informational diff --git a/Coder-Desktop/Coder-Desktop/Info.plist b/Coder-Desktop/Coder-Desktop/Info.plist index 5e59b253..30eb4d47 100644 --- a/Coder-Desktop/Coder-Desktop/Info.plist +++ b/Coder-Desktop/Coder-Desktop/Info.plist @@ -2,6 +2,21 @@ + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLIconFile + 1024 + CFBundleURLName + com.coder.Coder-Desktop + CFBundleURLSchemes + + coder + + + NSAppTransportSecurity