Skip to content

Fix Windows Terminal window staying open#223

Merged
davidnewhall merged 2 commits intoUnpackerr:mainfrom
jon-sanders:patch-1
May 26, 2023
Merged

Fix Windows Terminal window staying open#223
davidnewhall merged 2 commits intoUnpackerr:mainfrom
jon-sanders:patch-1

Conversation

@jon-sanders
Copy link
Contributor

Adding "-H=windowsgui" to the Makefile seems to correct the issue where Windows Terminal windows stay open after launch.

Adding "-H=windowsgui" to the Makefile seems to correct the issue where Windows Terminal windows stay open after launch.
@davidnewhall
Copy link
Collaborator

davidnewhall commented Sep 14, 2022

If the terminal is staying open, it means the application experienced a panic. Can you check your logs and console output for that please?

https://github.com/davidnewhall/unpackerr/blob/25cb291f1c0949a402109d497424f9f845bc30b7/main.go#L16

@davidnewhall
Copy link
Collaborator

The other situation this comes up in is when you switch your default terminal in Windows from cmd.exe to the new Windows Terminal. This new terminal does not provide the same APIs and Go applications are not able to hide the Windows that are created. I fought this behavior a long time with another user to no avail. Microsoft acknowledged the problem with their deprecation of specific API methods, and I'm really not sure where that went. Does it work now? I don't know (I'm not a Windows user). ref: microsoft/terminal#12570

@jon-sanders
Copy link
Contributor Author

This is to fix the issue you were discussing in the Discord. There is no error in the logs or console, but on launch a blank Windows Terminal window is launched. Closing this window closes unpackerr. Adding the above flag to the windows-specific build flags prevented the empty window from opening, and as far as I can tell unpackerr still functions as before.

@davidnewhall
Copy link
Collaborator

I discuss many issues in Discord. If you could link it, it may jog my memory. This is unfortunately not a change I can accept. What we need to do is figure out why hiding the terminal window doesn't work.

@davidnewhall
Copy link
Collaborator

Check out the workaround they found for nzbget. Can you try this and see if it works? nzbget/nzbget#792 (comment)

@jon-sanders
Copy link
Contributor Author

This workaround does solve the issue, and the console window disappears after unpackerr starts.

It does appear that the console is immediately hidden on launch, and only shown again in case of an error on startup. Would it make sense to add the windowsgui flag (this builds as a GUI binary and prevents the console appearing) and communicate the error with a Windows MessageBox directly? I have implemented this and could add it to the pull request.

@davidnewhall
Copy link
Collaborator

I'm not really following what you're proposing. I do not really want to remove the GUI window entirely. I've written a number of apps that have to support multiple OSes, including Windows, and I've had much better success leaving that flag off and hiding the window. This new Windows Terminal fiasco is going to require some changes to keep working I can see. I'd like to figure out how to hide it.

only shown again in case of an error on startup

It's shown any time panic() is thrown. Some panic messages fail to write to the log file, and showing the console window can help troubleshoot because the message is displayed there. You actually make a good point though, and I think I should also show it if the startup throws an error. I can't tell you how many people typo their config and the app refuses to start. The "solution" is to open it from a cmd window so you can see the error.

@davidnewhall davidnewhall merged commit f5294f6 into Unpackerr:main May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants