fix(cua-driver-rs)(install): re-register cua-driver-serve task on every install when it already exists - #1685
Conversation
…ry install when it already exists Symptom: user upgrades cua-driver (e.g. via install-local.ps1 to pick up the hidden-console wrapper from #1654), then runs `cua-driver autostart kick`, then sees a visible console window again. Repro confirmed: the scheduled task's <Command> path stayed hard-pointed at the previous release-install dir (a binary lacking the wrapper code), so kick spawned the OLD binary. Both install.ps1 and install-local.ps1 only re-registered the task when -AutoStart was passed. Users on the upgrade path don't pass it (they're not opting INTO autostart - they already have it). Fix: both scripts now sniff for an existing `cua-driver-serve` task post-install and re-register it pointing at the freshly-installed binary, even without -AutoStart. The re-register is idempotent and covers the upgrade case explicitly. If no task is registered, nothing changes (still need -AutoStart to opt in initially). End-to-end: user runs install-local.ps1, the just-built binary's REGISTER_PS produces the wrapped task action, kick now spawns hidden. Replaced em-dashes in added comments with ASCII hyphens - the file gets rewritten as UTF-8 on edit, but PS 5.1's parser had read older em-dashes in the same file as windows-1252 successfully (mixed- encoding), and treating new bytes as UTF-8 surfaced unterminated- string errors. Stay on ASCII in newly-added blocks to avoid drift.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughBoth ChangesScheduled Task Re-registration Without AutoStart
Possibly Related PRs
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Repro: user has `cua-driver-serve` registered (from a previous `install.ps1 -AutoStart`). They upgrade — `install-local.ps1` (no `-AutoStart`) drops a fresh binary, retargets the `current` junction. PATH now resolves to the fresh binary. But the scheduled task's `` is a hard-coded absolute path to the OLD release-install dir — that binary is still on disk and still has the pre-#1654 unwrapped task-action shape.
Result: `cua-driver autostart kick` runs the OLD binary, which displays a visible console window at logon. Even though everything ELSE on the system is now the new binary.
Discovered while debugging "why does autostart kick still show the console" with a user on Windows. Confirmed by checking `strings <task's-command-path> | grep 'WindowStyle Hidden'` → 0 hits (pre-fix binary); the fresh source build had 2 hits.
Fix
Both `install.ps1` and `install-local.ps1` now sniff for an existing `cua-driver-serve` task post-install:
```powershell
if (-not $AutoStart) {
schtasks.exe /Query /TN "cua-driver-serve" 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) {
# Re-register against the freshly-installed binary
Register-CuaDriverAutostart -InstalledBinary $installedBinary
}
}
```
Idempotent. Covers the upgrade path explicitly. If no task is registered, behaviour is unchanged — initial autostart opt-in still requires `-AutoStart` (or `cua-driver autostart enable`).
End-to-end
```
$ schtasks /Query /TN cua-driver-serve /XML | findstr powershell.exe
(empty — old binary's REGISTER_PS used direct cua-driver.exe action)
$ .\install-local.ps1
==> registering Scheduled Task 'cua-driver-serve' (because pre-existing task detected)
Re-registered. Task action now uses this build's hidden-console wrapper.
$ schtasks /Query /TN cua-driver-serve /XML | findstr powershell.exe
powershell.exe
-NoProfile -WindowStyle Hidden -NonInteractive ...
$ cua-driver autostart kick
no visible window
```
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit