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

feat: add extra_args #43

Merged
merged 2 commits into from
Dec 24, 2024
Merged

feat: add extra_args #43

merged 2 commits into from
Dec 24, 2024

Conversation

devsunb
Copy link
Contributor

@devsunb devsunb commented Dec 19, 2024

Closes #14

@rszyma
Copy link
Owner

rszyma commented Dec 19, 2024

Generally looking good.

2 things to think about:

  • should we restrict using some args within extra_args? Specifically:
    1. startup delay (default in kanata is 2000ms iirc, and we rely in tcp client code on this number being at most that);
    2. We already pass tcp port arg, and I guess kanata will error when it's passed the second time. Should we let kanata throw that error or should we catch it prematurely and throw a custom error guiding user to use tcp_port option instead?

@devsunb
Copy link
Contributor Author

devsunb commented Dec 22, 2024

That's interesting, I've tested it for some of the situations you mentioned.

startup delay

without --nodelay

/tmp/kanata_tray_lastrun.log

2024-12-22T15:40:12.261008+09:00 INFO kanata-tray config folder: /Users/sunb/dev/dotfiles/kanata
2024-12-22T15:40:12.396343+09:00 INFO Running preset 'Default'
2024-12-22T15:40:12.396911+09:00 INFO Running command: /Users/sunb/.local/bin/kanata -c=/Users/sunb/dev/dotfiles/kanata/test.kbd --port 5829
2024-12-22T15:40:12.398507+09:00 INFO Started kanata (pid=7497)
2024-12-22T15:40:14.903237+09:00 INFO Connected to kanata via TCP (127.0.0.1:53006)

/tmp/kanata_lastrun_125049367.log

15:40:12.4022 [INFO] kanata v1.8.0-prerelease-1 starting
15:40:12.4023 [WARN] No defcfg is defined. Consider whether the process-unmapped-keys defcfg option should be yes vs. no. Adding defcfg with process-unmapped-keys defined will remove this warning.
15:40:12.4023 [INFO] process unmapped keys: false
15:40:12.4024 [INFO] config file is valid
15:40:12.4024 [INFO] Sleeping for 2s. Please release all keys and don't press additional ones. Run kanata with --help to see how understand more and how to disable this sleep.
15:40:14.4304 [INFO] entering the processing loop
15:40:14.4306 [INFO] listening for event notifications to relay to connected clients
15:40:14.4308 [INFO] Init: catching only releases and sending immediately
15:40:14.4310 [INFO] entering the event loop
connected
driver_activated 1
driver_connected 0
driver_version_mismatched 0
15:40:14.9031 [INFO] new client connection, sending initial LayerChange event to inform them of current layer
15:40:14.9034 [INFO] listening for incoming messages 127.0.0.1:53006
driver_connected 1
15:40:16.2953 [INFO] Starting kanata proper
15:40:16.2955 [INFO] You may forcefully exit kanata by pressing lctl+spc+esc at any time. These keys refer to defsrc input, meaning BEFORE kanata remaps keys.

with --nodelay

extra_args = ['-n']

/tmp/kanata_tray_lastrun.log

2024-12-22T15:44:33.11213+09:00 INFO kanata-tray config folder: /Users/sunb/dev/dotfiles/kanata
2024-12-22T15:44:33.216229+09:00 INFO Running preset 'Default'
2024-12-22T15:44:33.216816+09:00 INFO Running command: /Users/sunb/.local/bin/kanata -c=/Users/sunb/dev/dotfiles/kanata/test.kbd --port 5829 -n
2024-12-22T15:44:33.218516+09:00 INFO Started kanata (pid=10447)
2024-12-22T15:44:35.723718+09:00 INFO Connected to kanata via TCP (127.0.0.1:53154)

/tmp/kanata_lastrun_15655503.log

15:44:33.2216 [INFO] kanata v1.8.0-prerelease-1 starting
15:44:33.2217 [WARN] No defcfg is defined. Consider whether the process-unmapped-keys defcfg option should be yes vs. no. Adding defcfg with process-unmapped-keys defined will remove this warning.
15:44:33.2217 [INFO] process unmapped keys: false
15:44:33.2217 [INFO] config file is valid
15:44:33.2218 [INFO] entering the processing loop
15:44:33.2218 [INFO] listening for event notifications to relay to connected clients
15:44:33.2218 [INFO] Starting kanata proper
15:44:33.2218 [INFO] You may forcefully exit kanata by pressing lctl+spc+esc at any time. These keys refer to defsrc input, meaning BEFORE kanata remaps keys.
15:44:33.2218 [INFO] entering the event loop
connected
driver_activated 1
driver_connected 0
driver_version_mismatched 0
driver_connected 1
15:44:35.7236 [INFO] new client connection, sending initial LayerChange event to inform them of current layer
15:44:35.7238 [INFO] listening for incoming messages 127.0.0.1:53154

Starting kanata proper is before new client connection but It looks like sending initial LayerChange event to inform them of current layer. So I think there's no problem.

with additional --port

extra_args = ['-p=12345']

/tmp/kanata_tray_lastrun.log

2024-12-22T15:53:47.936628+09:00 INFO kanata-tray config folder: /Users/sunb/dev/dotfiles/kanata
2024-12-22T15:53:48.057645+09:00 INFO Running preset 'Default'
2024-12-22T15:53:48.058216+09:00 INFO Running command: /Users/sunb/.local/bin/kanata -c=/Users/sunb/dev/dotfiles/kanata/test.kbd --port 5829 -p=12345
2024-12-22T15:53:48.059653+09:00 INFO Started kanata (pid=14991)
2024-12-22T15:53:50.565106+09:00 ERROR Failed to connect to kanata via TCP: dial tcp 127.0.0.1:5829: connect: connection refused
2024-12-22T15:53:50.762015+09:00 ERROR Failed to send ClientMessage: timeouted after 200 ms
2024-12-22T15:53:50.762146+09:00 INFO Waiting for all post-start-async hooks to exit
2024-12-22T15:53:50.762193+09:00 INFO All post-start-async hooks exited
2024-12-22T15:53:50.762371+09:00 ERROR Kanata runner terminated with an error: exit status 2

/tmp/kanata_lastrun_1201248634.log

error: the argument '--port <PORT or IP:PORT>' cannot be used multiple times

For more information, try '--help'.

I think this log is pretty clear, but I agree that it would be better if kanata-tray could guide user to use the tcp_port option instead.

after patch (commit c998224)

/tmp/kanata_tray_lastrun.log

2024-12-22T16:21:07.675162+09:00 INFO kanata-tray config folder: /Users/sunb/dev/dotfiles/kanata
2024-12-22T16:21:07.675628+09:00 ERROR kanata-tray exited with an error: loading config failed: port argument is not allowed in extra_args, use tcp_port instead

In the future, we might consider supporting nodelay or additional cfg options as dedicated options instead of extra_args, like tcp_port.
But since the kanata_config is currently implemented to be used in a single string format, we might want to open up additional options via extra_args for now to avoid breaking backwards compatibility.

@devsunb
Copy link
Contributor Author

devsunb commented Dec 22, 2024

Oh, and thanks for this awesome project!

@rszyma rszyma merged commit 7ebc44f into rszyma:main Dec 24, 2024
3 checks passed
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.

Feature: extra_args
2 participants