golang-design / hotkey

⌨️ cross-platform hotkey package
https://golang.design/x/hotkey
MIT License
212 stars 10 forks source link

Allow unregister hotkeys #7

Closed ventsislav-georgiev closed 2 years ago

ventsislav-georgiev commented 2 years ago

There seems to be a TODO for Darwin and an UnregisterHotKey already for Windows. Any plans on adding implementation for Darwin and using the one available for Windows?

changkun commented 2 years ago

Hi. Thanks for the feature request. I was initially thought this is a feature but didn't implement this because I can't imagine a need of frequently register, deregister, register, ... loop. Could you explain the necessarily of unregistering a hotkey?

ventsislav-georgiev commented 2 years ago

A GUI for the user to set/edit global shortcuts for commands while an application is running.

changkun commented 2 years ago

A GUI for the user to set/edit global shortcuts for commands while an application is running.

But that does not necessarily needed to be implemented at runtime. For example, Hotkey combination setting is registered at boot time, which can be stored in a config file. When a user needs added the hotkey, application rewrite the configuration and require a reboot to make it possible to be activated.

ventsislav-georgiev commented 2 years ago

The required restart is exactly what I am trying to avoid. Just for better UX. I am making myself an app launcher with fyne.

BTW I am aware of the limitation - https://github.com/golang-design/hotkey/issues/5 and have workaround it by allowing the runOnMain method from fyne to be passed on the register method, leaving the mainthread package usage up to the client - https://github.com/ventsislav-georgiev/hotkey/commit/bdab82048dbe6f43dfeec87a63835a1ea72c7c95

ventsislav-georgiev commented 2 years ago

Made it work via restart like you proposed for now: shortcuts

On another note I had issue on Mac where sometime the app would fail to start and I think it was caused by the runApp/stopApp code. I've removed it as it does not seem necessary in my use-case trough fyne. - https://github.com/ventsislav-georgiev/hotkey/commit/060ae7ddfbc405b28146818052f8a5c331ad2abd

changkun commented 2 years ago

I implemented the unregister feature and now available on v0.3.0-alpha.

Note that the new version breaks the existing APIs slightly.