From f0c126223cedc0bcebbdfef847fe178b54c1e790 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 11 Jul 2025 20:00:56 +0800 Subject: [PATCH] feat: enhance update checking functionality and UI in the About section - Refactor `checkForUpdates` method to return a promise with update status and error handling. - Update `checkForAppUpdates` to provide detailed update information. - Improve the About section UI with new buttons and modals for legal information and update checks. - Add new translations for update-related messages in multiple languages. Signed-off-by: Innei --- .../layer/main/src/ipc/services/app.ts | 4 +- apps/desktop/layer/main/src/updater/index.ts | 47 ++- .../src/modules/settings/tabs/about.tsx | 320 ++++++++++++------ locales/settings/en.json | 19 +- locales/settings/ja.json | 19 +- locales/settings/zh-CN.json | 19 +- locales/settings/zh-TW.json | 19 +- 7 files changed, 320 insertions(+), 127 deletions(-) diff --git a/apps/desktop/layer/main/src/ipc/services/app.ts b/apps/desktop/layer/main/src/ipc/services/app.ts index edd57ebbe..7aea4c05b 100644 --- a/apps/desktop/layer/main/src/ipc/services/app.ts +++ b/apps/desktop/layer/main/src/ipc/services/app.ts @@ -44,8 +44,8 @@ export class AppService extends IpcService { } @IpcMethod() - checkForUpdates(): void { - checkForAppUpdates() + async checkForUpdates(): Promise<{ hasUpdate: boolean; error?: string }> { + return checkForAppUpdates() } @IpcMethod() diff --git a/apps/desktop/layer/main/src/updater/index.ts b/apps/desktop/layer/main/src/updater/index.ts index dac662978..6d122e527 100644 --- a/apps/desktop/layer/main/src/updater/index.ts +++ b/apps/desktop/layer/main/src/updater/index.ts @@ -32,35 +32,56 @@ export const quitAndInstall = () => { let downloading = false let checkingUpdate = false -const upgradeRenderIfNeeded = async () => { +const checkRenderUpdateAvailable = async () => { const [state, manifest] = await canUpdateRender() - if (state === CanUpdateRenderState.NO_NEEDED) { - return true - } if (state === CanUpdateRenderState.NEEDED && manifest) { - await hotUpdateRender(manifest) return true } return false } -export const checkForAppUpdates = async () => { + +const upgradeRenderIfNeeded = async () => { + const [state, manifest] = await canUpdateRender() + if (state === CanUpdateRenderState.NO_NEEDED) { + return { upgraded: false } + } + if (state === CanUpdateRenderState.NEEDED && manifest) { + await hotUpdateRender(manifest) + return { upgraded: true } + } + return { upgraded: false } +} +export const checkForAppUpdates = async (): Promise<{ hasUpdate: boolean; error?: string }> => { if (disabled || checkingUpdate) { - return + return { hasUpdate: false } } checkingUpdate = true try { + let hasUpdate = false + if (appUpdaterConfig.enableRenderHotUpdate) { - const isRenderUpgraded = await upgradeRenderIfNeeded() - if (isRenderUpgraded) { - return + const hasRenderUpdate = await checkRenderUpdateAvailable() + if (hasRenderUpdate) { + hasUpdate = true + + // Auto upgrade renderer + upgradeRenderIfNeeded() } } + + // Check for core app updates if (appUpdaterConfig.enableCoreUpdate) { - return autoUpdater.checkForUpdates() + const result = await autoUpdater.checkForUpdates() + if (result !== null && result.updateInfo !== null) { + hasUpdate = true + } } + + return { hasUpdate } } catch (e) { logger.error("Error checking for updates", e) + return { hasUpdate: false, error: e instanceof Error ? e.message : "Unknown error" } } finally { checkingUpdate = false } @@ -119,8 +140,8 @@ export const registerUpdater = async () => { // Determine whether the app should be updated in full or only the renderer layer based on the version number. // https://www.notion.so/rss3/Follow-Hotfix-Electron-Renderer-layer-RFC-fe2444b9ac194c2cb38f9fa0bb1ef3c1?pvs=4#12e35ea049b480f1b268f1e605d86a62 if (appUpdaterConfig.enableRenderHotUpdate) { - const isRenderUpgraded = await upgradeRenderIfNeeded() - if (isRenderUpgraded) { + const renderResult = await upgradeRenderIfNeeded() + if (renderResult.upgraded) { return } } diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/about.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/about.tsx index 92fa8ce04..186d14a0c 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/about.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/about.tsx @@ -1,148 +1,260 @@ +import { Folo } from "@follow/components/icons/folo.js" import { Logo } from "@follow/components/icons/logo.jsx" -import { Button } from "@follow/components/ui/button/index.js" -import { styledButtonVariant } from "@follow/components/ui/button/variants.js" -import { Divider } from "@follow/components/ui/divider/index.js" +import { Divider } from "@follow/components/ui/divider/Divider.js" import { SocialMediaLinks } from "@follow/constants" +import { legalHtml } from "@follow/legal" import { IN_ELECTRON, MODE, ModeEnum } from "@follow/shared/constants" +import { stopPropagation } from "@follow/utils/dom" import { getCurrentEnvironment } from "@follow/utils/environment" +import { cn } from "@follow/utils/utils" import PKG, { repository } from "@pkg" import { useQuery } from "@tanstack/react-query" +import { m } from "motion/react" +import { useState } from "react" import { Trans, useTranslation } from "react-i18next" +import { toast } from "sonner" -import { CopyButton } from "~/components/ui/button/CopyButton" +import { useModalStack } from "~/components/ui/modal/stacked/hooks" import { ipcServices } from "~/lib/client" import { getNewIssueUrl } from "~/lib/issues" export const SettingAbout = () => { const { t } = useTranslation("settings") + const [isCheckingUpdate, setIsCheckingUpdate] = useState(false) const currentEnvironment = getCurrentEnvironment().join("\n") const { data: appVersion } = useQuery({ queryKey: ["appVersion"], queryFn: () => ipcServices?.app.getAppVersion(), }) + const { present } = useModalStack() const rendererVersion = PKG.version - const handleCheckForUpdates = () => { - ipcServices?.app.checkForUpdates() + const handleCheckForUpdates = async () => { + if (isCheckingUpdate) return + + setIsCheckingUpdate(true) + const toastId = toast.loading(t("about.checkingForUpdates")) + + try { + const result = await ipcServices?.app.checkForUpdates() + + if (result?.error) { + toast.error(t("about.updateCheckFailed"), { id: toastId }) + } else if (result?.hasUpdate) { + toast.success(t("about.updateAvailable"), { id: toastId }) + } else { + toast.info(t("about.noUpdateAvailable"), { id: toastId }) + } + } catch { + toast.error(t("about.updateCheckFailed"), { id: toastId }) + } finally { + setIsCheckingUpdate(false) + } + } + + const handleOpenLegal = (type: "privacy" | "tos") => { + present({ + id: `legal-${type}`, + title: type === "privacy" ? t("about.privacyPolicy") : t("about.termsOfService"), + content: () => , + resizeable: true, + clickOutsideToDismiss: true, + max: true, + }) } return ( -
-
-
- - -
-
- {APP_NAME} {MODE !== ModeEnum.production ? `(${MODE})` : ""} -
-
- {appVersion && ( - - app: {appVersion} - - )} - {rendererVersion && ( - - renderer: {rendererVersion} - - )} - -
-
- -
- {IN_ELECTRON && ( - - )} - -
+
+ {/* Header Section */} +
+
+
- -

+

+ +

+ {MODE !== ModeEnum.production && ( + + {MODE} + + )} +

{t("about.licenseInfo", { appName: APP_NAME, currentYear: new Date().getFullYear() })}

-

- - https://mgc.mingcute.com/ - - ), - ExternalLinkIcon: , + +

+ {appVersion && ( + + App + {appVersion} + + )} + {rendererVersion && ( + + Renderer + {rendererVersion} + + )} + +
+
-

- - open an issue - - - ), - ExternalLinkIcon: , - }} - /> -

+ {/* Quick Actions */} +
+ {IN_ELECTRON && ( + + )} + +
- + {/* Legal Section */} +
+ + + +
-

{t("about.socialMedia")}

-
+ {/* Resources Section */} +
+

{t("about.resources")}

+
+

+ + open an issue + + ), + }} + /> +

+

+ {t("about.projectLicense", { appName: APP_NAME })} +

+

+ + MingCute Icons + + ), + }} + /> +

+
+
+ + {/* Social Links */} +
+

{t("about.socialMedia")}

+
{SocialMediaLinks.map((link) => ( - - {link.label} + + {link.label} ))}
-
+
) } + +type LegalModalProps = { + type: "privacy" | "tos" +} + +const LegalModalContent: React.FC = ({ type }) => { + const content = type === "privacy" ? legalHtml.privacy : legalHtml.tos + + return ( + +
+