diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift
index 51ca5c8..d5d0e2a 100644
--- a/ShadowsocksX-NG/AppDelegate.swift
+++ b/ShadowsocksX-NG/AppDelegate.swift
@@ -85,6 +85,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 a00879e..a0b9885 100644
--- a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib
+++ b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib
@@ -21,6 +21,7 @@
+
diff --git a/ShadowsocksX-NG/PreferencesWindowController.swift b/ShadowsocksX-NG/PreferencesWindowController.swift
index fbfcf86..51e405f 100644
--- a/ShadowsocksX-NG/PreferencesWindowController.swift
+++ b/ShadowsocksX-NG/PreferencesWindowController.swift
@@ -32,6 +32,7 @@ class PreferencesWindowController: NSWindowController
@IBOutlet weak var copyURLBtn: NSButton!
+ @IBOutlet weak var removeButton: NSButton!
let tableViewDragType: String = "ss.server.profile.data"
var defaults: NSUserDefaults!
@@ -39,6 +40,7 @@ class PreferencesWindowController: NSWindowController
var editingProfile: ServerProfile!
+
override func windowDidLoad() {
super.windowDidLoad()
@@ -91,6 +93,7 @@ class PreferencesWindowController: NSWindowController
@IBAction func addProfile(sender: NSButton) {
if editingProfile != nil && !editingProfile.isValid(){
+ shakeWindows()
return
}
profilesTableView.beginUpdates()
@@ -121,31 +124,13 @@ class PreferencesWindowController: NSWindowController
@IBAction func ok(sender: NSButton) {
if editingProfile != nil {
if !editingProfile.isValid() {
- let numberOfShakes:Int = 8
- let durationOfShake:Float = 0.5
- let vigourOfShake:Float = 0.05
-
- let frame:CGRect = (self.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)
- self.window?.animations = ["frameOrigin":shakeAnimation]
- self.window?.animator().setFrameOrigin(self.window!.frame.origin)
+ shakeWindows()
return
}
}
profileMgr.save()
window?.performClose(nil)
+
NSNotificationCenter.defaultCenter()
.postNotificationName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil)
@@ -160,11 +145,12 @@ class PreferencesWindowController: NSWindowController
if editingProfile != nil && !editingProfile.isValid(){
return
}
- let index = profilesTableView.selectedRow
- if index >= 0 {
- let profile = profileMgr.profiles[index]
+ let oldProfileIndex = profilesTableView.selectedRow
+ if oldProfileIndex >= 0 {
+ let oldProfile = profileMgr.profiles[oldProfileIndex]
profilesTableView.beginUpdates()
- profileMgr.profiles.append(profile)
+ let newProfile = ServerProfile.fromDictionary(oldProfile.toDictionary())
+ profileMgr.profiles.append(newProfile)
let index = NSIndexSet(index: profileMgr.profiles.count-1)
profilesTableView.insertRowsAtIndexes(index, withAnimation: .EffectFade)
self.profilesTableView.scrollRowToVisible(self.profileMgr.profiles.count-1)
@@ -195,6 +181,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 {
@@ -371,4 +363,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)
+ }
}