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

fix(shim): allow GUI applications to attach to the shell's console when launched using the GUI shim #5721

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- **scoop-checkup:** Don't throw 7zip error when external 7zip is used ([#5703](https://github.com/ScoopInstaller/Scoop/issues/5703))
- **config:** Warn users about misconfigured GitHub token ([#5777](https://github.com/ScoopInstaller/Scoop/issues/5777))
- **update/uninstall:** Remove items from PATH correctly ([#5833](https://github.com/ScoopInstaller/Scoop/issues/5833))
- **shim:** Allow GUI applications to attach to the shell's console when launched using the GUI shim ([#5721](https://github.com/ScoopInstaller/Scoop/issues/5721))

### Performance Improvements

Expand Down
2 changes: 1 addition & 1 deletion supporting/shimexe/bin/checksum.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9726c3a429009a5b22bd92cb8ab96724c670e164e7240e83f27b7c8b7bd1ca39 *shim.exe
1e4a9e4b305ef78b375159b25e2f8a90243584efd56ed6994072a8dfc2147ade *shim.exe
2 changes: 1 addition & 1 deletion supporting/shimexe/bin/checksum.sha512
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18a737674afde4d5e7e1647d8d1e98471bb260513c57739651f92fdf1647d76c92f0cd0a9bb458daf4eae4bdab9d31404162acf6d74a041e6415752b75d722e0 *shim.exe
f580833905e45b02a433c03647fb0caa3692336c8bde9621c286684629c78d1c56a292bea2887ea0ae941b8beec50322f31975c23ab5644c2b85f3c2108f383d *shim.exe
Binary file modified supporting/shimexe/bin/shim.exe
Binary file not shown.
13 changes: 12 additions & 1 deletion supporting/shimexe/shim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ static extern bool CreateProcess(string lpApplicationName,
out PROCESS_INFORMATION lpProcessInformation);
const int ERROR_ELEVATION_REQUIRED = 740;

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AttachConsole(int dwProcessId);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetConsoleWindow();

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct STARTUPINFO {
public Int32 cb;
Expand Down Expand Up @@ -89,7 +95,12 @@ static int Main(string[] args) {
cmd_args += pass_args;
}
if(!string.IsNullOrEmpty(cmd_args)) cmd_args = " " + cmd_args;
var cmd = "\"" + path + "\"" + cmd_args;
var cmd = path + cmd_args;

// Fix when GUI applications want to write to a console
if (GetConsoleWindow() == IntPtr.Zero) {
AttachConsole(-1);
}

if(!CreateProcess(null, cmd, IntPtr.Zero, IntPtr.Zero,
bInheritHandles: true,
Expand Down
Loading