Skip to content

Conversation

@rburgst
Copy link
Contributor

@rburgst rburgst commented Aug 23, 2021

this PR adds 2 features to AuthPass:

  • Keyboard Shortcuts for TOTP
  • Global Hotkey support for Mac OSX: use CMD ^ n to bring AuthPass to front and invoke the search function

@CLAassistant
Copy link

CLAassistant commented Aug 23, 2021

CLA assistant check
All committers have signed the CLA.

@hpoul
Copy link
Collaborator

hpoul commented Aug 23, 2021

Nice, thanks 👍️
my only concern would be that it would be nice to keep the changes to the macos/ app template to a minimum (especially the Podfile) - do you think it's possible to move the hotkey logic into an external flutter plugin?

although this looks like it is already doing something very similar: https://pub.dev/packages/global_shortcuts - maybe we could reuse this, if it doesn't do anything weird 🤔️

@hpoul
Copy link
Collaborator

hpoul commented Aug 23, 2021

Here is another plugin which seems to even work on windows: https://pub.dev/packages/hotkey_manager

@rburgst
Copy link
Contributor Author

rburgst commented Aug 29, 2021

tried https://pub.dev/packages/hotkey_manager but something completely hosed my project, now i can no longer build (getting weird signing errors). So it might take a while to materialize.

@rburgst
Copy link
Contributor Author

rburgst commented Aug 29, 2021

I think the problem is related to leanflutter/hotkey_manager#1

@rburgst
Copy link
Contributor Author

rburgst commented Aug 29, 2021

hotkey_manager: 0.0.4 did the trick, @hpoul here is now the multiplatform version

@rburgst rburgst force-pushed the feature/totp-global-hotkey branch 3 times, most recently from 07cc25c to 8b2dcd3 Compare August 29, 2021 09:58
@rburgst
Copy link
Contributor Author

rburgst commented Aug 29, 2021

