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

Console attachment logic #30

Closed
ctrueden opened this issue Feb 1, 2024 · 6 comments
Closed

Console attachment logic #30

ctrueden opened this issue Feb 1, 2024 · 6 comments
Assignees

Comments

@ctrueden
Copy link
Member

ctrueden commented Feb 1, 2024

The ImageJ Launcher has logic to attach to a console using freopen with channels CONIN$ (stdin) and CONOUT$ (stdout and stderr), as well as create a new console using FreeConsole() + AllocConsole(). And it has a hidden option --console/--attach-console which calls attach_win_console() to do this. It also has --new-console to create a new console. Is this ever actually necessary?

@imagesc-bot
Copy link

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

@ctrueden
Copy link
Member Author

ctrueden commented May 3, 2024

Tangentially related is this SO post, which talks about the -mwindows and -mconsole flags to gcc when building with MinGW (which Jaunch does).

@ctrueden
Copy link
Member Author

ctrueden commented May 3, 2024

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.

hinerm added a commit that referenced this issue Jun 18, 2024
This is preferable to always creating and showing a new console.

Closes #24.

For a complete solution, see #30
@hinerm
Copy link
Collaborator

hinerm commented Jun 18, 2024

Just noting that in 392c60e 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?

@hinerm
Copy link
Collaborator

hinerm commented Jun 20, 2024

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.

@hinerm hinerm added this to Fiji Fit Jul 12, 2024
@hinerm hinerm self-assigned this Jul 12, 2024
@hinerm hinerm moved this to Backlog in Fiji Fit Jul 12, 2024
@hinerm
Copy link
Collaborator

hinerm commented Jul 15, 2024

Since the ctrl + c is not Jaunch specific and covered in fiji/fiji#347, and OS focus is also a separate issue covered in #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.

@hinerm hinerm closed this as completed Jul 15, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in Fiji Fit Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants