Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(app): show a manual update check when update balloons are off (#2169)

Emanyzwww064885635910
diff --git a/src/features/app/__tests__/updates.test.ts b/src/features/app/__tests__/updates.test.ts
index 28326a0e8..d6dce3e00 100644
--- a/src/features/app/__tests__/updates.test.ts
+++ b/src/features/app/__tests__/updates.test.ts
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-import type { Settings, UpdateCheck, UpdateProgress } from "@/bindings";
+import type { Settings, UpdateCheck, UpdateInfo, UpdateProgress } from "@/bindings";
import type { NotificationService } from "@/workbench/contributions";
vi.mock("@tauri-apps/api/core", () => ({
@@ -25,6 +25,7 @@ const appInstallUpdate = vi.fn((_source: string, _request: number, ch: Channel)
return install.promise;
});
const appCheckUpdate = vi.fn(() => check.promise);
+const appStartupUpdateCheck = vi.fn(async (): Promise<UpdateInfo | null> => null);
const appRestart = vi.fn(async () => null);
const cancelRequest = vi.fn(async () => null);
const appBuildInfo = vi.fn(async () => ({ version: "0.1.21" }));
@@ -39,6 +40,7 @@ vi.mock("@/platform/ipc", async (orig) => {
...actual.commands,
appInstallUpdate,
appCheckUpdate,
+ appStartupUpdateCheck,
appRestart,
cancelRequest,
appBuildInfo,
@@ -49,6 +51,7 @@ vi.mock("@/platform/ipc", async (orig) => {
const {
checkForUpdates,
+ checkForUpdatesOnStartup,
installUpdate,
notifyUpdate,
progressText,
@@ -85,7 +88,12 @@ afterEach(() => vi.clearAllMocks());
describe("Install and Restart", () => {
it("runs as a background task with download progress, then restarts", async () => {
const done = installUpdate("0.1.22");
- expect(notes.at(-1)).toMatchObject({ title: "Downloading OpenIDEA 0.1.22", key: UPDATE_KEY, sticky: true });
+ expect(notes.at(-1)).toMatchObject({
+ title: "Downloading OpenIDEA 0.1.22",
+ key: UPDATE_KEY,
+ sticky: true,
+ userInitiated: true,
+ });
expect(notes.at(-1)!.actions![0]!.label).toBe("Cancel");
expect(task(INSTALL_TASK_ID)).toMatchObject({ title: "Downloading OpenIDEA 0.1.22", fraction: null, done: false });
expect(task(INSTALL_TASK_ID)?.cancel).toBeTypeOf("function");
@@ -200,7 +208,7 @@ describe("Check for Updates", () => {
const done = checkForUpdates();
check.resolve(result);
await done;
- expect(notes.at(-1)?.title).toBe(title);
+ expect(notes.at(-1)).toMatchObject({ title, userInitiated: true });
expect(task(CHECK_TASK_ID)?.done).toBe(true);
});
@@ -212,6 +220,58 @@ describe("Check for Updates", () => {
expect(notes.at(-1)).toMatchObject({ title: "OpenIDEA 0.1.21 is up to date", key: UPDATE_KEY });
});
+ it("marks the manual check's progress as the user's own request", async () => {
+ const done = checkForUpdates();
+ expect(notes[0]).toMatchObject({ level: "info", title: "Checking for updates…", userInitiated: true });
+ check.resolve(ok({ enabled: true, update: null }));
+ await done;
+ });
+
+ it("leaves the startup check to the IDE Updates notification settings", async () => {
+ appStartupUpdateCheck.mockResolvedValueOnce({
+ version: "0.1.22",
+ currentVersion: "0.1.21",
+ notes: null,
+ date: null,
+ });
+ await checkForUpdatesOnStartup();
+ expect(notes.at(-1)).toMatchObject({ title: "OpenIDEA 0.1.22 is available" });
+ expect(notes.at(-1)?.userInitiated).toBe(false);
+ });
+
+ it('still pops up when IDE Updates is set to "No popup" (no other surface on the welcome screen)', async () => {
+ const { notificationServiceImpl, useNotifications } = await import("@/workbench/notificationStore");
+ // What Settings › Notifications › IDE Updates stores for "No popup" (or "Don't Show Again").
+ useProject.setState({
+ settings: {
+ notifications: { balloons: true, groups: { updates: { display: "none", log: true } } },
+ } as unknown as Settings,
+ });
+ useNotifications.setState({ items: [] });
+ provideNotificationService(notificationServiceImpl);
+ try {
+ const done = checkForUpdates();
+ try {
+ expect(useNotifications.getState().items[0]).toMatchObject({
+ key: UPDATE_KEY,
+ balloon: true,
+ title: "Checking for updates…",
+ });
+ } finally {
+ // Settle the check even when the assertion above fails, so later tests don't join it.
+ check.resolve(ok({ enabled: true, update: null }));
+ await done;
+ }
+ expect(useNotifications.getState().items[0]).toMatchObject({
+ key: UPDATE_KEY,
+ balloon: true,
+ title: "OpenIDEA 0.1.21 is up to date",
+ });
+ } finally {
+ useNotifications.setState({ items: [] });
+ }
+ });
+
it("leaves the check to the status bar in a project window", async () => {
useProject.setState({ project: { root: "/p", name: "p", trusted: true, isGit: false, settings: {} } as never });
const done = checkForUpdates();
diff --git a/src/features/app/updates.tsx b/src/features/app/updates.tsx
index 4d10d291d..1e25c881d 100644
--- a/src/features/app/updates.tsx
+++ b/src/features/app/updates.tsx
@@ -88,6 +88,7 @@ async function runCheck() {
title,
body: <UpdateBalloonBody task={CHECK_TASK_ID} />,
key: UPDATE_KEY,
+ userInitiated: true,
});
try {
const r = await Promise.race([call(commands.appCheckUpdate(updateSource())), abandoned]);
@@ -98,6 +99,7 @@ async function runCheck() {
title: t("app.update.disabled"),
body: t("app.update.disabledBody"),
key: UPDATE_KEY,
+ userInitiated: true,
});
} else if (!r.update) {
const info = await commands.appBuildInfo();
@@ -105,12 +107,19 @@ async function runCheck() {
level: "info",
title: t("app.update.none", { version: info.version }),
key: UPDATE_KEY,
+ userInitiated: true,
});
} else if (!installing) {
- notifyUpdate(r.update);
+ notifyUpdate(r.update, true);
}
} catch (e) {
- notifications().notify({ level: "error", title: t("app.update.failed"), body: errorText(e), key: UPDATE_KEY });
+ notifications().notify({
+ level: "error",
+ title: t("app.update.failed"),
+ body: errorText(e),
+ key: UPDATE_KEY,
+ userInitiated: true,
+ });
} finally {
upsertTask({ id: CHECK_TASK_ID, title, message: null, fraction: 1, done: true });
}
@@ -123,7 +132,8 @@ export async function checkForUpdatesOnStartup(): Promise<void> {
if (update) notifyUpdate(update);
}
-export function notifyUpdate(update: UpdateInfo) {
+/** `userInitiated`: the update came from a manual check, so it pops up regardless of the balloon settings. */
+export function notifyUpdate(update: UpdateInfo, userInitiated = false) {
notifications().notify({
level: "info",
title: t("app.update.available", { version: update.version }),
@@ -131,6 +141,7 @@ export function notifyUpdate(update: UpdateInfo) {
sticky: true,
key: UPDATE_KEY,
actions: [{ label: t("app.update.install"), run: () => void installUpdate(update.version) }],
+ userInitiated,
});
}
@@ -171,6 +182,7 @@ async function runInstall(version: string, source: UpdateSource) {
sticky: true,
key: UPDATE_KEY,
actions,
+ userInitiated: true,
});
let installingShown = false;
channel.onmessage = (p) => {
@@ -202,6 +214,7 @@ async function runInstall(version: string, source: UpdateSource) {
title: t("app.update.cancelled"),
key: UPDATE_KEY,
actions: [otherSourceAction(version, source)],
+ userInitiated: true,
});
} else {
notifications().notify({
@@ -213,6 +226,7 @@ async function runInstall(version: string, source: UpdateSource) {
{ label: t("app.update.retry"), run: () => void installUpdate(version, source) },
otherSourceAction(version, source),
],
+ userInitiated: true,
});
}
return;
@@ -228,6 +242,7 @@ async function runInstall(version: string, source: UpdateSource) {
sticky: true,
key: UPDATE_KEY,
actions: [{ label: t("app.update.restart"), run: restart }],
+ userInitiated: true,
});
restart();
}
diff --git a/src/workbench/Workbench.test.tsx b/src/workbench/Workbench.test.tsx
index 2ebf6fcdf..f7bd710e9 100644
--- a/src/workbench/Workbench.test.tsx
+++ b/src/workbench/Workbench.test.tsx
@@ -223,6 +223,25 @@ describe("notifications", () => {
expect(useNotifications.getState().items.every((n) => n.read && !n.balloon)).toBe(true);
dispose();
});
+
+ it("pops up the answer to a command the user ran even when balloons are off for its group", async () => {
+ const { useProject } = await import("@/platform/project");
+ useProject.setState({
+ settings: { notifications: { balloons: false, groups: { updates: { display: "none", log: true } } } } as never,
+ });
+ try {
+ act(() => {
+ notify({ level: "info", title: "Checking for updates…", key: "app.update", userInitiated: true });
+ notify({ level: "info", title: "Update available", key: "app.update.background" });
+ });
+ const balloon = (title: string) => useNotifications.getState().items.find((n) => n.title === title)?.balloon;
+ expect(balloon("Checking for updates…")).toBe(true);
+ // What the IDE raises on its own still follows the settings.
+ expect(balloon("Update available")).toBe(false);
+ } finally {
+ useProject.setState({ settings: null });
+ }
+ });
});
describe("tool window stripe", () => {
diff --git a/src/workbench/contributions.ts b/src/workbench/contributions.ts
index cefe7b722..bf0668dfb 100644
--- a/src/workbench/contributions.ts
+++ b/src/workbench/contributions.ts
@@ -633,6 +633,13 @@ export interface NotificationService {
* `vcs`, `run`, `tools`, `plugins`, `search`, `updates`.
*/
group?: string;
+ /**
+ * The notification answers a command the user just ran (Check for Updates
+ * and the install it offers). It pops up even when balloon notifications
+ * are turned off or its group's popup type is "No popup": those settings
+ * silence what the IDE reports on its own, not the answer to a request.
+ */
+ userInitiated?: boolean;
}): void;
/** Hides the balloon of the notification with `key` (it stays in the log), e.g. once its cause is gone. */
expire?(key: string): void;
diff --git a/src/workbench/notificationStore.ts b/src/workbench/notificationStore.ts
index b8a1017b0..bb51162e3 100644
--- a/src/workbench/notificationStore.ts
+++ b/src/workbench/notificationStore.ts
@@ -129,7 +129,8 @@ export function notify(n: Parameters<NotificationService["notify"]>[0]): number
const id = ++seq;
const group = groupOf(n);
const prefs = notificationPrefs(group);
- const balloon = prefs.balloons && prefs.display !== "none";
+ // The answer to a command the user ran is not a notification they opted out of.
+ const balloon = n.userInitiated === true || (prefs.balloons && prefs.display !== "none");
const sticky = prefs.display === "sticky" || (n.sticky ?? BALLOON_TIMEOUT[n.level] === null);
// Neither shown nor listed: dropped, as IDEA's "No popup" + no log.
if (!balloon && !prefs.log) return id;