Skip to content

feat(shortcuts): WT-form desktop/Start-menu links on Win10 (niubash#211) - #290

Merged
caomengxuan666 merged 4 commits into
masterfrom
feat/211-wt-shortcut
Oct 13, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
feat/211-wt-shortcut

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #211

Completes the remaining implementable scope of #211 (the WT profile auto-registration half already landed on master via windows_terminal.rs + the wtprofile installer task). Owner direction from the issue thread: default to the WT form; conhost stays the fallback; other terminals stay out of scope.

What changed

1. wt.exe resolution, robust order (issue point 3) — crates/niubash-runtime/src/shortcut.rs::resolve_wt_exe

  1. per-user WindowsApps execution alias %LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe — stable and Preview share this alias and the OS hands it to whichever install won, so resolving the alias file itself sidesteps the preemption question entirely;
  2. process PATH (scoop/choco/unpackaged installs);
  3. App Paths\wt.exe registry default value, HKCU then HKLM (expand-string aware).

2. Shortcut form branch — ShortcutPlan::build / wt_form_eligible

  • WT form: target = resolved wt.exe, arguments -p Niubash, working dir %USERPROFILE%, Niubash icon (bundled .ico, falling back to the niu.exe embedded icon — a .lnk can't use the profile's PNG). Eligibility needs both a resolved wt.exe and the registered profile (wt -p against an unknown profile errors out), via the new windows_terminal::niubash_profile_registered probe.
  • conhost baseline: direct niu.exe, byte-for-byte the shape the installer always made — machines without WT (or with the profile task skipped) keep the status quo.

3. New verb niu --install-wt-shortcuts [\--quiet\] [\--update-only\] [\--desktop <dir>\] [\--start-menu <dir>\]
The installer passes {autodesktop}/{group} explicitly (no Known-Folder guessing on the Rust side); --update-only rewrites only links that already exist, so a declined desktop-icon task never grows a desktop icon. Standalone runs create both links in known folders. The links keep the exact installer paths (...\Niubash.lnk), so Inno's uninstall log stays authoritative after the in-place rewrite.

4. installer/niubash.iss — new desktopicon task (default checked, per owner's WT-default direction); post-install step runs --install-wt-shortcuts --quiet --update-only gated on the existing wtprofile task, after the profile lands.

Implementation note (COM)

windows-sys 0.59 carries COM free functions but no interface types, so IShellLinkW/IPersistFile vtables are hand-declared in SDK order. Verified against shobjidl_core.h: IShellLinkW::SetPath is the interface's LAST method (after Resolve) — the common interop listings that show it second are wrong, and that slot silently hits GetIDList (returns S_FALSE, sets nothing). The round-trip test pins the whole call set.

Test matrix

Case Pinned by
wt.exe alias present → alias wins over PATH/registry resolve_prefers_windowsapps_alias_over_path_and_registry
alias absent → PATH tier; PATH absent → registry tier; all absent → None resolve_falls_back_to_path_then_registry, resolve_returns_none_when_all_missing
WT resolved → plan is wt.exe -p Niubash + home workdir + ico plan_uses_wt_form_when_wt_resolved
WT absent → conhost plan (direct niu.exe, no args) plan_keeps_conhost_form_without_wt
WT present but profile unregistered → not eligible (multi-channel stable+Preview settings probed) profile_registered_gate_matches_wt_form_eligibility, windows_terminal::profile_registration_detected_in_any_candidate
.lnk parameters (target/args/icon/workdir) survive a real write+read via shell-link COM tests/wt_shortcut_roundtrip.rs (3 tests, exercised on this machine)
update-only never grows absent links; create mode writes both install_shortcuts_updates_existing_and_skips_absent_links

Verification: cargo fmt --check --all clean; cargo test -p niubash-runtime --locked fully green (471 lib + 20 integration incl. the 3 new round-trip tests); root non-ConPTY integration green except two pre-existing, environment-reproducible failures on pristine origin/master in this environment (tests/repl_command.rs::command_mode_compound_commands_keep_home_paths_native — cd ~ prints POSIX-style PWD=/c/... with HOME="" under this shell profile — and the ConPTY issue182 interactive test, which is out of this PR's non-ConPTY scope). Both reproduce byte-identically without this branch's changes; not regressions.

Real smoke (this machine, not CI)

niu --install-wt-shortcuts was run against this machine's real WT Preview install (issue author's environment): both links written, and verified through the Windows shell COM independently — TargetPath = C:\Users\cmx\AppData\Local\Microsoft\WindowsApps\wt.exe, Arguments = -p Niubash, WorkingDirectory = C:\Users\cmx.

Release checklist (real installer smoke — deferred per plan)

  • Run the Inno-built installer on a Win10 machine with WT: desktopicon + wtprofile tasks on → after setup, desktop + Start-menu links carry wt.exe -p Niubash; double-click opens the Niubash WT profile with Nerd Font rendering, CWD %USERPROFILE% (not System32).
  • Same installer with the desktopicon task unchecked → no desktop link appears (update-only must not grow one).
  • Win10 machine without WT → links stay the direct-niu.exe conhost form; launching works.
  • Uninstall removes both rewritten links (Inno log authority over the in-place rewrite).
  • Upgrade install (checkedonce memory): previously created links get rewritten to the WT form.

Win10 has no default-terminal setting, so direct-exe shortcuts are hosted
by conhost. When a wt.exe resolves AND the Niubash WT profile is
registered, generated shortcuts take the wt.exe -p Niubash form; without
WT the conhost baseline is kept unchanged.

- shortcut.rs: wt.exe resolution (WindowsApps alias -> PATH -> App Paths
  registry HKCU/HKLM), pure plan construction, and .lnk write/read through
  the shell-link COM object (vtables hand-declared: windows-sys 0.59 has
  no interface types; SetPath is the interface's LAST method, verified
  against shobjidl_core.h).
- niu --install-wt-shortcuts [--update-only] [--desktop|--start-menu]:
  installer handoff passes {autodesktop}/{group} explicitly and only
  rewrites links that already exist, so a declined desktop icon is never
  grown; standalone runs create both in known folders.
- niubash.iss: desktopicon task (default on) plus a post-install rewrite
  step gated on the wtprofile task; same link paths keep Inno's uninstall
  log authoritative.
- windows_terminal.rs: expose NIU_PROFILE_NAME and the profile-registered
  probe that gates the WT form.

Tests: resolution-order matrix, plan/conhost/WT-form parameter asserts,
multi-settings profile-registration matrix, and a COM round-trip that
writes .lnk files and reads them back through the same vtables. Real
installer smoke is a release-checklist item (PR body); the verb was
smoked against this machine's real WT Preview alias.
…ndtrip path asserts

The CI cross-check lanes caught install_shortcuts calling the
#[cfg(windows)] write_shortcut on unix targets (E0425); the verb entry
in main.rs is already Windows-gated, so the lib function gets the same
gate. The COM roundtrip asserts now compare canonicalized paths —
the shell link resolves SetPath inputs to long form, so a target
staged under an 8.3 short-name temp dir (CI RUNNER~1) read back
runneradmin and tripped exact-match equality.
…dows

The unix acceptance lanes caught leftover non-Windows orphans: the
Context/Result imports and the top-level wide-string helpers serve
only the Windows COM paths, so they carry the same cfg gate (the
function-scoped registry helper keeps its own inner to_wide).
@caomengxuan666
caomengxuan666 merged commit 1f2180d into master Oct 13, 2026
9 checks passed
@caomengxuan666
caomengxuan666 deleted the feat/211-wt-shortcut branch October 13, 2026 03:09
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
…1.4.0 section (#326)

- The [Unreleased] entries (#284/#287, #293-#304, #313) move into
  [1.4.0]; [Unreleased] is empty again.
- Newly recorded (today's wave): Git Bash compatible factory default
  prompt (#292, headline), WT-form shortcuts (#290/#211), the paste
  burst trailing-Enter fix (#308/#291), self-update SHA256 + release
  pinning (#311/#312), managed-block convergence (#324), completion
  tables/NIU_COMPDEFS/NIU_ENV probe (#305-#307), -s on-demand stdin
  (rubash#586 host half), bash/rbash invocation faces (#321/#322).
- Older gaps recorded: closed-stdout pipe contract (#245/#286), history
  session-end write-back (#265), sh POSIX contract (#262), PWD persona
  alignment (#283), one-shot fast path (#270), --cwd-state (#272),
  --encoded-command (#271), REPL-command highlighting (#281), docs
  passes (#255/#225/#226/#227), MSRV (#267), easter-egg prune (#264).

CHANGELOG-only change; no version claims.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TODO] Win10 桌面快捷方式默认 conhost:建议检测 WT 并生成 wt.exe -p 快捷方式 + 自动注册 WT 配置档

1 participant