diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index 11a6c6b..ad6ea00 100644 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -81,7 +81,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele if let userInfo = note.userInfo { let urls: [NSURL] = userInfo["urls"] as! [NSURL] - let mgr = ServerProfileManager() + let mgr = ServerProfileManager.instance var isChanged = false for url in urls { @@ -191,8 +191,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele @IBAction func showQRCodeForCurrentServer(sender: NSMenuItem) { var errMsg: String? - let mgr = ServerProfileManager() - if let profile = mgr.getActiveProfile() { + if let profile = ServerProfileManager.instance.getActiveProfile() { if profile.isValid() { // Show window if qrcodeWinCtrl != nil{ @@ -275,7 +274,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele @IBAction func selectServer(sender: NSMenuItem) { let index = sender.tag - let spMgr = ServerProfileManager() + let spMgr = ServerProfileManager.instance let newProfile = spMgr.profiles[index] if newProfile.uuid != spMgr.activeProfileId { spMgr.setActiveProfiledId(newProfile.uuid) @@ -345,7 +344,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele } func updateServersMenu() { - let mgr = ServerProfileManager() + let mgr = ServerProfileManager.instance serversMenuItem.submenu?.removeAllItems() let preferencesItem = serversPreferencesMenuItem diff --git a/ShadowsocksX-NG/LaunchAgentUtils.swift b/ShadowsocksX-NG/LaunchAgentUtils.swift index 1488fe3..65fafca 100644 --- a/ShadowsocksX-NG/LaunchAgentUtils.swift +++ b/ShadowsocksX-NG/LaunchAgentUtils.swift @@ -147,7 +147,7 @@ func removeSSLocalConfFile() { func SyncSSLocal() { var changed: Bool = false changed = changed || generateSSLocalLauchAgentPlist() - let mgr = ServerProfileManager() + let mgr = ServerProfileManager.instance if mgr.activeProfileId != nil { changed = changed || writeSSLocalConfFile((mgr.getActiveProfile()?.toJsonConfig())!) diff --git a/ShadowsocksX-NG/PreferencesWindowController.swift b/ShadowsocksX-NG/PreferencesWindowController.swift index b3afebf..45fc92a 100644 --- a/ShadowsocksX-NG/PreferencesWindowController.swift +++ b/ShadowsocksX-NG/PreferencesWindowController.swift @@ -36,7 +36,7 @@ class PreferencesWindowController: NSWindowController // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. defaults = NSUserDefaults.standardUserDefaults() - profileMgr = ServerProfileManager() + profileMgr = ServerProfileManager.instance methodTextField.addItemsWithObjectValues([ "aes-128-cfb", diff --git a/ShadowsocksX-NG/ServerProfileManager.swift b/ShadowsocksX-NG/ServerProfileManager.swift index 3b678da..f3be6c8 100644 --- a/ShadowsocksX-NG/ServerProfileManager.swift +++ b/ShadowsocksX-NG/ServerProfileManager.swift @@ -10,10 +10,12 @@ import Cocoa class ServerProfileManager: NSObject { + static let instance:ServerProfileManager = ServerProfileManager() + var profiles:[ServerProfile] var activeProfileId: String? - override init() { + private override init() { profiles = [ServerProfile]() let defaults = NSUserDefaults.standardUserDefaults()