diff --git a/packages/app/config.ts b/packages/app/config.ts index 5972de73..245ead34 100644 --- a/packages/app/config.ts +++ b/packages/app/config.ts @@ -58,7 +58,6 @@ export const config = new Store({ "notifications.times": [], "updates.autoCheck": true, "updates.showNotifications": true, - "updates.notificationDelay": "next-day", "blocker.enabled": true, "blocker.ads": true, "blocker.tracking": true, @@ -304,5 +303,12 @@ export const config = new Store({ store.delete("resetConfig"); } }, + ">3.45.0": (store) => { + // @ts-expect-error: `updates.notificationDelay` has been removed + if (store.has("updates.notificationDelay")) { + // @ts-expect-error + store.delete("updates.notificationDelay"); + } + }, }, }); diff --git a/packages/app/updater.ts b/packages/app/updater.ts index 805fead4..4b8549c0 100644 --- a/packages/app/updater.ts +++ b/packages/app/updater.ts @@ -1,6 +1,4 @@ import { is } from "@electron-toolkit/utils"; -import { ms } from "@meru/shared/ms"; -import type { UpdateDownloadedEvent } from "electron-updater"; import { autoUpdater } from "electron-updater"; import { config } from "@/config"; import { ipc } from "./ipc"; @@ -8,44 +6,17 @@ import { log } from "./lib/log"; import { main } from "./main"; import { appState } from "./state"; -const URGENT_MARKERS = ["", "[urgent]"]; - -const NOTIFICATION_DELAY_MS = { - immediate: 0, - "few-hours": ms("4h"), - "next-day": ms("1d"), -} as const; - -type ReleaseNotes = UpdateDownloadedEvent["releaseNotes"]; - -function flattenReleaseNotes(releaseNotes: ReleaseNotes) { - if (!releaseNotes) { - return ""; - } - - if (typeof releaseNotes === "string") { - return releaseNotes; - } - - return releaseNotes.map((entry) => entry.note ?? "").join("\n"); -} - -function isUrgentRelease(releaseNotes: ReleaseNotes) { - const text = flattenReleaseNotes(releaseNotes).toLowerCase(); - - return URGENT_MARKERS.some((marker) => text.includes(marker)); -} - class AppUpdater { - private pendingVersion: string | null = null; - private notifyTimer: NodeJS.Timeout | null = null; - init() { autoUpdater.logger = log; if (config.get("updates.showNotifications")) { autoUpdater.on("update-downloaded", (updateInfo) => { - this.handleUpdateDownloaded(updateInfo); + ipc.renderer.send( + main.window.webContents, + "appUpdater.updateAvailable", + `v${updateInfo.version}`, + ); }); } @@ -78,45 +49,6 @@ class AppUpdater { autoUpdater.quitAndInstall(); } - - private handleUpdateDownloaded(updateInfo: UpdateDownloadedEvent) { - const delayMs = NOTIFICATION_DELAY_MS[config.get("updates.notificationDelay")]; - - if (delayMs === 0 || isUrgentRelease(updateInfo.releaseNotes)) { - this.clearPendingNotification(); - this.notifyRenderer(updateInfo.version); - - return; - } - - this.clearPendingNotification(); - - this.pendingVersion = updateInfo.version; - - this.notifyTimer = setTimeout(() => { - const version = this.pendingVersion; - - this.notifyTimer = null; - this.pendingVersion = null; - - if (version) { - this.notifyRenderer(version); - } - }, delayMs); - } - - private clearPendingNotification() { - if (this.notifyTimer) { - clearTimeout(this.notifyTimer); - this.notifyTimer = null; - } - - this.pendingVersion = null; - } - - private notifyRenderer(version: string) { - ipc.renderer.send(main.window.webContents, "appUpdater.updateAvailable", `v${version}`); - } } export const appUpdater = new AppUpdater(); diff --git a/packages/renderer-main/routes/settings/updates.tsx b/packages/renderer-main/routes/settings/updates.tsx index 647aaf71..f5341552 100644 --- a/packages/renderer-main/routes/settings/updates.tsx +++ b/packages/renderer-main/routes/settings/updates.tsx @@ -1,35 +1,8 @@ -import { - Field, - FieldContent, - FieldDescription, - FieldGroup, - FieldLabel, -} from "@meru/ui/components/field"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@meru/ui/components/select"; -import { useConfig, useConfigMutation } from "@meru/shared/renderer/react-query"; +import { FieldGroup } from "@meru/ui/components/field"; import { ConfigSwitchField } from "@/components/config-switch-field"; import { Settings, SettingsContent, SettingsHeader, SettingsTitle } from "@/components/settings"; -const notificationDelayItems = [ - { value: "next-day", label: "Next day (recommended)" }, - { value: "few-hours", label: "After a few hours" }, - { value: "immediate", label: "Immediately" }, -]; - export function UpdatesSettings() { - const { config } = useConfig(); - const configMutation = useConfigMutation(); - - if (!config) { - return; - } - return ( @@ -48,37 +21,6 @@ export function UpdatesSettings() { description="Receive notifications when updates are available." configKey="updates.showNotifications" /> - - - Notification Delay - - Batch rapid back-to-back releases into a single prompt. Urgent updates always notify - immediately. - - - - diff --git a/packages/shared/types.ts b/packages/shared/types.ts index d7a80f5d..c760c35f 100644 --- a/packages/shared/types.ts +++ b/packages/shared/types.ts @@ -123,7 +123,6 @@ export type Config = { "notifications.times": NotificationTime[]; "updates.autoCheck": boolean; "updates.showNotifications": boolean; - "updates.notificationDelay": "immediate" | "few-hours" | "next-day"; "blocker.enabled": boolean; "blocker.ads": boolean; "blocker.tracking": boolean;