feat: add a button to reset the preferences (#1275)
This commit is contained in:
1 parent
5f99e7280a
commit
82e9ca93b6
5 files changed
+28
-6
No files matched your search
@@ -37,6 +37,7 @@
|
||||
BF0C88D7E209C788558BD943 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8CC9692E6E4A32846D72 /* InfoPlist.strings */; };
|
||||
BF0C894199BB262BDB2D8D37 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8221101CD179DB1121D5 /* InfoPlist.strings */; };
|
||||
BF0C894325A54CF0B6B53464 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8B8B31D2F421AC258351 /* Localizable.strings */; };
|
||||
BF0C898511686611E4D7D81E /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8B2C057099EDABE46779 /* Button.swift */; };
|
||||
BF0C89C49CFBAAB4646BB8CB /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C82A8848224E76B880A83 /* InfoPlist.strings */; };
|
||||
BF0C8A739A74695E60F16369 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8062E78677398A4A217B /* InfoPlist.strings */; };
|
||||
BF0C8A95AAD9DADC95887A2D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C895A9AF79A869EE6B108 /* Localizable.strings */; };
|
||||
@@ -203,6 +204,7 @@
|
||||
BF0C89A541FBEA23E7CB1D94 /* lb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = lb; path = Localizable.strings; sourceTree = "<group>"; };
|
||||
BF0C8A50151A4EF88E494357 /* da */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = da; path = InfoPlist.strings; sourceTree = "<group>"; };
|
||||
BF0C8B15FFB262ECC54B5AA4 /* sl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sl; path = InfoPlist.strings; sourceTree = "<group>"; };
|
||||
BF0C8B2C057099EDABE46779 /* Button.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = "<group>"; };
|
||||
BF0C8B2EA9269BA0B79A525F /* sk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sk; path = Localizable.strings; sourceTree = "<group>"; };
|
||||
BF0C8BA452332236D972C60E /* ATShortcut.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ATShortcut.swift; sourceTree = "<group>"; };
|
||||
BF0C8C4E74DCA631A049492A /* preferences-policies.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "preferences-policies.jpg"; sourceTree = "<group>"; };
|
||||
@@ -799,6 +801,7 @@
|
||||
D04BAE333F7170E87C5AC0EF /* CustomRecorderControl.swift */,
|
||||
D04BA8AC77465E1B2BC947CF /* StackView.swift */,
|
||||
BF0C8DF400A1AF64EB0CD0B3 /* TrafficLightButton.swift */,
|
||||
BF0C8B2C057099EDABE46779 /* Button.swift */,
|
||||
);
|
||||
path = "generic-components";
|
||||
sourceTree = "<group>";
|
||||
@@ -1585,6 +1588,7 @@
|
||||
BF0C855CF8BA047E180425F9 /* KeyRepeatTimer.swift in Sources */,
|
||||
BF0C8CC5057406014FD612CC /* ATShortcut.swift in Sources */,
|
||||
BF0C8C7E96DB48120462DA00 /* TrafficLightButton.swift in Sources */,
|
||||
BF0C898511686611E4D7D81E /* Button.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -148,6 +148,10 @@ class Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
static func resetAll() {
|
||||
defaults.removePersistentDomain(forName: App.id)
|
||||
}
|
||||
|
||||
static func registerDefaults() {
|
||||
defaults.register(defaults: defaultValues)
|
||||
}
|
||||
@@ -161,7 +165,7 @@ class Preferences {
|
||||
UserDefaults.cache.removeValue(forKey: key)
|
||||
}
|
||||
|
||||
static var all: [String: Any] { defaults.persistentDomain(forName: NSRunningApplication.current.bundleIdentifier!)! }
|
||||
static var all: [String: Any] { defaults.persistentDomain(forName: App.id)! }
|
||||
|
||||
static func migratePreferences() {
|
||||
let preferencesKey = "preferencesVersion"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import Cocoa
|
||||
|
||||
class Button: NSButton {
|
||||
convenience init(_ title: String, _ action: ActionClosure?) {
|
||||
self.init(title: title, target: nil, action: nil)
|
||||
onAction = action
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
fit()
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,7 @@ class PermissionView: StackView {
|
||||
justification.translatesAutoresizingMaskIntoConstraints = false
|
||||
justification.preferredMaxLayoutWidth = 500
|
||||
justification.widthAnchor.constraint(equalToConstant: justification.fittingSize.width + 5).isActive = true
|
||||
let button = NSButton(title: buttonText, target: nil, action: nil)
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.onAction = { _ in NSWorkspace.shared.open(URL(string: buttonUrl)!) }
|
||||
button.fit()
|
||||
let button = Button(buttonText) { _ in NSWorkspace.shared.open(URL(string: buttonUrl)!) }
|
||||
let status = NSTextField(wrappingLabelWithString: "")
|
||||
status.translatesAutoresizingMaskIntoConstraints = false
|
||||
let buttonStack = NSStackView(views: [button, status])
|
||||
|
||||
@@ -4,6 +4,8 @@ class GeneralTab {
|
||||
static func initTab() -> NSView {
|
||||
let startAtLogin = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Start at login:", comment: ""), "startAtLogin", extraAction: startAtLoginCallback)
|
||||
let menubarIcon = LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Menubar icon:", comment: ""), "menubarIcon", MenubarIconPreference.allCases, extraAction: Menubar.menubarIconCallback)
|
||||
let resetPreferences = Button(NSLocalizedString("Reset preferences and restart", comment: "")) { _ in GeneralTab.resetPreferences() }
|
||||
if #available(OSX 11, *) { resetPreferences.hasDestructiveAction = true }
|
||||
let menubarIconDropdown = menubarIcon[1] as! NSPopUpButton
|
||||
for i in 0...2 {
|
||||
let image = NSImage.initCopy("menubar-" + String(i + 1))
|
||||
@@ -25,7 +27,12 @@ class GeneralTab {
|
||||
|
||||
startAtLoginCallback(startAtLogin[1] as! NSControl)
|
||||
|
||||
return grid
|
||||
return StackView([grid, resetPreferences], .vertical, bottom: GridView.padding)
|
||||
}
|
||||
|
||||
static func resetPreferences() {
|
||||
Preferences.resetAll()
|
||||
App.app.restart()
|
||||
}
|
||||
|
||||
// add/remove plist file in ~/Library/LaunchAgents/ depending on the checkbox state
|
||||
|
||||
Reference in new issue
Block a user