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
Hide console on Windows #1353
Hide console on Windows #1353
Conversation
When not adding -ldflags "-H=windowsgui" to go build/run/install on Windows, a console window shows up when you run the program. Hide this in an init function. The console window might be visible for a split second but then disappears.
What if I am running on a console and I just type "go run ."? |
If you start from the console, as well as from an IDE, nothing happens. That is why there is a check for whether the thread is the one who created the console. Windows will not create a console for you if it already has stdout set. In that case it uses it as is. Only if stdout is not assigned when the program starts, Windows will create the console for you. Hence, the owner of the console is the program itself. |
I have been using this code for years, it works as you would expect, only closing the console if it was created because Go creates exe type console and not GUI: https://github.com/gonutz/wui/blob/ac034522c879ac42ca5abeb7aa930a6998340d65/window.go#L953 |
But when you package the app for installation the console is not displayed though right? |
If they specify ldflags -H=windowsgui, the console is suppressed anyway. Windows will not try to create one in the first place, thus nothing happens in that case. |
Yes, our tools do just that. |
Sure, this is why I am asking feedback. Personally I do not mind flickering during development. Most of the time it is not even noticable (on my machine at least). This is more to not have that ugly window there during development. For a release product I would always build with -H=windowsgui anyway. This is more a feature for the developer while debugging. |
What is your similar thing on OS X? |
|
Perhaps you can expand on your "during development" workflow? If the console is not closed from IDE or command line launches what other development types exist that trigger new terminals being opened? This was initially an issue when installing apps with this not set, which is why the package tool adds it. |
Oh well, you are right. It turned up for me when In that case, I will just close this PR and everything stays as is :-) |
OK. Thanks for helping us to improve - sorry that we'd got something in place already :) |
Let me just say, you are doing a really good job, hats off. Keep up the good work :-) |
When not adding -ldflags "-H=windowsgui" to go build/run/install on Windows, a console window shows up when you run the program.
This PR hides the console in an init function. The console window might be visible for a split second but then disappears. This is nice for debugging and might even be used for deployment.
There are some considerations, though:
Do we always want to hide the console? It might be useful for programmers during development. Usually you will work in your IDE which shows you the stdout and stderr output but if you really want to click on your .exe and see output, you can using the default console window. We might add an option to not hide the console on Windows.
Is this the right place? I just put the code in an init function because I want it to happen right when the program starts and because I do not know where else to put it. What is the code path that every fyne app takes? waiting until ShowAndRun would be too late, settings up things, maybe pulling a database for example, it might take a while for the program to get to show the GUI. Until then we do not want the console to be visible, possibly printing debug output. As said in 1. this might be good for the developer but if this is deployed, it is bad.
This PR was easy for me to make, I do not expect it to be merged without discussion but I wanted to get something out there that people can try before deciding if we really want this to happen and if yes, how to do it.