sindresorhus / KeyboardShortcuts

⌨️ Add user-customizable global keyboard shortcuts (hotkeys) to your macOS app in minutes
https://swiftpackageindex.com/sindresorhus/KeyboardShortcuts/documentation/keyboardshortcuts/keyboardshortcuts
MIT License
2.02k stars 186 forks source link

Manually set a keyboard shortcut for a name #16

Closed sindresorhus closed 4 years ago

sindresorhus commented 4 years ago

This can be useful for migrating over to this package from some other solution.

Inside some one-time migration method:

let shortcut = KeyboardShortcuts.Shortcut(carbonKeycode: someHotkey, carbonModifiers: someModifiers)

KeyboardShortcuts.Name.foo.shortcut = shortcut

Alternatively:

let shortcut = KeyboardShortcuts.Shortcut(carbonKeycode: someHotkey, carbonModifiers: someModifiers)

KeyboardShortcuts.Name.set(shortcut, for: .foo)

That way, the user doesn't need to know the implementation details on how it's stored. Like here: https://github.com/p0deje/Maccy/commit/1001035d611cb411df702a941f5eb40626fc5ea7#diff-2589021fe69dedfc5619fc6a19136f23R117-R126

@p0deje Any thoughts?

p0deje commented 4 years ago

This would be great indeed as I had to read through the sources to figure out the storage mechanism. Another possible solution would be to allow to customize storage strategy that can be implemented to provide backwards compatiblity during the app migration. The silly implementation I used to have was to just write "command+shift+C" string to my own UserDefaults, then parse it and construct a shortcut.

sindresorhus commented 4 years ago

Another possible solution would be to allow to customize storage strategy that can be implemented to provide backwards compatiblity during the app migration.

Agreed. I could use your thoughts in https://github.com/sindresorhus/KeyboardShortcuts/issues/18.