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

Allow UIAccess on Windows to work with elevated apps #19

Open
eugenesvk opened this issue Apr 18, 2024 · 9 comments
Open

Allow UIAccess on Windows to work with elevated apps #19

eugenesvk opened this issue Apr 18, 2024 · 9 comments
Labels
enhancement New feature or request PRs welcome

Comments

@eugenesvk
Copy link

eugenesvk commented Apr 18, 2024

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

  • your app with UIA and regular kanata, launches, but doesn't work in elevated apps
  • your app without UIA and UIA kanata, crashes )

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
Copy link
Owner

rszyma commented Apr 18, 2024

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
Copy link
Owner

rszyma commented Apr 18, 2024

The build command for windows is here

kanata-tray/justfile

Lines 14 to 15 in 7739730

build_release_windows version="latest":
GOOS=windows CGO_ENABLED=1 GO111MODULE=on go build -ldflags "-H=windowsgui -s -w -X 'main.buildVersion={{version}}' -X 'main.buildHash=$(git rev-parse HEAD)' -X 'main.buildDate=$(date -u)'" -trimpath -o dist/kanata-tray.exe

@eugenesvk
Copy link
Author

eugenesvk commented Apr 19, 2024

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
Copy link
Owner

rszyma commented Apr 19, 2024

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
Copy link
Author

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

@rszyma
Copy link
Owner

rszyma commented Apr 19, 2024

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.

jtroo pushed a commit to jtroo/kanata that referenced this issue May 7, 2024
Add a `gui` feature allowing compiling kanata as a native tray-only
Windows GUI application. This greatly simplifies launching the app on
startup instead of resorting to hacks like this:

	#193

It gets rid of the console window and also allows UIAccess to work in
elevated apps. There is a kanata-tray project which helps with the
former, but doesn't allow UIAccess.

	issue: (rszyma/kanata-tray#19)

It also supports custom icon indicator per config and per layer within
the same config, as well as (re)loading configs. Other configs are
passed as cli args in the `.lnk` file

It also supports being launched from a console as a regular cli app, so
it's possible to replace the main `kanata.exe` with this or let it be
some separate `kanata-tray.exe` file

It also opens an avenue to more interesting ideas, but will add those in
a separate issue #991
@eugenesvk
Copy link
Author

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
Copy link
Owner

rszyma commented May 19, 2024

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
Copy link
Author

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

@rszyma rszyma added enhancement New feature or request PRs welcome labels Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PRs welcome
Projects
None yet
Development

No branches or pull requests

2 participants