Merge pull request #8 from cs17899219/develop
Use a singleton ServerProfileManager
This commit is contained in:
@ -81,7 +81,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
|||||||
if let userInfo = note.userInfo {
|
if let userInfo = note.userInfo {
|
||||||
let urls: [NSURL] = userInfo["urls"] as! [NSURL]
|
let urls: [NSURL] = userInfo["urls"] as! [NSURL]
|
||||||
|
|
||||||
let mgr = ServerProfileManager()
|
let mgr = ServerProfileManager.instance
|
||||||
var isChanged = false
|
var isChanged = false
|
||||||
|
|
||||||
for url in urls {
|
for url in urls {
|
||||||
@ -191,8 +191,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
|||||||
|
|
||||||
@IBAction func showQRCodeForCurrentServer(sender: NSMenuItem) {
|
@IBAction func showQRCodeForCurrentServer(sender: NSMenuItem) {
|
||||||
var errMsg: String?
|
var errMsg: String?
|
||||||
let mgr = ServerProfileManager()
|
if let profile = ServerProfileManager.instance.getActiveProfile() {
|
||||||
if let profile = mgr.getActiveProfile() {
|
|
||||||
if profile.isValid() {
|
if profile.isValid() {
|
||||||
// Show window
|
// Show window
|
||||||
if qrcodeWinCtrl != nil{
|
if qrcodeWinCtrl != nil{
|
||||||
@ -275,7 +274,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
|||||||
|
|
||||||
@IBAction func selectServer(sender: NSMenuItem) {
|
@IBAction func selectServer(sender: NSMenuItem) {
|
||||||
let index = sender.tag
|
let index = sender.tag
|
||||||
let spMgr = ServerProfileManager()
|
let spMgr = ServerProfileManager.instance
|
||||||
let newProfile = spMgr.profiles[index]
|
let newProfile = spMgr.profiles[index]
|
||||||
if newProfile.uuid != spMgr.activeProfileId {
|
if newProfile.uuid != spMgr.activeProfileId {
|
||||||
spMgr.setActiveProfiledId(newProfile.uuid)
|
spMgr.setActiveProfiledId(newProfile.uuid)
|
||||||
@ -345,7 +344,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateServersMenu() {
|
func updateServersMenu() {
|
||||||
let mgr = ServerProfileManager()
|
let mgr = ServerProfileManager.instance
|
||||||
serversMenuItem.submenu?.removeAllItems()
|
serversMenuItem.submenu?.removeAllItems()
|
||||||
let preferencesItem = serversPreferencesMenuItem
|
let preferencesItem = serversPreferencesMenuItem
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ func removeSSLocalConfFile() {
|
|||||||
func SyncSSLocal() {
|
func SyncSSLocal() {
|
||||||
var changed: Bool = false
|
var changed: Bool = false
|
||||||
changed = changed || generateSSLocalLauchAgentPlist()
|
changed = changed || generateSSLocalLauchAgentPlist()
|
||||||
let mgr = ServerProfileManager()
|
let mgr = ServerProfileManager.instance
|
||||||
if mgr.activeProfileId != nil {
|
if mgr.activeProfileId != nil {
|
||||||
changed = changed || writeSSLocalConfFile((mgr.getActiveProfile()?.toJsonConfig())!)
|
changed = changed || writeSSLocalConfFile((mgr.getActiveProfile()?.toJsonConfig())!)
|
||||||
|
|
||||||
|
@ -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.
|
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
||||||
defaults = NSUserDefaults.standardUserDefaults()
|
defaults = NSUserDefaults.standardUserDefaults()
|
||||||
profileMgr = ServerProfileManager()
|
profileMgr = ServerProfileManager.instance
|
||||||
|
|
||||||
methodTextField.addItemsWithObjectValues([
|
methodTextField.addItemsWithObjectValues([
|
||||||
"aes-128-cfb",
|
"aes-128-cfb",
|
||||||
|
@ -10,10 +10,12 @@ import Cocoa
|
|||||||
|
|
||||||
class ServerProfileManager: NSObject {
|
class ServerProfileManager: NSObject {
|
||||||
|
|
||||||
|
static let instance:ServerProfileManager = ServerProfileManager()
|
||||||
|
|
||||||
var profiles:[ServerProfile]
|
var profiles:[ServerProfile]
|
||||||
var activeProfileId: String?
|
var activeProfileId: String?
|
||||||
|
|
||||||
override init() {
|
private override init() {
|
||||||
profiles = [ServerProfile]()
|
profiles = [ServerProfile]()
|
||||||
|
|
||||||
let defaults = NSUserDefaults.standardUserDefaults()
|
let defaults = NSUserDefaults.standardUserDefaults()
|
||||||
|
Reference in New Issue
Block a user