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

Hide console on Windows #1353

Closed
wants to merge 1 commit into from
Closed

Hide console on Windows #1353

wants to merge 1 commit into from

Conversation

gonutz
Copy link

@gonutz gonutz commented Oct 1, 2020

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:

  1. 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.

  2. 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.

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.
@andydotxyz
Copy link
Member

What if I am running on a console and I just type "go run ."?

@gonutz
Copy link
Author

gonutz commented Oct 1, 2020

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.

@gonutz
Copy link
Author

gonutz commented Oct 1, 2020

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

https://github.com/gonutz/prototype/blob/98c5cc2572eea5cd47936ac8bf00f20746a335d4/draw/window_windows.go#L339

@andydotxyz
Copy link
Member

But when you package the app for installation the console is not displayed though right?
"fyne package" or "fyne install" (or fyne-cross builds for that matter) all suppress the console already...

@gonutz
Copy link
Author

gonutz commented Oct 1, 2020

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.

@andydotxyz
Copy link
Member

Yes, our tools do just that.
I'm just not a fan of the workarounds that flicker windows on to screen (there is a similar workaround to a macOS bug that we won't land because it's just ugly).
How about we just push people to use the tools provided? :)

@gonutz
Copy link
Author

gonutz commented Oct 1, 2020

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.

@gonutz
Copy link
Author

gonutz commented Oct 1, 2020

What is your similar thing on OS X?

@andydotxyz
Copy link
Member

What is your similar thing on OS X?

#505

@andydotxyz
Copy link
Member

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.

@gonutz
Copy link
Author

gonutz commented Oct 1, 2020

Oh well, you are right. It turned up for me when go building your demo apps. Opening them via double-click on the icon opened the console window. But of course when I went to my IDE to put this in, it did not appear. So really this would actually be for deployment but not a good enough solution for that.

In that case, I will just close this PR and everything stays as is :-)

@andydotxyz
Copy link
Member

OK. Thanks for helping us to improve - sorry that we'd got something in place already :)

@gonutz
Copy link
Author

gonutz commented Oct 1, 2020

Let me just say, you are doing a really good job, hats off. Keep up the good work :-)

@gonutz gonutz closed this Oct 1, 2020
@gonutz gonutz deleted the master branch December 10, 2021 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants