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

Use better console hiding API #4051

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

HebaruSan
Copy link
Member

Background

Windows 11 recently introduced a new virtual terminal to replace the Windows console. It behaves much more like standard Unix terminals:

Problems

  • If you open a console (old style) in Windows and then run ckan.exe without the --show-console flag (and none of the CmdLine commands like list or install), your console windows closes. This is not typical behavior for a command that you launch from a console and can be very surprising.
  • If you double click ckan.exe in Windows 11, the virtual terminal stays open the entire time you're using the GUI

Causes

Since ckan.exe is both a console application and a GUI application, Windows always automatically opens a console for it at launch. This is not desirable when running in GUI mode, so the GUI closes its console by finding it with GetConsoleWindow and then hiding it with ShowWindow.

  • This approach is too aggressive because it doesn't care whether that console is still in use by other applications
  • The new virtual terminal doesn't support GetConsoleWindow, so the whole approach breaks down anyway

Changes

Now we use FreeConsole instead of ShowWindow and GetConsoleWindow. This API just detaches the current process from its console or terminal, so it won't aggressively close consoles that are still in use by other processes (such as a shell), but will auto-close any terminal that is only associated with ckan.exe. It is also supported by the new virtual terminals (see microsoft/terminal#14544), so console hiding should now work on Win11.

Fixes #3902.

@HebaruSan HebaruSan added Bug Something is not working as intended Easy This is easy to fix GUI Issues affecting the interactive GUI Windows Issues specific for Windows labels Mar 6, 2024
@HebaruSan HebaruSan merged commit 56fe6e7 into KSP-CKAN:master Mar 6, 2024
8 checks passed
@HebaruSan HebaruSan deleted the fix/console-hiding branch March 6, 2024 19:48
@HebaruSan
Copy link
Member Author

Hi @errolkokbas, the issue on Windows 10 is a bit different from the one reported in #2193, but we're hoping that the changes in this pull request will address it. If you'd like, you can try the dev build to test it out:

@errolkokbas
Copy link

errolkokbas commented Jul 8, 2024

Hi @errolkokbas, the issue on Windows 10 is a bit different from the one reported in #2193, but we're hoping that the changes in this pull request will address it. If you'd like, you can try the dev build to test it out:

* https://ksp-ckan.s3-us-west-2.amazonaws.com/ckan.exe

I'm on win11, tested the beta and it is correctly killing the terminal window again. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Easy This is easy to fix GUI Issues affecting the interactive GUI Windows Issues specific for Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] A Windows 11 update broke console hiding
2 participants