mirror of
https://github.com/qinyuhang/ShadowsocksX-NG-R.git
synced 2026-10-20 14:34:30 +00:00
Fix activeProfileId not sync change with subscribe
This commit is contained in:
@@ -118,7 +118,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
, using: {
|
||||
(note) in
|
||||
let profileMgr = ServerProfileManager.instance
|
||||
if profileMgr.activeProfileId == nil &&
|
||||
if profileMgr.getActiveProfileId() == "" &&
|
||||
profileMgr.profiles.count > 0{
|
||||
if profileMgr.profiles[0].isValid(){
|
||||
profileMgr.setActiveProfiledId(profileMgr.profiles[0].uuid)
|
||||
@@ -480,7 +480,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
let index = sender.tag
|
||||
let spMgr = ServerProfileManager.instance
|
||||
let newProfile = spMgr.profiles[index]
|
||||
if newProfile.uuid != spMgr.activeProfileId {
|
||||
if newProfile.uuid != spMgr.getActiveProfileId() {
|
||||
spMgr.setActiveProfiledId(newProfile.uuid)
|
||||
updateServersMenu()
|
||||
SyncSSLocal()
|
||||
@@ -542,7 +542,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
|
||||
let mgr = ServerProfileManager.instance
|
||||
for p in mgr.profiles {
|
||||
if mgr.activeProfileId == p.uuid {
|
||||
if mgr.getActiveProfileId() == p.uuid {
|
||||
if !p.remark.isEmpty {
|
||||
serverMenuText = p.remark
|
||||
} else {
|
||||
@@ -671,7 +671,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
item.title += " - failed"
|
||||
}
|
||||
}
|
||||
if mgr.activeProfileId == p.uuid {
|
||||
if mgr.getActiveProfileId() == p.uuid {
|
||||
item.state = 1
|
||||
}
|
||||
if !p.isValid() {
|
||||
@@ -687,7 +687,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
groupSubmenuItem.title = p.ssrGroup
|
||||
serversMenuItem.submenu?.addItem(groupSubmenuItem)
|
||||
serversMenuItem.submenu?.setSubmenu(groupSubmenu, for: groupSubmenuItem)
|
||||
if mgr.activeProfileId == p.uuid {
|
||||
if mgr.getActiveProfileId() == p.uuid {
|
||||
item.state = 1
|
||||
groupSubmenuItem.state = 1
|
||||
}
|
||||
@@ -696,7 +696,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
continue
|
||||
}
|
||||
else{
|
||||
if mgr.activeProfileId == p.uuid {
|
||||
if mgr.getActiveProfileId() == p.uuid {
|
||||
item.state = 1
|
||||
serversMenuItem.submenu?.item(withTitle: p.ssrGroup)?.state = 1
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ func SyncSSLocal() {
|
||||
var changed: Bool = false
|
||||
changed = changed || generateSSLocalLauchAgentPlist()
|
||||
let mgr = ServerProfileManager.instance
|
||||
if mgr.activeProfileId != nil {
|
||||
if mgr.getActiveProfileId() != "" {
|
||||
if mgr.getActiveProfile() != nil {
|
||||
changed = changed || writeSSLocalConfFile((mgr.getActiveProfile()?.toJsonConfig())!)
|
||||
}
|
||||
@@ -315,7 +315,7 @@ func SyncPrivoxy() {
|
||||
var changed: Bool = false
|
||||
changed = changed || generatePrivoxyLauchAgentPlist()
|
||||
let mgr = ServerProfileManager.instance
|
||||
if mgr.activeProfileId != nil {
|
||||
if mgr.getActiveProfileId() != "" {
|
||||
changed = changed || writePrivoxyConfFile()
|
||||
|
||||
let on = UserDefaults.standard.bool(forKey: "LocalHTTPOn")
|
||||
|
||||
@@ -260,7 +260,7 @@ class PreferencesWindowController: NSWindowController
|
||||
|
||||
func getDataAtRow(_ index:Int) -> (String, Bool) {
|
||||
let profile = profileMgr.profiles[index]
|
||||
let isActive = (profileMgr.activeProfileId == profile.uuid)
|
||||
let isActive = (profileMgr.getActiveProfileId() == profile.uuid)
|
||||
if !profile.remark.isEmpty {
|
||||
return (profile.remark, isActive)
|
||||
} else {
|
||||
|
||||
@@ -19,16 +19,15 @@ class ServerProfileManager: NSObject {
|
||||
profiles = [ServerProfile]()
|
||||
|
||||
let defaults = UserDefaults.standard
|
||||
activeProfileId = defaults.string(forKey: "ActiveServerProfileId")
|
||||
var didFindActiveProfileId = false
|
||||
if let _profiles = defaults.array(forKey: "ServerProfiles") {
|
||||
for _profile in _profiles {
|
||||
let profile = ServerProfile.fromDictionary(_profile as! [String : AnyObject])
|
||||
profiles.append(profile)
|
||||
}
|
||||
}
|
||||
activeProfileId = defaults.string(forKey: "ActiveServerProfileId")
|
||||
for p in profiles {
|
||||
if p.uuid == activeProfileId {
|
||||
return
|
||||
if profile.uuid == activeProfileId {
|
||||
didFindActiveProfileId = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if profiles.count == 0{
|
||||
@@ -38,7 +37,9 @@ class ServerProfileManager: NSObject {
|
||||
NSUserNotificationCenter.default.deliver(notice)
|
||||
return
|
||||
}
|
||||
activeProfileId = profiles[0].uuid
|
||||
if !didFindActiveProfileId {
|
||||
activeProfileId = profiles[0].uuid
|
||||
}
|
||||
}
|
||||
|
||||
func setActiveProfiledId(_ id: String) {
|
||||
@@ -47,6 +48,16 @@ class ServerProfileManager: NSObject {
|
||||
defaults.set(id, forKey: "ActiveServerProfileId")
|
||||
}
|
||||
|
||||
func getActiveProfileId() -> String {
|
||||
for p in profiles {
|
||||
if p.uuid == activeProfileId {
|
||||
return activeProfileId!
|
||||
}
|
||||
}
|
||||
if profiles.count == 0 {return ""}
|
||||
return profiles[0].uuid
|
||||
}
|
||||
|
||||
func save() {
|
||||
let defaults = UserDefaults.standard
|
||||
var _profiles = [AnyObject]()
|
||||
|
||||
@@ -159,6 +159,7 @@ class Subscribe: NSObject{
|
||||
self.profileMgr.save()
|
||||
pushNotification(title: "成功更新订阅", subtitle: "", info: "更新来自\(subscribeFeed)的订阅")
|
||||
(NSApplication.shared().delegate as! AppDelegate).updateServersMenu()
|
||||
(NSApplication.shared().delegate as! AppDelegate).updateRunningModeMenu()
|
||||
}
|
||||
|
||||
if (!isActive){ return }
|
||||
|
||||
Reference in New Issue
Block a user