Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: keep the Windows app and its shortcuts through updates

ogsamrat3fcb6e427423
diff --git a/apps/desktop/build/installer.nsh b/apps/desktop/build/installer.nsh
index 89cb0d3b..fb8f0c91 100644
--- a/apps/desktop/build/installer.nsh
+++ b/apps/desktop/build/installer.nsh
@@ -1,11 +1,43 @@
+; The app writes its own Start menu shortcut and records the path in
+; windows-brand-shortcut.txt. An update runs the old uninstaller with
+; --updated and then keeps shortcuts as they are, so removing that shortcut
+; during an update left the app without a Start menu entry until it was
+; opened from somewhere else.
!macro customUnInstall
+ ${ifNot} ${isUpdated}
+ StrCpy $1 ""
+ FileOpen $0 "$APPDATA\ai.omnirush.desktop\windows-brand-shortcut.txt" r
+ IfErrors +3
+ FileRead $0 $1
+ FileClose $0
+ ${If} $1 != ""
+ Delete "$1"
+ ${EndIf}
+ Delete "$APPDATA\ai.omnirush.desktop\windows-brand-shortcut.txt"
+ ${endIf}
+!macroend
+
+; Updates from versions whose uninstaller removed the Start menu shortcut:
+; put it back unless the app's own shortcut is still in place.
+!macro customInstall
+ Push $0
+ Push $1
StrCpy $1 ""
+ ClearErrors
FileOpen $0 "$APPDATA\ai.omnirush.desktop\windows-brand-shortcut.txt" r
- IfErrors +3
+ ${ifNot} ${Errors}
FileRead $0 $1
FileClose $0
- ${If} $1 != ""
- Delete "$1"
- ${EndIf}
- Delete "$APPDATA\ai.omnirush.desktop\windows-brand-shortcut.txt"
+ ${endIf}
+ ClearErrors
+ ${if} $1 == ""
+ ${orIfNot} ${FileExists} "$1"
+ ${ifNot} ${FileExists} "$newStartMenuLink"
+ CreateShortCut "$newStartMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
+ ClearErrors
+ WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
+ ${endIf}
+ ${endIf}
+ Pop $1
+ Pop $0
!macroend
diff --git a/apps/desktop/electron-builder.base.yml b/apps/desktop/electron-builder.base.yml
index 3baf8e29..399d6e7a 100644
--- a/apps/desktop/electron-builder.base.yml
+++ b/apps/desktop/electron-builder.base.yml
@@ -148,3 +148,6 @@ win:
- nsis
nsis:
include: build/installer.nsh
+ # A reinstall puts back a desktop shortcut that was deleted (for example
+ # after Windows offered to delete it while an update was replacing the app).
+ createDesktopShortcut: always
diff --git a/apps/desktop/electron/electron-builder-config.test.mjs b/apps/desktop/electron/electron-builder-config.test.mjs
index f23ef0a7..43c3ca46 100644
--- a/apps/desktop/electron/electron-builder-config.test.mjs
+++ b/apps/desktop/electron/electron-builder-config.test.mjs
@@ -12,6 +12,17 @@ async function readConfig(name) {
}
describe("Electron distribution configs", () => {
+ it("keeps Windows shortcuts across updates and puts back a deleted desktop shortcut on reinstall", async () => {
+ const config = await readConfig("electron-builder.base.yml");
+ assert.equal(config.nsis.include, "build/installer.nsh");
+ assert.equal(config.nsis.createDesktopShortcut, "always");
+ const script = await readFile(path.resolve(dirname, "..", "build", "installer.nsh"), "utf8");
+ const uninstall = script.slice(script.indexOf("!macro customUnInstall"), script.indexOf("!macroend"));
+ assert.match(uninstall, /\$\{ifNot\} \$\{isUpdated\}[\s\S]*Delete "\$1"[\s\S]*\$\{endIf\}/, "an update must not delete the Start menu shortcut");
+ const install = script.slice(script.indexOf("!macro customInstall"));
+ assert.match(install, /\$\{ifNot\} \$\{FileExists\} "\$newStartMenuLink"[\s\S]*CreateShortCut "\$newStartMenuLink"/);
+ });
+
it("uses a stable Linux desktop identity and ships integration icons", async () => {
const packageMetadata = JSON.parse(
await readFile(path.resolve(dirname, "..", "package.json"), "utf8"),
diff --git a/apps/desktop/electron/main.mjs b/apps/desktop/electron/main.mjs
index 37969b98..4166cff3 100644
--- a/apps/desktop/electron/main.mjs
+++ b/apps/desktop/electron/main.mjs
@@ -1583,6 +1583,8 @@ function startReportScrubRoots() {
/** Set by restartApp(): the quit below ends in a restart. */
let restartAfterQuit = false;
+// Windows is signing out or shutting down: a staged update waits for the next launch.
+let windowsSessionEnding = false;
/**
* Quit and open again (Fix and restart, Reset / Restore app data). The
@@ -3153,7 +3155,10 @@ async function createMainWindow() {
});
// Windows logout or shutdown never waits on the turn guard.
- mainWindow.on("session-end", () => turnGuard.allowQuit());
+ mainWindow.on("session-end", () => {
+ windowsSessionEnding = true;
+ turnGuard.allowQuit();
+ });
// A turn still running: ask before the window goes (turn-guard.mjs).
mainWindow.on("close", (event) => {
const win = mainWindow;
@@ -3439,7 +3444,7 @@ or use: pnpm dev:worktree`);
// Re-check the update feed while services stop, so a download staged
// before newer releases shipped is replaced by the newest one instead
// of installing on quit.
- const updateInstall = prepareInstallOnQuit({ relaunch: restartAfterQuit });
+ const updateInstall = prepareInstallOnQuit({ relaunch: restartAfterQuit, sessionEnding: windowsSessionEnding });
try {
await Promise.all([
disposeRuntimeBeforeQuit(),
diff --git a/apps/desktop/electron/updater.mjs b/apps/desktop/electron/updater.mjs
index 02060842..70ac2893 100644
--- a/apps/desktop/electron/updater.mjs
+++ b/apps/desktop/electron/updater.mjs
@@ -1448,12 +1448,15 @@ export function registerUpdaterIpc({
* With `relaunch` (the app restarts itself: Fix and restart, Reset app
* data) the install opens the new version when it is done, and the caller
* must not app.relaunch() as well: the old exe would start while the
- * installer replaces it. Never rejects.
+ * installer replaces it. With `sessionEnding` (Windows is signing out or
+ * shutting down) nothing installs: the installer would be killed after it
+ * moved the old version away, leaving no app at all. Never rejects.
*/
- async function prepareInstallOnQuit({ relaunch = false } = {}) {
+ async function prepareInstallOnQuit({ relaunch = false, sessionEnding = false } = {}) {
try {
const updater = autoUpdaterInstance;
if (!updater || !updateDownloaded || installTriggered) return null;
+ if (sessionEnding) return null;
const installMode = await resolveInstallMode();
if (installMode !== "in-place" && installMode !== "appimage" && installMode !== "mac-swap") return null;
// Quitting never asks for a password: an /Applications this user cannot
@@ -1478,13 +1481,17 @@ export function registerUpdaterIpc({
return () => {
installTriggered = true;
quitInstallInProgress = true;
- // Quit means quit: install silently without relaunching, unless the
- // app is restarting itself; then the installer opens the new version.
- updater.autoRunAppAfterInstall = relaunch;
+ // Elsewhere quit means quit: install silently without relaunching,
+ // unless the app is restarting itself. On Windows the installer shows
+ // its progress and opens the new version when done: a silent install
+ // left nothing on screen while the old version was already moved
+ // away, and a shortcut clicked then offered to delete itself.
+ const silent = platform !== "win32";
+ updater.autoRunAppAfterInstall = relaunch || !silent;
setTimeout(() => quitApp(), quitInstallFallbackMs);
try {
allowQuit();
- updater.quitAndInstall(true, relaunch);
+ updater.quitAndInstall(silent, relaunch || !silent);
} catch (error) {
console.warn("[updater] install on quit failed", error?.message ?? error);
if (relaunch) app.relaunch();
diff --git a/apps/desktop/electron/updater.test.mjs b/apps/desktop/electron/updater.test.mjs
index 5aeb1ec9..d878800a 100644
--- a/apps/desktop/electron/updater.test.mjs
+++ b/apps/desktop/electron/updater.test.mjs
@@ -1120,7 +1120,7 @@ describe("installing the newest published release", () => {
}
});
- it("on quit, re-checks the feed and silently installs the newest release", async () => {
+ it("on quit, re-checks the feed and installs the newest release with the Windows installer on screen", async () => {
const { tempDir, handlers, feed, downloaded, installs, updater, prepareInstallOnQuit } = await publishingFeedHarness({
quitInstallFallbackMs: 0,
});
@@ -1133,8 +1133,8 @@ describe("installing the newest published release", () => {
assert.equal(typeof installAndQuit, "function");
installAndQuit();
assert.deepEqual(downloaded, ["2.2.1", "2.2.3"]);
- assert.deepEqual(installs, [{ version: "2.2.3", isSilent: true, isForceRunAfter: false }]);
- assert.equal(updater.autoRunAppAfterInstall, false);
+ assert.deepEqual(installs, [{ version: "2.2.3", isSilent: false, isForceRunAfter: true }]);
+ assert.equal(updater.autoRunAppAfterInstall, true, "the new version opens instead of the app vanishing");
assert.equal(await prepareInstallOnQuit(), null, "an install already started");
} finally {
await rm(tempDir, { recursive: true, force: true });
@@ -1151,13 +1151,52 @@ describe("installing the newest published release", () => {
const installAndQuit = await prepareInstallOnQuit({ relaunch: true });
assert.equal(typeof installAndQuit, "function");
installAndQuit();
- assert.deepEqual(installs, [{ version: "2.2.1", isSilent: true, isForceRunAfter: true }]);
+ assert.deepEqual(installs, [{ version: "2.2.1", isSilent: false, isForceRunAfter: true }]);
assert.equal(updater.autoRunAppAfterInstall, true);
} finally {
await rm(tempDir, { recursive: true, force: true });
}
});
+ it("on macOS a quit still installs silently without reopening the app", async () => {
+ const { tempDir, handlers, installs, updater, prepareInstallOnQuit } = await publishingFeedHarness({
+ quitInstallFallbackMs: 0,
+ platform: "darwin",
+ isDeveloperIdSigned: async () => true,
+ getAppPath: () => "/Applications/OmniRush.ai.app/Contents/Resources/app.asar",
+ execPath: "/Applications/OmniRush.ai.app/Contents/MacOS/OmniRush.ai",
+ isReadOnlyVolume: async () => false,
+ isInApplicationsFolder: () => true,
+ });
+ try {
+ assert.equal((await handlers.get("omnirush:updater:check")(null, "stable")).installMode, "in-place");
+ await handlers.get("omnirush:updater:download")();
+ const installAndQuit = await prepareInstallOnQuit();
+ assert.equal(typeof installAndQuit, "function");
+ installAndQuit();
+ assert.deepEqual(installs, [{ version: "2.2.1", isSilent: true, isForceRunAfter: false }]);
+ assert.equal(updater.autoRunAppAfterInstall, false);
+ } finally {
+ await rm(tempDir, { recursive: true, force: true });
+ }
+ });
+
+ it("never installs while Windows signs out or shuts down", async () => {
+ const { tempDir, handlers, installs, prepareInstallOnQuit } = await publishingFeedHarness({
+ quitInstallFallbackMs: 0,
+ });
+ try {
+ await handlers.get("omnirush:updater:check")(null, "stable");
+ await handlers.get("omnirush:updater:download")();
+ assert.equal(await prepareInstallOnQuit({ sessionEnding: true }), null);
+ assert.deepEqual(installs, []);
+ const installAndQuit = await prepareInstallOnQuit();
+ assert.equal(typeof installAndQuit, "function", "the staged update still installs on the next quit");
+ } finally {
+ await rm(tempDir, { recursive: true, force: true });
+ }
+ });
+
it("on quit, skips the stale download when the newer release cannot be fetched", async () => {
const { tempDir, handlers, feed, installs, prepareInstallOnQuit } = await publishingFeedHarness();
try {