urob / komotray

A system tray status indicator for komorebi
28 stars 4 forks source link

Autohotkey version 2? #1

Open Zerogaku opened 7 months ago

Zerogaku commented 7 months ago

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 commented 7 months ago

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

Zerogaku commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

urob commented 7 months ago

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

As long as it supports v2 it should work

Zerogaku commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

@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 commented 7 months ago

@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 commented 4 months ago

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