Skip to content

Commit

Permalink
Fixes bug #1137
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuyuzhou committed Oct 29, 2019
1 parent 5cb98a1 commit 9b204d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions ShadowsocksX-NG/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class PreferencesWindowController: NSWindowController
}

@IBAction func cancel(_ sender: NSButton) {
profileMgr.reload()
window?.performClose(self)
}

Expand Down
17 changes: 14 additions & 3 deletions ShadowsocksX-NG/ServerProfileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ class ServerProfileManager: NSObject {

static let instance:ServerProfileManager = ServerProfileManager()

var profiles:[ServerProfile]
var profiles:[ServerProfile] = [ServerProfile]()
var activeProfileId: String?

fileprivate override init() {
profiles = [ServerProfile]()

let defaults = UserDefaults.standard
if let _profiles = defaults.array(forKey: "ServerProfiles") {
for _profile in _profiles {
Expand Down Expand Up @@ -50,6 +48,19 @@ class ServerProfileManager: NSObject {
}
}

func reload() {
profiles.removeAll()

let defaults = UserDefaults.standard
if let _profiles = defaults.array(forKey: "ServerProfiles") {
for _profile in _profiles {
let profile = ServerProfile.fromDictionary(_profile as! [String: Any])
profiles.append(profile)
}
}
activeProfileId = defaults.string(forKey: "ActiveServerProfileId")
}

func getActiveProfile() -> ServerProfile? {
if let id = activeProfileId {
for p in profiles {
Expand Down

0 comments on commit 9b204d1

Please sign in to comment.