From 1e0a1e86183468907ccfb215e04b64c28cce3044 Mon Sep 17 00:00:00 2001 From: Charlie Qiu Date: Fri, 10 Jun 2016 22:30:48 +0800 Subject: [PATCH] Handle ss url. --- ShadowsocksX-NG/AppDelegate.swift | 26 ++++++++++++++++++++++++-- ShadowsocksX-NG/Info.plist | 15 +++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index 2a53dfb..1a1865a 100644 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -59,7 +59,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele statusItem.image = image statusItem.menu = statusMenu - updateServersMenu() let notifyCenter = NSNotificationCenter.defaultCenter() notifyCenter.addObserverForName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil, queue: nil @@ -92,7 +91,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele let userNote = NSUserNotification() userNote.title = "Add Shadowsocks Server Profile".localized - userNote.subtitle = "By scan QR Code".localized + if userInfo["source"] as! String == "qrcode" { + userNote.subtitle = "By scan QR Code".localized + } else if userInfo["source"] as! String == "url" { + userNote.subtitle = "By Handle SS URL".localized + } userNote.informativeText = "Host: \(profile.serverHost)" " Port: \(profile.serverPort)" " Encription Method: \(profile.method)".localized @@ -110,7 +113,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele } } + // Handle ss url scheme + NSAppleEventManager.sharedAppleEventManager().setEventHandler(self + , andSelector: #selector(self.handleURLEvent) + , forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL)) + updateMainMenu() + updateServersMenu() updateRunningModeMenu() updateLaunchAtLoginMenu() @@ -314,6 +323,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele serversMenuItem.submenu?.addItem(preferencesItem) } + func handleURLEvent(event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) { + if let urlString = event.paramDescriptorForKeyword(AEKeyword(keyDirectObject))?.stringValue { + if let url = NSURL(string: urlString) { + NSNotificationCenter.defaultCenter().postNotificationName( + "NOTIFY_FOUND_SS_URL", object: nil + , userInfo: [ + "ruls": [url], + "source": "url", + ]) + } + } + } + //------------------------------------------------------------ // NSUserNotificationCenterDelegate diff --git a/ShadowsocksX-NG/Info.plist b/ShadowsocksX-NG/Info.plist index a07a177..8927441 100644 --- a/ShadowsocksX-NG/Info.plist +++ b/ShadowsocksX-NG/Info.plist @@ -20,6 +20,21 @@ 1.0 CFBundleSignature ???? + CFBundleURLTypes + + + CFBundleTypeRole + Viewer + CFBundleURLIconFile + menu_icon@2x + CFBundleURLName + shadowsocks + CFBundleURLSchemes + + ss + + + CFBundleVersion 1 LSApplicationCategoryType