Skip to content

Commit

Permalink
Fixed the problem that resetting the preferences will cause the chart…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
gee1k committed Nov 27, 2019
1 parent 9dad5f8 commit 9ce76a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
12 changes: 6 additions & 6 deletions uPic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand All @@ -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 = (
Expand All @@ -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 = (
Expand All @@ -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 = (
Expand All @@ -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 = (
Expand Down
24 changes: 16 additions & 8 deletions uPic/General/Managers/ConfigManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

}

}
Expand Down
29 changes: 17 additions & 12 deletions uPic/PreferencesWindow/AdvancedPreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 9ce76a3

Please sign in to comment.