Skip to content

Commit

Permalink
- add comments for unregisterAll()
Browse files Browse the repository at this point in the history
- relocate unregisterAll() to below public static func reset()
  • Loading branch information
stormychel committed Oct 5, 2024
1 parent 122174a commit 5dda3b4
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions Sources/KeyboardShortcuts/KeyboardShortcuts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,6 @@ public enum KeyboardShortcuts {
unregisterIfNeeded(shortcut)
}

public static func unregisterAll() {
CarbonKeyboardShortcuts.unregisterAll()
registeredShortcuts.removeAll()

// remove user defaults too
let userDefaults = UserDefaults.standard

for key in userDefaults.dictionaryRepresentation().keys where key.hasPrefix("KeyboardShortcuts_") {
userDefaults.removeObject(forKey: key)
}
}

static func initialize() {
guard !isInitialized else {
return
Expand Down Expand Up @@ -246,7 +234,7 @@ public enum KeyboardShortcuts {
setShortcut(name.defaultShortcut, for: name)
}
}

Check warning on line 237 in Sources/KeyboardShortcuts/KeyboardShortcuts.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
/**
Reset the keyboard shortcut for one or more names.

Expand Down Expand Up @@ -275,6 +263,29 @@ public enum KeyboardShortcuts {
reset(names)
}

/**
Unregister all keyboard shortcuts and remove their stored values from `UserDefaults`.

This method unregisters 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.

- Important: This method affects all shortcuts registered with `KeyboardShortcuts` and should be used with caution.
*/
public static func unregisterAll() {
CarbonKeyboardShortcuts.unregisterAll()
registeredShortcuts.removeAll()

Check warning on line 280 in Sources/KeyboardShortcuts/KeyboardShortcuts.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
// remove user defaults too
let userDefaults = UserDefaults.standard

for key in userDefaults.dictionaryRepresentation().keys where key.hasPrefix("KeyboardShortcuts_") {
userDefaults.removeObject(forKey: key)
}
}

Check warning on line 288 in Sources/KeyboardShortcuts/KeyboardShortcuts.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
/**
Set the keyboard shortcut for a name.

Expand Down

0 comments on commit 5dda3b4

Please sign in to comment.