AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
feat(desktop): prepare updates in background
tianma-if82c2252323ac
diff --git a/apps/desktop/src/main/desktop-update-flow.test.mjs b/apps/desktop/src/main/desktop-update-flow.test.mjsnew file mode 100644index 00000000..c7fe412f--- /dev/null+++ b/apps/desktop/src/main/desktop-update-flow.test.mjs@@ -0,0 +1,20 @@+import { readFileSync } from "node:fs";+import { describe, expect, test } from "bun:test";++const mainSource = readFileSync(new URL("./index.mjs", import.meta.url), "utf8");+const noticeSource = readFileSync(new URL("../../../web/src/components/DesktopUpdateNotice.tsx", import.meta.url), "utf8");++describe("desktop update flow", () => {+ test("downloads updates in the background and relaunches after installation", () => {+ expect(mainSource).toContain("autoUpdater.autoDownload = true");+ expect(mainSource).toContain("autoUpdater.autoRunAppAfterInstall = true");+ expect(mainSource).toContain("isQuitting = true;\n autoUpdater.quitAndInstall(false, true)");+ expect(mainSource).toContain("result?.downloadPromise?.catch");+ });++ test("only offers the restart action after the update is downloaded", () => {+ expect(noticeSource).toContain('statusQuery.data?.state === "downloaded"');+ expect(noticeSource).toContain('t("systemInfo.desktopUpdateRestart")');+ expect(noticeSource).not.toContain("downloadUpdate()");+ });+});diff --git a/apps/desktop/src/main/index.mjs b/apps/desktop/src/main/index.mjsindex 37983b12..26aa92fc 100644--- a/apps/desktop/src/main/index.mjs+++ b/apps/desktop/src/main/index.mjs@@ -426,8 +426,7 @@ const createTray = () => {{ label: "Show EdgeEver", click: () => showWindow(mainWindow) },{ label: "Sync now", click: () => sendDesktopCommand("sync-now") },{ label: "Backup now", click: () => sendDesktopCommand("backup-now") },- ...(updateState === "available" ? [{ label: "Download update", click: () => void autoUpdater.downloadUpdate() }] : []),- ...(updateState === "downloaded" ? [{ label: "Restart to update", click: () => autoUpdater.quitAndInstall() }] : []),+ ...(updateState === "downloaded" ? [{ label: "Restart to update", click: () => installDownloadedUpdate() }] : []),{ type: "separator" },{ label: "Quit EdgeEver", click: () => { isQuitting = true; app.quit(); } },]));@@ -500,15 +499,27 @@ const refreshTrayMenu = () => {createTray();};+const installDownloadedUpdate = () => {+ if (updateState !== "downloaded") return { started: false };+ // The normal window close handler hides the app. Mark this as a real quit+ // before electron-updater closes windows so installation can proceed.+ isQuitting = true;+ autoUpdater.quitAndInstall(false, true);+ return { started: true };+};+const configureAutoUpdater = () => {if (!app.isPackaged || process.env.EDGE_EVER_DISABLE_AUTO_UPDATE === "1") return;- autoUpdater.autoDownload = false;+ autoUpdater.autoDownload = true;autoUpdater.autoInstallOnAppQuit = true;+ autoUpdater.autoRunAppAfterInstall = true;autoUpdater.on("update-available", () => { updateState = "available"; refreshTrayMenu(); void writeDiagnostic("update.available"); });autoUpdater.on("download-progress", (progress) => { void writeDiagnostic("update.download-progress", { percent: progress.percent }); });autoUpdater.on("update-downloaded", () => { updateState = "downloaded"; refreshTrayMenu(); void writeDiagnostic("update.downloaded"); });- autoUpdater.on("error", (error) => { void writeDiagnostic("update.error", { message: error.message }); });- void autoUpdater.checkForUpdates().catch((error) => writeDiagnostic("update.check-failed", { message: error.message }));+ autoUpdater.on("error", (error) => { isQuitting = false; void writeDiagnostic("update.error", { message: error.message }); });+ void autoUpdater.checkForUpdates()+ .then((result) => result?.downloadPromise?.catch((error) => writeDiagnostic("update.download-failed", { message: error.message })))+ .catch((error) => writeDiagnostic("update.check-failed", { message: error.message }));};const startSidecar = async (accountId = null) => {@@ -897,7 +908,7 @@ app.whenReady().then(async () => {});ipcMain.handle("desktop:update-status", () => ({ state: updateState }));ipcMain.handle("desktop:download-update", () => autoUpdater.downloadUpdate());- ipcMain.handle("desktop:install-update", () => autoUpdater.quitAndInstall());+ ipcMain.handle("desktop:install-update", () => installDownloadedUpdate());ipcMain.handle("desktop:stage-resource", async (_event, input) => {const { memoId, name, type, bytes } = normalizeStagedResourceInput(input);const id = `stage_${Date.now()}_${Math.random().toString(36).slice(2)}`;diff --git a/apps/web/src/components/DesktopUpdateNotice.tsx b/apps/web/src/components/DesktopUpdateNotice.tsxindex 000428eb..528e577f 100644--- a/apps/web/src/components/DesktopUpdateNotice.tsx+++ b/apps/web/src/components/DesktopUpdateNotice.tsx@@ -1,83 +1,53 @@-import { useState } from "react";-import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";-import { Download, LoaderCircle, RotateCcw, X } from "lucide-react";+import { useMutation, useQuery } from "@tanstack/react-query";+import { LoaderCircle, RotateCcw } from "lucide-react";import { useTranslation } from "react-i18next";import { Button } from "@/components/ui/button";--type DesktopUpdateState = "idle" | "available" | "downloaded";--const UPDATE_STATUS_QUERY_KEY = ["desktop-update-status"] as const;+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";export const DesktopUpdateNotice = () => {const { t } = useTranslation();- const queryClient = useQueryClient();const bridge = window.edgeeverDesktop;- const [dismissedState, setDismissedState] = useState<DesktopUpdateState | null>(null);const statusQuery = useQuery({- queryKey: UPDATE_STATUS_QUERY_KEY,+ queryKey: ["desktop-update-status"],queryFn: () => bridge!.updateStatus(),enabled: bridge?.isAvailable === true,- refetchInterval: 5_000,+ refetchInterval: (query) => query.state.data?.state === "downloaded" ? false : 5_000,retry: 1,});- const downloadMutation = useMutation({- mutationFn: () => bridge!.downloadUpdate(),- onSuccess: async () => {- await queryClient.invalidateQueries({ queryKey: UPDATE_STATUS_QUERY_KEY });- },- });const installMutation = useMutation({mutationFn: () => bridge!.installUpdate(),});- const updateState = statusQuery.data?.state ?? "idle";- const visible = bridge?.isAvailable === true && updateState !== "idle" && dismissedState !== updateState;- if (!visible) return null;+ const downloaded = bridge?.isAvailable === true && statusQuery.data?.state === "downloaded";+ if (!downloaded) return null;- const downloaded = updateState === "downloaded";- const downloading = downloadMutation.isPending;- const failed = downloadMutation.isError || installMutation.isError;+ const label = installMutation.isError+ ? t("systemInfo.desktopUpdateFailed")+ : t("systemInfo.desktopUpdateRestart");return (- <div- className="fixed bottom-5 right-5 z-[90] w-[min(22rem,calc(100vw-2rem))] animate-in slide-in-from-bottom-3 fade-in rounded-lg border border-emerald-200 bg-white/95 p-3 text-slate-900 shadow-[0_18px_48px_rgba(15,23,42,0.18)] backdrop-blur duration-300"- role="status"- aria-live="polite"- >- <div className="flex items-start gap-3">- <div className="mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-emerald-50 text-emerald-700" aria-hidden="true">- {downloading ? <LoaderCircle className="h-4 w-4 animate-spin" /> : downloaded ? <RotateCcw className="h-4 w-4" /> : <Download className="h-4 w-4" />}- </div>- <div className="min-w-0 flex-1">- <div className="text-sm font-semibold leading-5">- {t(downloaded ? "systemInfo.desktopUpdateReadyTitle" : "systemInfo.desktopUpdateAvailableTitle")}- </div>- <div className="mt-0.5 text-xs leading-5 text-slate-500">- {t(downloaded ? "systemInfo.desktopUpdateReadyDescription" : "systemInfo.desktopUpdateAvailableDescription")}- </div>- {failed ? <div className="mt-1 text-xs font-medium text-rose-700" role="alert">{t("systemInfo.desktopUpdateFailed")}</div> : null}- <Button- className="mt-2"- size="sm"- variant="solid"- disabled={downloading || installMutation.isPending}- onClick={() => downloaded ? installMutation.mutate() : downloadMutation.mutate()}- >- {downloading- ? t("systemInfo.desktopUpdateDownloading")- : t(downloaded ? "systemInfo.desktopUpdateRestart" : "systemInfo.desktopUpdateDownload")}- </Button>- </div>- <button- className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-slate-400 transition hover:bg-slate-100 hover:text-slate-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/70"- type="button"- aria-label={t("common.close")}- onClick={() => setDismissedState(updateState)}- >- <X className="h-4 w-4" />- </button>- </div>+ <div className="fixed right-5 top-5 z-[90] animate-in slide-in-from-top-3 fade-in duration-300" role="status" aria-live="polite">+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ className="relative h-10 w-10 rounded-full shadow-[0_12px_32px_rgba(15,23,42,0.2)]"+ size="icon"+ variant="solid"+ aria-label={label}+ disabled={installMutation.isPending}+ onClick={() => installMutation.mutate()}+ >+ {installMutation.isPending+ ? <LoaderCircle className="h-4 w-4 animate-spin" />+ : <RotateCcw className="h-4 w-4" />}+ <span className="absolute right-0 top-0 h-2.5 w-2.5 rounded-full border-2 border-white bg-amber-400" aria-hidden="true" />+ </Button>+ </TooltipTrigger>+ <TooltipContent side="left">{label}</TooltipContent>+ </Tooltip>+ </TooltipProvider></div>);};diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex 6194a5dc..beb19209 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -608,10 +608,6 @@ export const enUS = {releaseNotesUnavailable: "This build does not include an update summary. You can view the full Release notes.",clientUpdatesNote: "Download desktop updates from <releases>Releases</releases>, or update mobile apps through the corresponding app store.",viewReleaseNotes: "Full notes",- desktopUpdateAvailableTitle: "Client update available",- desktopUpdateAvailableDescription: "A new version is ready to download and install.",- desktopUpdateReadyTitle: "Client update ready",- desktopUpdateReadyDescription: "Restart EdgeEver to finish updating.",desktopUpdateDownloading: "Downloading update…",desktopUpdateReady: "Update downloaded",desktopUpdateDownload: "Download update",diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex 4d3fc1c6..7650428b 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -608,10 +608,6 @@ export const zhCN = {releaseNotesUnavailable: "本次构建未包含更新摘要,可查看完整 Release 说明。",clientUpdatesNote: "桌面端可前往 <releases>Releases</releases> 下载更新,移动端请通过对应的应用商店更新。",viewReleaseNotes: "完整说明",- desktopUpdateAvailableTitle: "发现客户端新版本",- desktopUpdateAvailableDescription: "新版本已可下载并安装。",- desktopUpdateReadyTitle: "客户端更新已就绪",- desktopUpdateReadyDescription: "重启 EdgeEver 以完成更新。",desktopUpdateDownloading: "正在下载更新…",desktopUpdateReady: "更新已下载完成",desktopUpdateDownload: "下载更新",