Handle ss url.

This commit is contained in:
Charlie Qiu
2016-06-10 22:30:48 +08:00
parent dde48b6bd3
commit 1e0a1e8618
2 changed files with 39 additions and 2 deletions

View File

@ -59,7 +59,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
statusItem.image = image statusItem.image = image
statusItem.menu = statusMenu statusItem.menu = statusMenu
updateServersMenu()
let notifyCenter = NSNotificationCenter.defaultCenter() let notifyCenter = NSNotificationCenter.defaultCenter()
notifyCenter.addObserverForName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil, queue: nil notifyCenter.addObserverForName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil, queue: nil
@ -92,7 +91,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
let userNote = NSUserNotification() let userNote = NSUserNotification()
userNote.title = "Add Shadowsocks Server Profile".localized 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)" userNote.informativeText = "Host: \(profile.serverHost)"
" Port: \(profile.serverPort)" " Port: \(profile.serverPort)"
" Encription Method: \(profile.method)".localized " 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() updateMainMenu()
updateServersMenu()
updateRunningModeMenu() updateRunningModeMenu()
updateLaunchAtLoginMenu() updateLaunchAtLoginMenu()
@ -314,6 +323,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
serversMenuItem.submenu?.addItem(preferencesItem) 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 // NSUserNotificationCenterDelegate

View File

@ -20,6 +20,21 @@
<string>1.0</string> <string>1.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLIconFile</key>
<string>menu_icon@2x</string>
<key>CFBundleURLName</key>
<string>shadowsocks</string>
<key>CFBundleURLSchemes</key>
<array>
<string>ss</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>1</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>