Skip to content
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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added Sources/.DS_Store
Binary file not shown.
33 changes: 25 additions & 8 deletions Sources/KeyboardShortcuts/KeyboardShortcuts.swift
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

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

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

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
/**
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.
Comment on lines +267 to +271
Copy link
Owner

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.


- 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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to reset shortcuts back to their default values, consider using .reset(_:) instead.

I don't think it makes sense that this has different behavior than .reset(). resetAll should just be reset for all.


- 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

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

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

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
// 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

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

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

GitHub Actions / lint

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


Unchanged files with check annotations Beta

extension Data {
var toString: String? { String(data: self, encoding: .utf8) } // swiftlint:disable:this non_optional_string_data_conversion

Check warning on line 17 in Sources/KeyboardShortcuts/Utilities.swift

GitHub Actions / lint

Superfluous Disable Command Violation: SwiftLint rule 'non_optional_string_data_conversion' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)

Check warning on line 17 in Sources/KeyboardShortcuts/Utilities.swift

GitHub Actions / lint

Superfluous Disable Command Violation: SwiftLint rule 'non_optional_string_data_conversion' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
}