From 9ce76a30fff6b702a2b67772d47c2c09b63e83dd Mon Sep 17 00:00:00 2001 From: Svend Date: Wed, 27 Nov 2019 23:09:26 +0800 Subject: [PATCH] Fixed the problem that resetting the preferences will cause the chart bed configuration to be lost 1.Fixed the problem that resetting the preferences will cause the chart bed configuration to be lost 2. Optimize the logic of resetting the history configuration --- uPic.xcodeproj/project.pbxproj | 12 ++++---- uPic/General/Managers/ConfigManager.swift | 24 ++++++++++----- .../AdvancedPreferencesViewController.swift | 29 +++++++++++-------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/uPic.xcodeproj/project.pbxproj b/uPic.xcodeproj/project.pbxproj index 1d111e3..c1790eb 100644 --- a/uPic.xcodeproj/project.pbxproj +++ b/uPic.xcodeproj/project.pbxproj @@ -1204,7 +1204,7 @@ CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 20191126; - DEVELOPMENT_TEAM = 2U23P5CPX2; + DEVELOPMENT_TEAM = W863J6W8DZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "$(SRCROOT)/uPic/Supporting Files/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( @@ -1234,7 +1234,7 @@ CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 20191126; - DEVELOPMENT_TEAM = 2U23P5CPX2; + DEVELOPMENT_TEAM = W863J6W8DZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "$(SRCROOT)/uPic/Supporting Files/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( @@ -1259,7 +1259,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = 2U23P5CPX2; + DEVELOPMENT_TEAM = W863J6W8DZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = uPicHelper/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -1282,7 +1282,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = 2U23P5CPX2; + DEVELOPMENT_TEAM = W863J6W8DZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = uPicHelper/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -1305,7 +1305,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = 2U23P5CPX2; + DEVELOPMENT_TEAM = W863J6W8DZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = uPicFinderExtension/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -1330,7 +1330,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = 2U23P5CPX2; + DEVELOPMENT_TEAM = W863J6W8DZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = uPicFinderExtension/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/uPic/General/Managers/ConfigManager.swift b/uPic/General/Managers/ConfigManager.swift index 6bd9334..4511967 100644 --- a/uPic/General/Managers/ConfigManager.swift +++ b/uPic/General/Managers/ConfigManager.swift @@ -50,18 +50,26 @@ public class ConfigManager { } public func removeAllUserDefaults() { + // 提前取出图床配置 + let hostItems = self.getHostItems() + let defaultHostId = Defaults[.defaultHostId] + let historyList = self.getHistoryList_New() - let ignoreKeys = [Keys.hostItems, Keys.defaultHostId, Keys.historyList] + let domain = Bundle.main.bundleIdentifier! + Defaults.removePersistentDomain(forName: domain) + Defaults.synchronize() - let dics = Defaults.dictionaryRepresentation() - for key in dics { - if ignoreKeys.contains(key.key) { - continue + DispatchQueue.main.async { + // 清除所有用户设置后,再重新写入图床配置 + self.setHostItems(items: hostItems) + Defaults[.defaultHostId] = defaultHostId + + let list = historyList.map { (model) -> [String: Any] in + return model.toKeyValue() } - Defaults.removeObject(forKey: key.key) + + self.setHistoryList_New(items: list) } - Defaults.synchronize() - } } diff --git a/uPic/PreferencesWindow/AdvancedPreferencesViewController.swift b/uPic/PreferencesWindow/AdvancedPreferencesViewController.swift index e4e1f15..60772d7 100644 --- a/uPic/PreferencesWindow/AdvancedPreferencesViewController.swift +++ b/uPic/PreferencesWindow/AdvancedPreferencesViewController.swift @@ -49,15 +49,19 @@ class AdvancedPreferencesViewController: PreferencesViewController { } @IBAction func didClickHistoryRecordConfigurationResetButton(_ sender: NSButton) { - Defaults[.historyRecordWidth] = Float(500) - Defaults[.historyRecordColumns] = Int(3) - Defaults[.historyRecordSpacing] = Float(5) - Defaults[.historyRecordPadding] = Float(5) - Defaults[.historyRecordFileNameScrollSpeed] = Double(30) - Defaults[.historyRecordFileNameScrollWaitTime] = Float(1) - setHistoryRecordTextFieldDefaultText() - ConfigNotifier.postNotification(.changeHistoryList) + Defaults.removeObject(forKey: Keys.historyRecordWidth) + Defaults.removeObject(forKey: Keys.historyRecordColumns) + Defaults.removeObject(forKey: Keys.historyRecordSpacing) + Defaults.removeObject(forKey: Keys.historyRecordPadding) + Defaults.removeObject(forKey: Keys.historyRecordFileNameScrollSpeed) + Defaults.removeObject(forKey: Keys.historyRecordFileNameScrollWaitTime) + Defaults.synchronize() + + DispatchQueue.main.async { + self.setHistoryRecordTextFieldDefaultText() + ConfigNotifier.postNotification(.changeHistoryList) + } } @IBAction func didClickHistoryRecordConfigurationSaveButton(_ sender: NSButton) { @@ -95,11 +99,12 @@ class AdvancedPreferencesViewController: PreferencesViewController { SMLoginItemSetEnabled(Constants.launcherAppIdentifier as CFString, false) ConfigManager.shared.removeAllUserDefaults() ConfigManager.shared.firstSetup() - _ = NSApplication.shared.delegate as! AppDelegate -// appDelegate.setStatusToggle() - // reset all values - resetAllValues() + DispatchQueue.main.async { + ConfigNotifier.postNotification(.changeHistoryList) + self.resetAllValues() + } + default: print("Cancel Resetting User Preferences") }