From 689693e42dfade6e8d609b47c3b8677acfce3f4d Mon Sep 17 00:00:00 2001 From: Yicheng Date: Mon, 22 Aug 2016 23:10:33 +0800 Subject: [PATCH 1/3] shakewindows --- .../PreferencesWindowController.swift | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ShadowsocksX-NG/PreferencesWindowController.swift b/ShadowsocksX-NG/PreferencesWindowController.swift index 6cff2ce..d15a335 100644 --- a/ShadowsocksX-NG/PreferencesWindowController.swift +++ b/ShadowsocksX-NG/PreferencesWindowController.swift @@ -95,6 +95,7 @@ class PreferencesWindowController: NSWindowController if editingProfile != nil { if !editingProfile.isValid() { // TODO Shake window? + shakeWindows() return } } @@ -293,4 +294,27 @@ class PreferencesWindowController: NSWindowController } } } + + func shakeWindows(){ + let numberOfShakes:Int = 8 + let durationOfShake:Float = 0.5 + let vigourOfShake:Float = 0.05 + + let frame:CGRect = (window?.frame)! + let shakeAnimation = CAKeyframeAnimation() + + let shakePath = CGPathCreateMutable() + CGPathMoveToPoint(shakePath, nil, NSMinX(frame), NSMinY(frame)) + + for _ in 1...numberOfShakes{ + CGPathAddLineToPoint(shakePath, nil, NSMinX(frame) - frame.size.width * CGFloat(vigourOfShake), NSMinY(frame)) + CGPathAddLineToPoint(shakePath, nil, NSMinX(frame) + frame.size.width * CGFloat(vigourOfShake), NSMinY(frame)) + } + + CGPathCloseSubpath(shakePath) + shakeAnimation.path = shakePath + shakeAnimation.duration = CFTimeInterval(durationOfShake) + window?.animations = ["frameOrigin":shakeAnimation] + window?.animator().setFrameOrigin(window!.frame.origin) + } } From 4f982d48e001515902414e904a265325004e9d29 Mon Sep 17 00:00:00 2001 From: Yicheng Date: Mon, 22 Aug 2016 23:17:31 +0800 Subject: [PATCH 2/3] prevent remove all servers --- .../Base.lproj/PreferencesWindowController.xib | 1 + ShadowsocksX-NG/PreferencesWindowController.swift | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib index 8142d87..c08dcca 100644 --- a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib +++ b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib @@ -16,6 +16,7 @@ + diff --git a/ShadowsocksX-NG/PreferencesWindowController.swift b/ShadowsocksX-NG/PreferencesWindowController.swift index d15a335..ab0535a 100644 --- a/ShadowsocksX-NG/PreferencesWindowController.swift +++ b/ShadowsocksX-NG/PreferencesWindowController.swift @@ -26,6 +26,7 @@ class PreferencesWindowController: NSWindowController @IBOutlet weak var copyURLBtn: NSButton! + @IBOutlet weak var removeButton: NSButton! let tableViewDragType: String = "ss.server.profile.data" var defaults: NSUserDefaults! @@ -33,6 +34,7 @@ class PreferencesWindowController: NSWindowController var editingProfile: ServerProfile! + override func windowDidLoad() { super.windowDidLoad() @@ -64,6 +66,7 @@ class PreferencesWindowController: NSWindowController @IBAction func addProfile(sender: NSButton) { if editingProfile != nil && !editingProfile.isValid(){ + shakeWindows() return } profilesTableView.beginUpdates() @@ -131,6 +134,12 @@ class PreferencesWindowController: NSWindowController } func updateProfileBoxVisible() { + if profileMgr.profiles.count == 1 { + removeButton.enabled = false + }else{ + removeButton.enabled = true + } + if profileMgr.profiles.isEmpty { profileBox.hidden = true } else { From 671816b592598b3cfaeb838eab11c833e4345251 Mon Sep 17 00:00:00 2001 From: Yicheng Date: Mon, 22 Aug 2016 23:26:04 +0800 Subject: [PATCH 3/3] auto active service when create first server profile --- ShadowsocksX-NG/AppDelegate.swift | 7 +++++++ ShadowsocksX-NG/PreferencesWindowController.swift | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index 3fc0af2..4f2f90f 100644 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -78,6 +78,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele notifyCenter.addObserverForName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil, queue: nil , usingBlock: { (note) in + let profileMgr = ServerProfileManager.instance + if profileMgr.activeProfileId == nil && + profileMgr.profiles.count > 0{ + if profileMgr.profiles[0].isValid(){ + profileMgr.setActiveProfiledId(profileMgr.profiles[0].uuid) + } + } self.updateServersMenu() SyncSSLocal() } diff --git a/ShadowsocksX-NG/PreferencesWindowController.swift b/ShadowsocksX-NG/PreferencesWindowController.swift index ab0535a..086acd7 100644 --- a/ShadowsocksX-NG/PreferencesWindowController.swift +++ b/ShadowsocksX-NG/PreferencesWindowController.swift @@ -104,6 +104,7 @@ class PreferencesWindowController: NSWindowController } profileMgr.save() window?.performClose(nil) + NSNotificationCenter.defaultCenter() .postNotificationName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil) @@ -134,7 +135,7 @@ class PreferencesWindowController: NSWindowController } func updateProfileBoxVisible() { - if profileMgr.profiles.count == 1 { + if profileMgr.profiles.count <= 1 { removeButton.enabled = false }else{ removeButton.enabled = true