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/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 6cff2ce..086acd7 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() @@ -95,11 +98,13 @@ class PreferencesWindowController: NSWindowController if editingProfile != nil { if !editingProfile.isValid() { // TODO Shake window? + shakeWindows() return } } profileMgr.save() window?.performClose(nil) + NSNotificationCenter.defaultCenter() .postNotificationName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil) @@ -130,6 +135,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 { @@ -293,4 +304,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) + } }