From 671816b592598b3cfaeb838eab11c833e4345251 Mon Sep 17 00:00:00 2001 From: Yicheng Date: Mon, 22 Aug 2016 23:26:04 +0800 Subject: [PATCH] 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