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

fix: shortcuts with Option key #31

Merged
merged 3 commits into from
Jan 6, 2023

Conversation

Ty3uK
Copy link
Contributor

@Ty3uK Ty3uK commented Jan 5, 2023

Related to #11.

event.key returns transformed char when option key is pressed.

For example, when user is trying to record shortcut Option+Shift+G, event.key returns Option+Shift+˝.

event.code returns KeyG instead. So getting substring with offset 3 fixes this issue.

This commit fixes another bug: when user records shortcut that already registered, window will hide. Adding unregister before start recording fixes this issue.

Related to ParthJadhav#11.

`event.key` returns transformed char when `option` key is pressed.

For example, when user is trying to record shortcut `Option+Shift+G`,
`event.key` returns `Option+Shift+˝`.

`event.code` returns `KeyG` instead. So getting substring with offset 3
fixes this issue.

This commit fixes another bug: when user records shortcut that already
registered, window will hide. Adding `unregister` before start recording
fixes this issue.
@@ -35,6 +35,8 @@
async function recordShortcut() {
shortcutArray = [];
hotkeys.unbind();
// Prevent closing Preferences when recording already registered shortcut
unregister(preferences.get("shortcut"));
Copy link
Owner

Choose a reason for hiding this comment

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

There would be an issue with this though...

For eg:

if I try executing setting CMD + Space which already is assigned to spotlight. When I click on the recorder, It will unregister the old shortcut but when I press CMD + Space spotlight would be opened. And hence there won't be a new registered shortcut & the previous shortcut would also be unregistered.

Leaving us with no shortcut to start the app 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ParthJadhav, I have the same issue on current master 🥲

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is in hotkeys-js: it cannot capture last key of system hotkeys sequence

Screen.Recording.2023-01-06.at.21.14.36.mp4

So maybe we put this problem into another issue? Or you prefer resolve it in this PR? 🙂

@ParthJadhav ParthJadhav linked an issue Jan 6, 2023 that may be closed by this pull request
@ParthJadhav
Copy link
Owner

Ohh, I see. That's alright. We will resolve it in different PR. This doesn't seem to be that important as of now

@ParthJadhav
Copy link
Owner

Do you think this PR is ready to merge?

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

Do you think this PR is ready to merge?

Give me another five minutes to check production release 🫡

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

Got another bug when trying to set Option+Shift+Space shortcut

} else {
shortcutArray.push(event.code.substring(3));
}
const key = event.code.startsWith("Key")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ParthJadhav, check this please

Copy link
Owner

Choose a reason for hiding this comment

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

On it..

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

Also, quick question: do I need to squash commits or you prefer to preserve full history of changes?

@ParthJadhav
Copy link
Owner

Also, quick question: do I need to squash commits or you prefer to preserve full history of changes?

Oh dw, I'll directly do Squash & Merge

@ParthJadhav
Copy link
Owner

TBH, The whole shortcut recorder function is messy & hard to understand.

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

TBH, The whole shortcut recorder function is messy & hard to understand.

You can create issue and assign it to me, if you want. I can do some refactoring 🙂

@ParthJadhav
Copy link
Owner

I've tested it and everything works as expected... Except if anything else launches while setting the shortcut then we can only open the window by clicking the menu item

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

I've tested it and everything works as expected... Except if anything else launches while setting the shortcut then we can only open the window by clicking the menu item

Maybe we can do some researching for global shortcuts from Rust itself? I think Tauri do this under the hood, but maybe some other library can do this better...

@ParthJadhav
Copy link
Owner

I've tested it and everything works as expected... Except if anything else launches while setting the shortcut then we can only open the window by clicking the menu item

Maybe we can do some researching for global shortcuts from Rust itself? I think Tauri do this under the hood, but maybe some other library can do this better...

Oh no, Everything works as expected. But the fact that we unregister the key before recording the shortcut is causing the problem.

What do you think?

@ParthJadhav
Copy link
Owner

You can create issue and assign it to me, if you want. I can do some refactoring 🙂

I think we can do it at later time when we find to be working on any issue related to the shortcut function... What are you opinion on it?

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

I've tested it and everything works as expected... Except if anything else launches while setting the shortcut then we can only open the window by clicking the menu item

Maybe we can do some researching for global shortcuts from Rust itself? I think Tauri do this under the hood, but maybe some other library can do this better...

Oh no, Everything works as expected. But the fact that we unregister the key before recording the shortcut is causing the problem.

What do you think?

I've tried to comment unregister and it does nothing 🥲

image

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

You can create issue and assign it to me, if you want. I can do some refactoring 🙂

I think we can do it at later time when we find to be working on any issue related to the shortcut function... What are you opinion on it?

Great catch! I think the same way 🙂

@ParthJadhav
Copy link
Owner

I've tested it and everything works as expected... Except if anything else launches while setting the shortcut then we can only open the window by clicking the menu item

Maybe we can do some researching for global shortcuts from Rust itself? I think Tauri do this under the hood, but maybe some other library can do this better...

Oh no, Everything works as expected. But the fact that we unregister the key before recording the shortcut is causing the problem.
What do you think?

I've tried to comment unregister and it does nothing 🥲

image

If you just unbind the unregister line you would notice that the pre-existing shortcut still works after you try to set a shortcut which already exist.

Eg: if you try option + command + space without unregister then it would now listen for the default shortcut which was CMD + SHIFT + G... But with Unregister it wouldn't listen for anything..

@ParthJadhav
Copy link
Owner

Do you use Discord by any chance ? It would be easier to communicate there IMO 😄

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

Do you use Discord by any chance ? It would be easier to communicate there IMO 😄

Yes 🙂 Ty3uK#0057

@Ty3uK
Copy link
Contributor Author

Ty3uK commented Jan 6, 2023

I've tested it and everything works as expected... Except if anything else launches while setting the shortcut then we can only open the window by clicking the menu item

Maybe we can do some researching for global shortcuts from Rust itself? I think Tauri do this under the hood, but maybe some other library can do this better...

Oh no, Everything works as expected. But the fact that we unregister the key before recording the shortcut is causing the problem.
What do you think?

I've tried to comment unregister and it does nothing 🥲
image

If you just unbind the unregister line you would notice that the pre-existing shortcut still works after you try to set a shortcut which already exist.

Eg: if you try option + command + space without unregister then it would now listen for the default shortcut which was CMD + SHIFT + G... But with Unregister it wouldn't listen for anything..

Got it. So maybe I just drop this line and we put this in another issue?

Also, we can do some refactoring just for resolving that kind of issues 🙂

@ParthJadhav
Copy link
Owner

I've tested it and everything works as expected... Except if anything else launches while setting the shortcut then we can only open the window by clicking the menu item

Maybe we can do some researching for global shortcuts from Rust itself? I think Tauri do this under the hood, but maybe some other library can do this better...

Oh no, Everything works as expected. But the fact that we unregister the key before recording the shortcut is causing the problem.
What do you think?

I've tried to comment unregister and it does nothing 🥲
image

If you just unbind the unregister line you would notice that the pre-existing shortcut still works after you try to set a shortcut which already exist.
Eg: if you try option + command + space without unregister then it would now listen for the default shortcut which was CMD + SHIFT + G... But with Unregister it wouldn't listen for anything..

Got it. So maybe I just drop this line and we put this in another issue?

Also, we can do some refactoring just for resolving that kind of issues 🙂

Yep, lets do that 🙌

@ParthJadhav
Copy link
Owner

Awesome, Let's merge it 🚀

@ParthJadhav ParthJadhav merged commit 8eb8ded into ParthJadhav:master Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address Buggy shortcuts when using Option key as modifier
2 participants