From 5ce8e611e27455933822548afb632c4860aa3738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E5=AE=87=E8=88=AA?= Date: Mon, 24 Jul 2017 00:36:46 +0800 Subject: [PATCH] fix crash problem --- ShadowsocksX-NG/AppDelegate.swift | 2 +- ShadowsocksX-NG/ServerProfileManager.swift | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index dde0c83..84a5b33 100644 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -199,7 +199,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele ProxyConfHelper.install() applyConfig() - SyncSSLocal() +// SyncSSLocal() if defaults.bool(forKey: "ConnectAtLaunch") && ServerProfileManager.instance.getActiveProfileId() != "" { toggleRunning(toggleRunningMenuItem) diff --git a/ShadowsocksX-NG/ServerProfileManager.swift b/ShadowsocksX-NG/ServerProfileManager.swift index ba7ffeb..ac3bf75 100644 --- a/ShadowsocksX-NG/ServerProfileManager.swift +++ b/ShadowsocksX-NG/ServerProfileManager.swift @@ -74,7 +74,7 @@ class ServerProfileManager: NSObject { } if getActiveProfileId() != "" { - defaults.set(activeProfileId, forKey: "ActiveServerProfileId") + defaults.set(getActiveProfileId(), forKey: "ActiveServerProfileId") let _ = writeSSLocalConfFile((getActiveProfile()?.toJsonConfig())!) } else { defaults.removeObject(forKey: "ActiveServerProfileId") @@ -83,16 +83,13 @@ class ServerProfileManager: NSObject { } func getActiveProfile() -> ServerProfile? { - if let id = activeProfileId { - for p in profiles { - if p.uuid == id { - return p - } + if getActiveProfileId() == "" { return nil } + for p in profiles { + if p.uuid == getActiveProfileId() { + return p } - return nil - } else { - return nil } + return nil } func isExisted(profile: ServerProfile) -> (Bool, Int){