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

Autohotkey version 2? #1

Open
Zerogaku opened this issue Feb 21, 2024 · 10 comments
Open

Autohotkey version 2? #1

Zerogaku opened this issue Feb 21, 2024 · 10 comments

Comments

@Zerogaku
Copy link

hey can there be an update to version 2? I tried to modify the autohotkey script using a v2 script converter but i had no luck.

@urob
Copy link
Owner

urob commented Feb 21, 2024

It's not something that I need but a PR would definitely be welcome :)

@Zerogaku
Copy link
Author

I could maybe attempt it, but can you explain to me the folder structure a bit, i know this is a wrapper for the komorebi configuration as well, if i change the syntax won't it affect the rest of the files? I'm assumimng the exe is only for autostarting, i'm not sure what the json.ahk is though

@urob
Copy link
Owner

urob commented Feb 21, 2024

The main script is komotray.ahk. The exe is just a compiled version for people who don't have AHK v1 installed locally. The lib folders contains one external library that is used to read the pipe output, which is just a json db with the state of komorebi. The config folder contains my personal configuration, but that's somewhat independent from the rest.

To port to v2, you'll need to find an external json library that supports v2. I am using this one: https://github.com/G33kDude/cJson.ahk. I think the maintainer is working on porting themselves, but there might be other options as well.

(If you load the config folder, you'll also need to port bindings.ahk)

@Zerogaku
Copy link
Author

would i need to use a more updated version of the library? like this?

@urob
Copy link
Owner

urob commented Feb 21, 2024

would i need to use a more updated version of the library? like this?

As long as it supports v2 it should work

@Zerogaku
Copy link
Author

Zerogaku commented Feb 22, 2024

Hey i made an attempt on moving the syntax from v1 to v2, but got stuck, i used the v2 version of json library you used while removing some parts of the code since they weren't being used and were also causing a tone of errors, I'm not sure if it's a simple fix but I'm getting:

Error: This value of type "VarRef" has no property named "Ptr".

	071: Continue
	072: }
▶	074: State := JSON.Load(StrGet(&Data, Bytes, "UTF-8")).state
	077: Paused := State.is_paused
	078: Screen := State.Monitors.focused

To be honest i'm still relatively new to all this so any help would be appreciated, some parameters/variables used don't seem defined anywhere like BytesToRead, Bytes and Data, defining them made the errors go away, also apparently some of the functions that didn't need parameters needed them for the errors to go away, so i used * as a placeholder parameter, worst one was StartKomorebi, it kept giving me an invalid callback function error, same as the others that required parameters, but it already had one, so i just moved all the variables under the functions and it got fixed.

The pipes seemed to have been created, though i'm not sure how to confirm if it's receiving data, running MsgBox on the DllCalls gave some arbitrary numbers.

Ignore any jank like the keybinding section being completely commented out 😅 I was trying to get it to use the %USERPROFILE% directory but it seemed not to work, here is the repo: https://github.com/Zerogaku/komotray-ahk-v2

by the way just so I understand, autohotkey or to be precise the DLLCall function, is taking the json recieved from the pipe, putting it in a "temporary buffer" with peek namedpipe and reading it with readfile, and running it into the library so the json is then converted into and object that autohotkey can then read and use, or is it the other way around, object to json?

@Zerogaku
Copy link
Author

Zerogaku commented Feb 23, 2024

I made some progress with the script, it's able to run now, it creates the pipe and gets komorebi to subscribe, but then all komorebi commands cease to function, ahk specific keybindings work (liike openings apps and general remaps) but anything with a komorebic command attached to it will fail, but it seems successfully to send 1 hotkey before stopping though, komorebic state and neither will komorebic stop, i have to kill komorebi from the task manager to get it working again, komorebic check works though, and after messing with MsgBox i was able to infer that the main problem with the script wasn't komorebic connecting, it was the:

    if (Bytes <= 1) {
        Continue
    }

in the loop that caused the problem, anything placed after wouldn't work and removing it got the MsgBox working, MsgBox also worked when placed at the very top of the loop as well, but obviously removing that seemed to also stop the script from filtering the info properly. I pushed the recent changes to this repo

then again, it could also be that komorebi is not sending data at all, which is why the script stops there, so i'm not sure

@Zerogaku
Copy link
Author

@urob Hey good news, I managed to make the v2 script functional 🎉

But it's not a fork so I can't do a pull request, I'm hoping you could maybe create a new branch called v2 and put the contents of the repo there?

@urob
Copy link
Owner

urob commented Feb 26, 2024

@urob Hey good news, I managed to make the v2 script functional 🎉

But it's not a fork so I can't do a pull request, I'm hoping you could maybe create a new branch called v2 and put the contents of the repo there?

Sounds good! I'm a bit busy these days but I'll try to review and add a branch once things lighten up.

@GerardvSchie
Copy link

I'm dumb, didn't look at the issues before rewriting it to V2 myself as well 🙈
Somehow someway I have the scroll over tray icon working. But it could be something that Autohotkey fixed, no clue since your code looks correct @Zerogaku
Very sorry for not using your hard work, would've saved me some time for sure ^^

I'll make a fork PR so you can see the changes and have some comparison material

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

No branches or pull requests

3 participants