feat: allow settings export/import (closes #4514)
This commit is contained in:
1 parent
4e6361ff7b
commit
69a9dfa41b
2 files changed
+54
-1
No files matched your search
@@ -190,12 +190,18 @@
|
||||
/* No comment provided by engineer. */
|
||||
"End" = "End";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Export…" = "Export…";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Fade in animation of Preview" = "Fade in animation of Preview";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Fade out animation of Switcher" = "Fade out animation of Switcher";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Failed to import settings" = "Failed to import settings";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Focus selected window" = "Focus selected window";
|
||||
|
||||
@@ -241,6 +247,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"Ignore shortcuts when active" = "Ignore shortcuts when active";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Import…" = "Import…";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Keep open" = "Keep open";
|
||||
|
||||
@@ -410,6 +419,9 @@
|
||||
/* Menubar option */
|
||||
"Send feedback…" = "Send feedback…";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"Settings imported" = "Settings imported";
|
||||
|
||||
/* Menubar option */
|
||||
"Settings…" = "Settings…";
|
||||
|
||||
@@ -509,6 +521,9 @@
|
||||
/* No comment provided by engineer. */
|
||||
"System Default" = "System Default";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"The application needs to restart to apply the imported settings." = "The application needs to restart to apply the imported settings.";
|
||||
|
||||
/* No comment provided by engineer. */
|
||||
"The application needs to restart to apply the language change." = "The application needs to restart to apply the language change.";
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@ class GeneralTab {
|
||||
table.addRow(menubarIcon)
|
||||
table.addNewTable()
|
||||
table.addRow(language)
|
||||
let view = TableGroupSetView(originalViews: [table], bottomPadding: 0)
|
||||
let exportButton = NSButton(title: NSLocalizedString("Export…", comment: ""), target: nil, action: nil)
|
||||
exportButton.onAction = { _ in exportSettings() }
|
||||
let importButton = NSButton(title: NSLocalizedString("Import…", comment: ""), target: nil, action: nil)
|
||||
importButton.onAction = { _ in importSettings() }
|
||||
let tools = StackView([exportButton, importButton], .horizontal)
|
||||
let view = TableGroupSetView(originalViews: [table, tools], bottomPadding: 0)
|
||||
return view
|
||||
}
|
||||
|
||||
@@ -64,6 +69,39 @@ class GeneralTab {
|
||||
}
|
||||
}
|
||||
|
||||
private static func exportSettings() {
|
||||
let panel = NSSavePanel()
|
||||
panel.nameFieldStringValue = "\(App.bundleIdentifier).plist"
|
||||
panel.allowedFileTypes = ["plist"]
|
||||
guard panel.runModal() == .OK, let url = panel.url else { return }
|
||||
NSDictionary(dictionary: Preferences.all).write(to: url, atomically: true)
|
||||
}
|
||||
|
||||
private static func importSettings() {
|
||||
let panel = NSOpenPanel()
|
||||
panel.allowedFileTypes = ["plist"]
|
||||
panel.allowsMultipleSelection = false
|
||||
guard panel.runModal() == .OK, let url = panel.url else { return }
|
||||
guard let dict = NSDictionary(contentsOf: url) as? [String: Any] else {
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .critical
|
||||
alert.messageText = NSLocalizedString("Failed to import settings", comment: "")
|
||||
alert.runModal()
|
||||
return
|
||||
}
|
||||
UserDefaults.standard.setPersistentDomain(dict, forName: App.bundleIdentifier)
|
||||
CachedUserDefaults.cache.withLock { $0.removeAll() }
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .informational
|
||||
alert.messageText = NSLocalizedString("Settings imported", comment: "")
|
||||
alert.informativeText = NSLocalizedString("The application needs to restart to apply the imported settings.", comment: "")
|
||||
alert.addButton(withTitle: NSLocalizedString("Restart Now", comment: ""))
|
||||
alert.addButton(withTitle: NSLocalizedString("Later", comment: ""))
|
||||
if alert.runModal() == .alertFirstButtonReturn {
|
||||
App.app.restart()
|
||||
}
|
||||
}
|
||||
|
||||
static func setLanguageCallback(_ sender: NSControl) {
|
||||
if Preferences.language == .systemDefault {
|
||||
UserDefaults.standard.removeObject(forKey: "AppleLanguages")
|
||||
|
||||
Reference in new issue
Block a user