@hpoul I am a bit new to flutter, so I cant figure out why the integration test is failing. I added a catch to the registration of the hotkey (https://github.com/authpass/authpass/pull/262/files#diff-e134bef29121dced32f37fe56c1dcacbe97c298d81c4db00f57f1e13144f05beR103) but somehow this does not seem to work or the int test. I tested the actual build on the ios simulator and there it looked like the exception was properly caught.
Not sure what I am doing wrong here.

@hpoul
Copy link
Collaborator

hpoul commented Aug 29, 2021

@rburgst no worries, i think the exception is not catched, because you don't await the future. and the exception is actually thrown in asynchronous code and not synchronously. So it ends up in flutters catchall which is probably ignored when running the app, but it produces the integration test to fail..

So you could probably "fix" this by adding an await but I think it would be nicer if instead of catching the error you only register on supported platforms.. ie. if (AuthPassPlatform.isMacOS || AuthPassPlatform.isWindows) { await HotKeyManager.instance.unregister(_hotKey); } so no try/catch, just an if..

(btw. any idea if the plugin is supported on linux? it seems there is linux code which does something but the README.md for the plugin states clearly that it lacks linux support 🤔️)

@lijy91
Copy link

lijy91 commented Aug 29, 2021

I am the author of hotkey_manager, it will support linux platform soon.

@rburgst
Copy link
Contributor Author

rburgst commented Aug 29, 2021

@rburgst no worries, i think the exception is not catched, because you don't await the future.

Ah, that makes sense, the problem is that KeyboardHandler.initState is not async and therefore, I cannot await the promise (I think)

@rburgst rburgst force-pushed the feature/totp-global-hotkey branch from 8b2dcd3 to 37a3e25 Compare August 29, 2021 15:16
@rburgst
Copy link
Contributor Author

rburgst commented Aug 29, 2021

So you could probably "fix" this by adding an await but I think it would be nicer if instead of catching the error you only register on supported platforms.. ie. if (AuthPassPlatform.isMacOS || AuthPassPlatform.isWindows) { await HotKeyManager.instance.unregister(_hotKey); } so no try/catch, just an if..

I am not sure I want to always keep track of which platforms HotKeyManager supports.
I currently worked around the problem via HotKeyManager.instance.register.catchError

@hpoul
Copy link
Collaborator

hpoul commented Aug 29, 2021

always keep track of which platforms HotKeyManager supports

It's not like this will change on a weekly basis 😂
The problem with catching and ignoring is that when a supported platform fails to register, for whatever reason, we would never know and it would be a pain to debug it.. it would be invisible in user logs..

@rburgst rburgst force-pushed the feature/totp-global-hotkey branch 2 times, most recently from bf3272b to 40f8417 Compare August 29, 2021 15:52
@codecov
Copy link

codecov bot commented Aug 30, 2021

Codecov Report

Merging #262 (2ff375c) into master (9fa3254) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

❗ Current head 2ff375c differs from pull request most recent head ff6c6c8. Consider uploading reports for the commit ff6c6c8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##           master    #262      +/-   ##
=========================================
- Coverage    2.95%   2.93%   -0.03%     
=========================================
  Files         102     102              
  Lines        9499    9566      +67     
=========================================
  Hits          281     281              
- Misses       9218    9285      +67     
Impacted Files Coverage Δ
authpass/lib/bloc/app_data.dart 4.13% <0.00%> (-0.07%) ⬇️
authpass/lib/bloc/app_data.g.dart 11.57% <0.00%> (-0.48%) ⬇️
authpass/lib/ui/screens/entry_details.dart 12.05% <0.00%> (-0.14%) ⬇️
authpass/lib/ui/screens/main_app_scaffold.dart 0.00% <0.00%> (ø)
authpass/lib/ui/screens/preferences.dart 0.00% <0.00%> (ø)
authpass/lib/ui/widgets/keyboard_handler.dart 1.96% <0.00%> (-0.64%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9fa3254...ff6c6c8. Read the comment docs.

@hpoul
Copy link
Collaborator

hpoul commented Aug 30, 2021

@rburgst thanks, looks good 👍
I've made two changes, maybe you can take a look and see if everything still works for you:

  1. require users to enable system wide shortcuts in the preferences 3b8bf28 (I don't want to mess with system wide shortcuts without asking)
  2. added a fallback to the totp copy 856d3fc - it now copies either the otpauth or otp or totp seed fields.

Also - what was the thought behind using ctrl+alt+n as shortcut for search? since the app internal shortcut is ctrl+f wouldnt it make more sense to use ctrl+alt+f? 🤔️

(btw. in the future it would be easier if you could create separate PRs for each feature, it would make discussions a bit easier 😅️)

@rburgst
Copy link
Contributor Author

rburgst commented Aug 30, 2021

Also - what was the thought behind using ctrl+alt+n as shortcut for search? since the app internal shortcut is ctrl+f wouldnt it make more sense to use ctrl+alt+f? 🤔️

Actually the keyboard shortcut should be configurable, but I dont have enough knowledge and practice with Flutter to efficiently do this.
I am using IntelliJ/Android Studio on a regular basis and therefore, the list of available shortcut keys is quite short.

@lijy91
Copy link

lijy91 commented Aug 30, 2021

@rburgst Please upgrade hotkey_manager to 0.0.5, This version is supported linux platform.

@rburgst
Copy link
Contributor Author

rburgst commented Aug 31, 2021

@rburgst Please upgrade hotkey_manager to 0.0.5, This version is supported linux platform.

done

@rburgst
Copy link
Contributor Author

rburgst commented Aug 31, 2021

(btw. in the future it would be easier if you could create separate PRs for each feature, it would make discussions a bit easier 😅️)

Sorry about that, I was on a roll. Will do that next time.
Anyway, thanks for improving the PR significantly. Can we merge this now?

@hpoul
Copy link
Collaborator

hpoul commented Aug 31, 2021

@rburgst my only concern is the keyboard shortcut ctrl+alt+n - for me this would make more sense for creating a new password entry :-) i think i'll change it to ctrl+alt+f, if you don't have a better idea? 🤔️

yes, earlier or later this should be configurable.. but until then it should be a sensible default.. the whole keyboard shortcut implementation is just a workaround right now, honestly..

// Seems i can't figure out how to get `Shortcuts` & co to work.. workaround it for now
// also see https://github.com/flutter/flutter/issues/38076

😂 I actually hoped that someone would come out with a nice pub package which makes this easier ;-) This should be a pretty generic problem to solve :)

@hpoul
Copy link
Collaborator

hpoul commented Aug 31, 2021

@lijy91 thanks for the update of hotkey_manager 👍 i've seen you're using it in the biyi_app app - do you plan on providing user's a way to customize hotkeys in your app? 😅️ Just thinking how this could be implemented the easiest way..

@hpoul hpoul force-pushed the feature/totp-global-hotkey branch from f993149 to 52785b0 Compare August 31, 2021 09:01
@hpoul
Copy link
Collaborator

hpoul commented Aug 31, 2021

@lijy91 are there any external dependencies for linux? the build seems to fail with:

[  +43 ms] -- Checking for module 'keybinder-3.0'
[   +2 ms] --   No package 'keybinder-3.0' found

@lijy91
Copy link

lijy91 commented Aug 31, 2021

@lijy91 are there any external dependencies for linux? the build seems to fail with:

[  +43 ms] -- Checking for module 'keybinder-3.0'
[   +2 ms] --   No package 'keybinder-3.0' found

On linux platform it depends on keybinder-3.0, You need to install it.

sudo apt-get install keybinder-3.0

@hpoul
Copy link
Collaborator

