ofek / pyapp

Runtime installer for Python applications
https://ofek.dev/pyapp/
1.1k stars 24 forks source link

PyApp with GUI program - disable console on Windows #96

Closed trappitsch closed 3 months ago

trappitsch commented 3 months ago

When running PyApp packaged GUI on Windows, a console window is generally open which is not really the wanted behavior. This is not the case on Linux, don't know right how it is on macos...

In order run a GUI without a console windows on Windows, two things would be required as far as I can see it:

  1. Add top-level crate attribute #![windows_subsystem = "windows"] to main.rs, see RFC 1665
  2. Execute the program with pythonw.exe instead of python.exe when running.

For 1 I currently don't see a good way of using an environmental variable. One possible solution would be to add

[features]

gui = []

to Cargo.toml. This way, the windows_subsystem = "windows" top-level crate attribute could simply be activated during compilation with cargo build --features gui.

I'll prepare a draft PR that implements this, plus the pythonw.exe usage for running the program. Let me know what you think, this is just an idea at this point... the additions in the PR should make it easier to see hopefully.

Tremeschin commented 3 months ago

It's been a while since I used pyapp and I might be wrong on a few comments, but I have some questions/worries:

IIRC if we open two processed of pyapp and the venv installation wasn't finished, one or both will fail. I had to run app.exe self restore command on a terminal to start fresh (or even manually delete the virtualenv folder)

Is there a mechanism to automatically run the self restore command on installation or imports failure, and could this be an issue when a user clicks the app, it takes a while to load/install and they spawn many processes of it?

~

For that, it's probably feature creep, but a quick pyinstaller-like splash screen would be nice to have-

-or even detecting same-name processes of the pyapp binary already running and giving preference to the older one*

*This might NOOP and require task managers strategy of sending a challenge signal to the process we might replace to detect if softlocked or healthy

trappitsch commented 3 months ago

I agree with your worries. These started to come up when I was testing the implementation as well. There's a longer explanation / write up in the PR, see #97. The short is:

shenjackyuanjie commented 3 months ago

about subsystem = "windows" I have a rust project about a caller wrapper in rust it may can help you doing it

https://github.com/shenjackyuanjie/wrapper-rs

ofek commented 3 months ago

Resolved by https://github.com/ofek/pyapp/pull/97