From 1388c065c715964bd50fce0e4f4368b7776c3e94 Mon Sep 17 00:00:00 2001 From: Charlie Qiu Date: Thu, 12 Jan 2017 11:45:57 +0800 Subject: [PATCH] Send a system notification when not found valid qrcode of ss profile. --- ShadowsocksX-NG/AppDelegate.swift | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index ac851a6..a7fdeeb 100755 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -138,6 +138,20 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele ) notifyCenter.addObserver(forName: NSNotification.Name(rawValue: "NOTIFY_FOUND_SS_URL"), object: nil, queue: nil) { (note: Notification) in + + let sendNotify = { + (title: String, subtitle: String, infoText: String) in + + let userNote = NSUserNotification() + userNote.title = title + userNote.subtitle = subtitle + userNote.informativeText = infoText + userNote.soundName = NSUserNotificationDefaultSoundName + + NSUserNotificationCenter.default + .deliver(userNote); + } + if let userInfo = (note as NSNotification).userInfo { let urls: [URL] = userInfo["urls"] as! [URL] @@ -149,26 +163,22 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele mgr.profiles.append(profile) isChanged = true - let userNote = NSUserNotification() - userNote.title = "Add Shadowsocks Server Profile".localized + var subtitle: String = "" if userInfo["source"] as! String == "qrcode" { - userNote.subtitle = "By scan QR Code".localized + subtitle = "By scan QR Code".localized } else if userInfo["source"] as! String == "url" { - userNote.subtitle = "By Handle SS URL".localized + subtitle = "By Handle SS URL".localized } - userNote.informativeText = "Host: \(profile.serverHost)" - //" Port: \(profile.serverPort)" - //" Encription Method: \(profile.method)".localized - userNote.soundName = NSUserNotificationDefaultSoundName - NSUserNotificationCenter.default - .deliver(userNote); + sendNotify("Add Shadowsocks Server Profile".localized, subtitle, "Host: \(profile.serverHost)") } } if isChanged { mgr.save() self.updateServersMenu() + } else { + sendNotify("Not found valid qrcode of shadowsocks profile.", "", "") } } }