-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make unregisterall() remove UserDefaults + Make it a public method #184
Changes from all commits
113863a
1c533ed
0c76058
5949935
122174a
5dda3b4
761d28b
0af13cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,13 +127,6 @@ | |
unregisterIfNeeded(shortcut) | ||
} | ||
|
||
private static func unregisterAll() { | ||
CarbonKeyboardShortcuts.unregisterAll() | ||
registeredShortcuts.removeAll() | ||
|
||
// TODO: Should remove user defaults too. | ||
} | ||
|
||
static func initialize() { | ||
guard !isInitialized else { | ||
return | ||
|
@@ -241,7 +234,7 @@ | |
setShortcut(name.defaultShortcut, for: name) | ||
} | ||
} | ||
|
||
Check warning on line 237 in Sources/KeyboardShortcuts/KeyboardShortcuts.swift GitHub Actions / lint
|
||
/** | ||
Reset the keyboard shortcut for one or more names. | ||
|
||
|
@@ -270,6 +263,30 @@ | |
reset(names) | ||
} | ||
|
||
/** | ||
Reset all keyboard shortcuts and remove their stored values from `UserDefaults`. | ||
|
||
This method resets all keyboard shortcuts registered via `KeyboardShortcuts` and removes any associated data stored in `UserDefaults`. | ||
|
||
Use this method to completely reset the state of all keyboard shortcuts in your app, including removing any saved user-defined shortcuts and default shortcuts. | ||
|
||
- Note: This action cannot be undone. All shortcuts will be removed, including any default shortcuts defined in `Name`. If you want to reset shortcuts back to their default values, consider using `.reset(_:)` instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think it makes sense that this has different behavior than |
||
|
||
- Important: This method affects all shortcuts registered with `KeyboardShortcuts` and should be used with caution. | ||
*/ | ||
public static func resetAll() { | ||
// remove shortcuts | ||
CarbonKeyboardShortcuts.unregisterAll() | ||
registeredShortcuts.removeAll() | ||
|
||
Check warning on line 281 in Sources/KeyboardShortcuts/KeyboardShortcuts.swift GitHub Actions / lint
|
||
// remove userdefaults | ||
let userDefaults = UserDefaults.standard | ||
|
||
for key in userDefaults.dictionaryRepresentation().keys where key.hasPrefix("KeyboardShortcuts_") { | ||
userDefaults.removeObject(forKey: key) | ||
} | ||
} | ||
|
||
Check warning on line 289 in Sources/KeyboardShortcuts/KeyboardShortcuts.swift GitHub Actions / lint
|
||
/** | ||
Set the keyboard shortcut for a name. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 paragraphs pretty much say the same thing.