Closed ctrueden closed 1 week ago
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/jaunch-a-new-java-launcher-test-fiji-with-java-21/92058/1
Tangentially related is this SO post, which talks about the -mwindows
and -mconsole
flags to gcc when building with MinGW (which Jaunch does).
What we really need though is to attach contingently to the console, depending on whether one is already active. And only pop a new console when --new-console
is given as a command line argument.
Just noting that in https://github.com/apposed/jaunch/commit/392c60e690fa19c4c12b9003696ad334fbad4dec I set -mwindows
to disable the console. That may need to be reverted to attach to an existing console. Then just always try AttachConsole
and if it fails, contingently create a new one as suggested.
If we do go back to console mode I'm curious, if the AttachConsole
fails, if it will still make/show a new console. If so it looks like we can hide it (if --new-console
is not present) with
// Get the handle to the console window
HWND consoleWindow = GetConsoleWindow();
// Check if the console window handle is valid
if (consoleWindow != NULL) {
// Hide the console window
ShowWindow(consoleWindow, SW_HIDE);
}
Also wondering if this needs to be repeated for both the C and kotlin launchers?
That may need to be reverted to attach to an existing console.
Actually right now when I launch from an existing console Fiji just attaches to it. I'm actually not sure we need any other logic here at all.
edit: ctrl + c
doesn't fully kill Fiji when running from the console. Maybe because the kotlin launcher is in console mode? Investigation is needed..
edit: adding linkerOpts("-mwindows")
to the executable
section of build.gradle.kts
did not change this behavior, sadly.
Since the ctrl + c
is not Jaunch specific and covered in https://github.com/fiji/fiji/issues/347, and OS focus is also a separate issue covered in https://github.com/apposed/jaunch/issues/52 I think think the actual console attachment logic is working as desired and closing this issue. We can create a new one if behavior needs to be modified specifically with respect to console attachment.
The ImageJ Launcher has logic to attach to a console using
freopen
with channelsCONIN$
(stdin) andCONOUT$
(stdout and stderr), as well as create a new console usingFreeConsole()
+AllocConsole()
. And it has a hidden option--console
/--attach-console
which callsattach_win_console()
to do this. It also has--new-console
to create a new console. Is this ever actually necessary?