hpoul commented Aug 31, 2021

@lijy91 thanks.. is this "only" a compile time dependency, or must this also be installed during runtime?

I'm now getting the following compile errors https://github.com/authpass/authpass/pull/262/checks?check_run_id=3472093090#step:8:506


[        ] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:23:15: error: no member named 'string' in namespace 'std'
[   +4 ms] std::map<std::string, uint> known_virtual_key_codes = {
[        ]          ~~~~~^
[   +1 ms] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:254:15: error: no member named 'string' in namespace 'std'
[        ] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:279:3: error: no type named 'string' in namespace 'std'; did you mean 'GString'?
[        ] std::map<std::string, std::string> hotkey_map;
[        ]          ~~~~~^
[   +1 ms]   std::string val = keystring;
[        ]   ^~~~~~~~~~~
[        ] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:301:39: error: no member named 'string' in namespace 'std'
[        ]   GString
[        ] /usr/include/glib-2.0/glib/gstring.h:39:33: note: 'GString' declared here
[        ] typedef struct _GString         GString;
[        ]                                 ^
[   +1 ms] guint get_mods(const std::vector<std::string> &modifiers)
[        ]                                  ~~~~~^
[        ] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:327:20: error: no member named 'string' in namespace 'std'
[        ] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:327:28: error: C++ requires a type specifier for all declarations
[        ]   std::vector<std::string> modifiers;
[        ]               ~~~~~^
[        ]   std::vector<std::string> modifiers;
[        ] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:330:5: error: no type named 'string' in namespace 'std'; did you mean 'GString'?
[        ]                            ^
[        ]     std::string keyModifier = fl_value_get_string(fl_value_get_list_value(modifiers_value, i));
[        ]     ^~~~~~~~~~~
[        ]     GString
[        ] /usr/include/glib-2.0/glib/gstring.h:39:33: note: 'GString' declared here
[        ] typedef struct _GString         GString;
[        ]                                 ^
[        ] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:338:36: error: no member named 'string' in namespace 'std'
[        ]   hotkey_map.insert(std::pair<std::string, std::string>(identifier, keystring));
[        ]                               ~~~~~^
[        ] /home/runner/work/authpass/authpass/authpass/linux/flutter/ephemeral/.plugin_symlinks/hotkey_manager/linux/hotkey_manager_plugin.cc:352:3: error: no type named 'string' in namespace 'std'; did you mean 'GString'?
[        ]   std::string val = identifier;
[        ]   ^~~~~~~~~~~
[        ]   GString
[        ] /usr/include/glib-2.0/glib/gstring.h:39:33: note: 'GString' declared here
[        ] typedef struct _GString         GString;
[        ]                                 ^
[        ] 9 errors generated.

@lijy91
Copy link

lijy91 commented Aug 31, 2021

@hpoul I think this may be caused by the build environment, I tried adding #include <string> to my code, you can update hotkey_manager to 0.0.6, if it still fails to build I may need to add a github action for hotkey_manager to verify it.

I use Ubuntu 20.04.1 LTS for testing

@hpoul hpoul force-pushed the feature/totp-global-hotkey branch from 1dbf033 to a5340cb Compare August 31, 2021 16:33
@hpoul hpoul force-pushed the feature/totp-global-hotkey branch from a5340cb to b9cea56 Compare August 31, 2021 16:34
@hpoul
Copy link
Collaborator

hpoul commented Aug 31, 2021

@lijy91 thanks! that seems to have done the trick. The linux build uses ubuntu-18.04 - maybe that's the difference. Now I just need a way to find a way to try the runtime 😂️ too many platforms :-)

@hpoul
Copy link
Collaborator

hpoul commented Aug 31, 2021

okay, this seems to be a runtime dependency as well 🙄 starting to get a bit annoying to have more dependencies a user must install just for a single shortcut nobody is going to use 🤣 but anyway..

Screen Shot 2021-08-31 at 20 25 28

@hpoul
Copy link
Collaborator

hpoul commented Aug 31, 2021

@rburgst did you test on windows or macos whether the global system wide keys where working correctly?

@rburgst
Copy link
Contributor Author

rburgst commented Aug 31, 2021

I did test Mac. That was fine. Didn't check windows.

@lijy91
Copy link

lijy91 commented Sep 1, 2021

@hpoul hotkey_manager v0.1.0 is released. Please upgrade it.

@hpoul
Copy link
Collaborator

hpoul commented Sep 4, 2021

Great, I've updated hoteky_manager and window_manager to their latest versions. I'll merge, let's hope for the best 😅️ I can't really test windows or linux.. but at least it compiles.. 🤞

@hpoul hpoul merged commit f0d8002 into authpass:master Sep 4, 2021
@rburgst rburgst deleted the feature/totp-global-hotkey branch September 13, 2021 15:41
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.

4 participants