rszyma / kanata-tray

Tray Icon for Kanata
GNU General Public License v3.0
33 stars 1 forks source link

Allow UIAccess on Windows to work with elevated apps #19

Open eugenesvk opened 2 months ago

eugenesvk commented 2 months ago

Kanata.exe will be able to work in elevated apps on Windows when this is merged.

But I couldn't make it work with your tray app. Even if both are signed in the same way with UIAccess enabled, and within Program Files, I get an error while loading kanata (and there are no logs since I guess logs are only available from kanata after it starts)

(also tried

Not sure if there is something special you need to do to load another UIA app, but would be nice if that were possible

rszyma commented 2 months ago

The prebult windows exe is compiled with -W=windowsgui to hide console window. But that also disables stdin/out, and there would probably be some more info about the error.

As aside, I'll soon be adding a button in tray menu to allow reading kanata-tray logs with the disabled console too. For now though if you want to logs, you need to compile it manually with that -W ldflag removed.

rszyma commented 2 months ago

The build command for windows is here https://github.com/rszyma/kanata-tray/blob/7739730dd21e057af4ef55fb350743f0fdaabeb0/justfile#L14-L15

eugenesvk commented 2 months ago

So it's how you launch it: you're still launching kanata.exe as a cli app with cli flags, and I get the same message when I try to launch kanata from a terminal, but double click works

Kanata process terminated with an error: failed to start process: fork/exec C:\Program Files\5 Util\6 Key&Mouse\kanata\kanata.exe: The requested operation requires elevation.

rszyma commented 2 months ago

https://gist.github.com/jerblack/d0eb182cc5a1c1d92d92a4c4fcc416c6 this seems like it could work

I rarely use Windows these days, it's unlikely I'll work on it. However PR's welcome

eugenesvk commented 2 months ago

That seems like a way to launch kanata elevated, but this isn't needed, UIAccess works without elevation on "double-click" launch.

rszyma commented 2 months ago

It could still be useful depending on whether we want entire kanata-tray app to be elavated (would all spawned subprocesses be elevated automatically too? Like in linux?) or popup UAC every time a preset is ran for which we explicitly declare (with an new option in config) that we want elevation for kanata.

Or even better, we could implement both, maybe.

eugenesvk commented 1 month ago

FYI found the following tidbid on launching UIAcceess apps:

UIAccess-enabled programs cannot be launched using CreateProcess and fail with ERROR_ELEVATION_REQUIRED, but launching them using ShellExecute works without elevation

rszyma commented 1 month ago

Thanks for the info. Though, I've no plans to implement it, especially for Windows, because I've recently uninstalled it (previously ran dual boot, but mainly driving Linux). But if you feel like adding it, feel free to send PR.

BTW, now that we have native tray icon support in kanata, I'm thinking about deprecating and archiving this repo. I'll wait with pulling the trigger when there's also native Linux and macOS support added.

eugenesvk commented 1 month ago

That's fine, just FYI, on Windows I'm also using the native gui version, so don't plan to add it here, especially since I know no GO