This commit is contained in:
Qiu Yuzhou
2019-10-29 17:32:31 +08:00
parent 5cb98a1112
commit 9b204d1cf3
2 changed files with 15 additions and 3 deletions

View File

@ -130,6 +130,7 @@ class PreferencesWindowController: NSWindowController
}
@IBAction func cancel(_ sender: NSButton) {
profileMgr.reload()
window?.performClose(self)
}

View File

@ -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 {
@ -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 {