fix(terminal): silence ShellExecute dialog when launching Windows Terminal#2363
fix(terminal): silence ShellExecute dialog when launching Windows Terminal#2363JWM0203 wants to merge 1 commit intofarion1231:mainfrom
Conversation
…minal When the user picks Windows Terminal as the preferred terminal, we launch it via `cmd /C start wt cmd /K <bat>`. If `start` cannot resolve `wt` it routes through ShellExecute, which pops a modal "Windows 找不到文件 'wt'" dialog and only *then* returns failure. The existing fallback to cmd fires after the dialog is already on screen, so the user sees the popup on every launch. This commonly hits users who run cc-switch elevated: the SYSTEM PATH inherited by an admin process lacks the per-user `%LOCALAPPDATA%\Microsoft\WindowsApps` directory where `wt.exe` lives. Resolve a concrete path to wt.exe up-front via `where wt`, with an explicit fallback to the user's WindowsApps alias location. Pass the resolved path to `start`, which avoids the ShellExecute dialog. If resolution fails, return Err so the existing cmd fallback kicks in silently — no modal popup either way. Same fix applied at both Windows launch sites (`launch_windows_terminal` and `launch_terminal_running`).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b6e6a994fa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .output() | ||
| { | ||
| if output.status.success() { | ||
| let stdout = String::from_utf8_lossy(&output.stdout); |
There was a problem hiding this comment.
Use Windows encoding when reading
where wt output
resolve_windows_terminal_path() decodes cmd /C where wt output with String::from_utf8_lossy, but cmd pipe output is not guaranteed to be UTF-8 (it follows the active Windows code page unless /U is used). If the resolved path contains non-ASCII characters (for example, localized profile names under %LOCALAPPDATA%), the decoded path becomes corrupted, start cannot launch wt.exe, and the app falls back to cmd even though Windows Terminal is actually present.
Useful? React with 👍 / 👎.
Summary
Fixes a long-standing bug where picking Windows Terminal as the preferred terminal causes a modal dialog
Windows 找不到文件 'wt'to pop up on every launch, even though the existing fallback tocmdis supposed to handle the failure silently.Root cause
launch_windows_terminaland the Windows branch oflaunch_terminal_runningboth invoke:which expands to
cmd /C start wt cmd /K <bat>. Whenstartcannot resolvewt, it routes throughShellExecute, which first pops a modal "Windows cannot find" dialog and only then returns failure. By the time the existingresult.is_err()cmd-fallback fires, the user has already seen the popup.This commonly hits users who run cc-switch elevated: an admin-elevated process inherits the SYSTEM PATH, which lacks the per-user
%LOCALAPPDATA%\Microsoft\WindowsAppsdirectory wherewt.exelives — so even thoughwtis installed,start wtcan't find it.Fix
Resolve a concrete path to
wt.exebefore invokingstart:where wt(covers the normal case).%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe(covers the elevated-launch scenario).Err(...)so the existing cmd fallback path kicks in cleanly — no modal dialog.When
wt.exeis found, pass the full resolved path tostart(with an empty title argument:start "" "<full path>" cmd /K <bat>).ShellExecuteagainst a concrete path doesn't show the "cannot find" dialog.The change is minimal and contained: one new helper
resolve_windows_terminal_path()plus a two-line replacement at each of the two existing Windows launch sites.Test plan
pnpm tauri build --no-bundleon Windows 11 Pro 23H2 (MSVC 14.44, rustc 1.95.0)cmdandPowerShellselections continue to work unchanged