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 <tukon479@gmail.com>
This commit is contained in:
Innei
2025-07-11 20:01:17 +08:00
parent 435ecf8700
commit f0c126223c
7 changed files with 320 additions and 127 deletions
@@ -44,8 +44,8 @@ export class AppService extends IpcService {
}
@IpcMethod()
checkForUpdates(): void {
checkForAppUpdates()
async checkForUpdates(): Promise<{ hasUpdate: boolean; error?: string }> {
return checkForAppUpdates()
}
@IpcMethod()
+34 -13
View File
@@ -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
}
}
@@ -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: () => <LegalModalContent type={type} />,
resizeable: true,
clickOutsideToDismiss: true,
max: true,
})
}
return (
<div>
<section className="mt-4">
<div className="flex gap-3">
<Logo className="size-[52px]" />
<div className="flex grow flex-col">
<div className="text-lg font-bold">
{APP_NAME} {MODE !== ModeEnum.production ? `(${MODE})` : ""}
</div>
<div className="flex flex-wrap items-center gap-2">
{appVersion && (
<span className="bg-material-medium rounded px-2 py-1 text-xs">
app: {appVersion}
</span>
)}
{rendererVersion && (
<span className="bg-material-medium rounded px-2 py-1 text-xs">
renderer: {rendererVersion}
</span>
)}
<CopyButton
variant="outline"
value={
rendererVersion
? `${currentEnvironment}\n**Renderer**: ${rendererVersion}`
: currentEnvironment
}
className="text-text-secondary hover:bg-theme-item-hover hover:text-text active:bg-theme-item-active border-0 bg-transparent p-1 [&_i]:size-3"
/>
</div>
</div>
<div className="flex shrink-0 gap-2">
{IN_ELECTRON && (
<Button variant="outline" onClick={handleCheckForUpdates} buttonClassName="h-10">
{t("about.checkForUpdates")}
</Button>
)}
<Button
variant="outline"
buttonClassName="h-10"
onClick={() => {
window.open(`${repository.url}/releases`, "_blank")
}}
>
{t("about.changelog")}
</Button>
</div>
<div className="mx-auto mt-6 max-w-3xl space-y-8">
{/* Header Section */}
<div className="px-2 text-center">
<div className="mb-6 flex justify-center">
<Logo className="size-20" />
</div>
<p className="mt-6 text-balance text-sm">
<h1 className="flex justify-center">
<Folo className="size-16" />
</h1>
{MODE !== ModeEnum.production && (
<span className="text-text-tertiary block -translate-y-2 text-sm font-normal">
{MODE}
</span>
)}
<p className="text-text-secondary mt-2 text-sm">
{t("about.licenseInfo", { appName: APP_NAME, currentYear: new Date().getFullYear() })}
</p>
<p className="mt-3 text-balance text-sm">
<Trans
ns="settings"
i18nKey="about.iconLibrary"
components={{
IconLibraryLink: (
<a
className="follow-link--underline inline-flex items-center"
href="https://mgc.mingcute.com/"
target="_blank"
rel="noreferrer"
>
https://mgc.mingcute.com/
</a>
),
ExternalLinkIcon: <i className="i-mgc-external-link-cute-re translate-y-px" />,
<div className="mt-6 flex flex-wrap items-center justify-center gap-2">
{appVersion && (
<span className="bg-fill-secondary text-text-secondary inline-flex items-center rounded-full px-3 py-1 text-xs font-medium">
<span className="text-text-tertiary mr-1.5">App</span>
{appVersion}
</span>
)}
{rendererVersion && (
<span className="bg-fill-secondary text-text-secondary inline-flex items-center rounded-full px-3 py-1 text-xs font-medium">
<span className="text-text-tertiary mr-1.5">Renderer</span>
{rendererVersion}
</span>
)}
<button
type="button"
onClick={() => {
navigator.clipboard.writeText(
rendererVersion
? `${currentEnvironment}\n**Renderer**: ${rendererVersion}`
: currentEnvironment,
)
toast.success(t("about.environmentCopied"))
}}
/>
</p>
className="text-text-tertiary hover:text-text-secondary hover:bg-fill-secondary inline-flex items-center rounded-full px-3 py-1 text-xs transition-colors"
>
<i className="i-mgc-copy-cute-re mr-1.5" />
{t("about.copyEnvironment")}
</button>
</div>
</div>
<p className="mt-3 text-sm">
<Trans
ns="settings"
i18nKey="about.feedbackInfo"
values={{ appName: APP_NAME, commitSha: GIT_COMMIT_SHA.slice(0, 7).toUpperCase() }}
components={{
OpenIssueLink: (
<a
className="inline-flex cursor-pointer items-center gap-1 hover:underline"
href={getNewIssueUrl({ template: "feature_request.yml" })}
target="_blank"
>
open an issue
<i className="i-mgc-external-link-cute-re" />
</a>
),
ExternalLinkIcon: <i className="i-mgc-external-link-cute-re" />,
}}
/>
</p>
{/* Quick Actions */}
<div className="-mx-3 space-y-1 px-2">
{IN_ELECTRON && (
<button
type="button"
onClick={handleCheckForUpdates}
disabled={isCheckingUpdate}
className="hover:bg-fill-secondary group flex w-full items-center justify-between rounded-lg p-3 text-left transition-all hover:shadow-sm"
>
<div className="flex items-center gap-3">
<div>
<div className="text-sm font-medium">{t("about.checkForUpdates")}</div>
<div className="text-text-tertiary text-xs">{t("about.updateDescription")}</div>
</div>
</div>
{isCheckingUpdate ? (
<i className="i-mgc-loading-3-cute-re animate-spin text-base" />
) : (
<i className="i-mgc-arrow-right-up-cute-re text-text-tertiary group-hover:text-accent text-base transition-all group-hover:-translate-y-0.5 group-hover:translate-x-0.5" />
)}
</button>
)}
<button
type="button"
onClick={() => window.open(`${repository.url}/releases`, "_blank")}
className="hover:bg-fill-secondary group flex w-full items-center justify-between rounded-lg p-3 text-left transition-all hover:shadow-sm"
>
<div>
<div className="text-sm font-medium">{t("about.changelog")}</div>
<div className="text-text-tertiary text-xs">{t("about.changelogDescription")}</div>
</div>
<i className="i-mgc-external-link-cute-re text-text-tertiary group-hover:text-accent text-base transition-all group-hover:-translate-y-0.5 group-hover:translate-x-0.5" />
</button>
</div>
<Divider className="scale-x-50" />
{/* Legal Section */}
<div className="-mx-3 !mt-4 space-y-1 px-2">
<Divider />
<button
type="button"
onClick={() => handleOpenLegal("tos")}
className="hover:bg-fill-secondary group flex w-full items-center justify-between rounded-lg p-3 text-left transition-all hover:shadow-sm"
>
<span className="text-sm">{t("about.termsOfService")}</span>
<i className="i-mgc-external-link-cute-re text-text-tertiary group-hover:text-accent transition-all group-hover:-translate-y-0.5 group-hover:translate-x-0.5" />
</button>
<button
type="button"
onClick={() => handleOpenLegal("privacy")}
className="hover:bg-fill-secondary group flex w-full items-center justify-between rounded-lg p-3 text-left transition-all hover:shadow-sm"
>
<span className="text-sm">{t("about.privacyPolicy")}</span>
<i className="i-mgc-external-link-cute-re text-text-tertiary group-hover:text-accent transition-all group-hover:-translate-y-0.5 group-hover:translate-x-0.5" />
</button>
</div>
<h2 className="text-base font-semibold">{t("about.socialMedia")}</h2>
<div className="mt-2 flex flex-wrap gap-2">
{/* Resources Section */}
<div className="px-2">
<h2 className="text-text-secondary mb-4 text-sm font-semibold">{t("about.resources")}</h2>
<div className="space-y-4">
<p className="text-text-secondary text-sm leading-relaxed">
<Trans
ns="settings"
i18nKey="about.feedbackInfo"
values={{ appName: APP_NAME, commitSha: GIT_COMMIT_SHA.slice(0, 7).toUpperCase() }}
components={{
OpenIssueLink: (
<a
className="text-accent hover:underline"
href={getNewIssueUrl({ template: "feature_request.yml" })}
target="_blank"
>
open an issue
</a>
),
}}
/>
</p>
<p className="text-text-secondary text-sm leading-relaxed">
{t("about.projectLicense", { appName: APP_NAME })}
</p>
<p className="text-text-secondary text-sm leading-relaxed">
<Trans
ns="settings"
i18nKey="about.iconLibrary"
components={{
IconLibraryLink: (
<a
className="text-accent hover:underline"
href="https://mgc.mingcute.com/"
target="_blank"
rel="noreferrer"
>
MingCute Icons
</a>
),
}}
/>
</p>
</div>
</div>
{/* Social Links */}
<div className="px-2">
<h2 className="text-text-secondary mb-4 text-sm font-semibold">{t("about.socialMedia")}</h2>
<div className="flex flex-wrap gap-6">
{SocialMediaLinks.map((link) => (
<a
href={link.url}
key={link.url}
className={styledButtonVariant({
variant: "outline",
className: "flex-1 gap-1",
})}
className="hover:text-accent flex items-center gap-2 text-sm transition-colors"
target="_blank"
rel="noreferrer"
>
<i className={link.iconClassName} />
{link.label}
<i className={cn(link.iconClassName, "text-base")} />
<span>{link.label}</span>
</a>
))}
</div>
</section>
</div>
</div>
)
}
type LegalModalProps = {
type: "privacy" | "tos"
}
const LegalModalContent: React.FC<LegalModalProps> = ({ type }) => {
const content = type === "privacy" ? legalHtml.privacy : legalHtml.tos
return (
<m.div className="size-full overflow-hidden">
<div className="bg-background size-full overflow-auto rounded-lg" onClick={stopPropagation}>
<iframe
sandbox="allow-scripts"
srcDoc={content}
title={type === "privacy" ? "Privacy Policy" : "Terms of Service"}
className="size-full border-0"
/>
</div>
</m.div>
)
}
+17 -2
View File
@@ -1,11 +1,26 @@
{
"about.changelog": "Changelog",
"about.changelogDescription": "See what's new in each version",
"about.checkForUpdates": "Check for Updates",
"about.feedbackInfo": "{{appName}} ({{commitSha}}) is open-source and actively developed on GitHub. If you have any feedback or suggestions, please feel free to <OpenIssueLink>open an issue</OpenIssueLink> <ExternalLinkIcon /> on our GitHub.",
"about.iconLibrary": "The icon library used is copyrighted by <IconLibraryLink /> <ExternalLinkIcon /> and cannot be redistributed.",
"about.checkNow": "Check now",
"about.checkingForUpdates": "Checking for updates...",
"about.copyEnvironment": "Copy environment",
"about.environmentCopied": "Environment info copied",
"about.feedbackInfo": "{{appName}} ({{commitSha}}) is open-source and actively developed on GitHub. If you have any feedback or suggestions, please feel free to <OpenIssueLink>open an issue</OpenIssueLink> on our GitHub.",
"about.iconLibrary": "The icon library used is copyrighted by <IconLibraryLink /> and cannot be redistributed.",
"about.legal": "Legal",
"about.licenseInfo": "Copyright © {{currentYear}} {{appName}}. All rights reserved.",
"about.noUpdateAvailable": "You're on the latest version",
"about.privacyPolicy": "Privacy Policy",
"about.projectLicense": "{{appName}} is licensed under the GNU General Public License version 3 with additional exceptions.",
"about.resources": "Resources & Contributions",
"about.sidebar_title": "About",
"about.socialMedia": "Social Media",
"about.termsOfService": "Terms of Service",
"about.updateAvailable": "Update available!",
"about.updateCheckFailed": "Failed to check for updates",
"about.updateDescription": "Keep your app up to date with the latest features and improvements",
"about.viewChangelog": "View changelog",
"actions.actionName": "Action {{number}}",
"actions.action_card.add": "Add",
"actions.action_card.all": "All",
+17 -2
View File
@@ -1,11 +1,26 @@
{
"about.changelog": "変更履歴",
"about.changelogDescription": "各バージョンの新機能を確認",
"about.checkForUpdates": "アップデートを確認",
"about.feedbackInfo": "{{appName}} ({{commitSha}}) は開発の初期段階にあります。フィードバックや提案があれば、気軽に <OpenIssueLink>GitHub で課題を報告してください</OpenIssueLink> <ExternalLinkIcon />。",
"about.iconLibrary": "使用されているアイコンライブラリは <IconLibraryLink /> <ExternalLinkIcon /> によって著作権が保護されており、再配布できません。",
"about.checkNow": "今すぐ確認",
"about.checkingForUpdates": "アップデートを確認中...",
"about.copyEnvironment": "環境をコピー",
"about.environmentCopied": "環境情報をコピーしました",
"about.feedbackInfo": "{{appName}} ({{commitSha}}) は開発の初期段階にあります。フィードバックや提案があれば、気軽に <OpenIssueLink>GitHub で課題を報告してください</OpenIssueLink> 。",
"about.iconLibrary": "使用されているアイコンライブラリは <IconLibraryLink /> によって著作権が保護されており、再配布できません。",
"about.legal": "法的情報",
"about.licenseInfo": "Copyright © {{currentYear}} {{appName}}. All rights reserved.",
"about.noUpdateAvailable": "最新版を使用しています",
"about.privacyPolicy": "プライバシーポリシー",
"about.projectLicense": "{{appName}} は GNU General Public License バージョン3に追加の例外条項を加えたライセンスで提供されています。",
"about.resources": "リソースと貢献",
"about.sidebar_title": "About",
"about.socialMedia": "ソーシャルメディア",
"about.termsOfService": "利用規約",
"about.updateAvailable": "アップデートがあります!",
"about.updateCheckFailed": "アップデートの確認に失敗しました",
"about.updateDescription": "最新の機能と改善を取得するため、アプリを最新の状態に保ちましょう",
"about.viewChangelog": "変更履歴を表示",
"actions.actionName": "アクション {{number}}",
"actions.action_card.add": "追加",
"actions.action_card.all": "すべて",
+17 -2
View File
@@ -1,11 +1,26 @@
{
"about.changelog": "更新日志",
"about.changelogDescription": "查看每个版本的新功能",
"about.checkForUpdates": "检查更新",
"about.feedbackInfo": "{{appName}}({{commitSha}})正处于开发的早期阶段。如果你有任何反馈或建议,请随时在我们的 GitHub 上<OpenIssueLink>提出</OpenIssueLink> <ExternalLinkIcon />。",
"about.iconLibrary": "使用的图标库受版权保护,版权所有者为 <IconLibraryLink /><ExternalLinkIcon />,不得重新分发。",
"about.checkNow": "立即检查",
"about.checkingForUpdates": "正在检查更新...",
"about.copyEnvironment": "复制环境",
"about.environmentCopied": "环境信息已复制",
"about.feedbackInfo": "{{appName}}({{commitSha}})正处于开发的早期阶段。如果你有任何反馈或建议,请随时在我们的 GitHub 上<OpenIssueLink>提出</OpenIssueLink> 。",
"about.iconLibrary": "使用的图标库受版权保护,版权所有者为 <IconLibraryLink />,不得重新分发。",
"about.legal": "法律信息",
"about.licenseInfo": "Copyright © {{currentYear}} {{appName}}. 保留所有权利。",
"about.noUpdateAvailable": "已是最新版本",
"about.privacyPolicy": "隐私政策",
"about.projectLicense": "{{appName}} 采用 GNU 通用公共许可证第3版授权,并附有额外的例外条款。",
"about.resources": "资源与贡献",
"about.sidebar_title": "关于",
"about.socialMedia": "社交媒体",
"about.termsOfService": "服务条款",
"about.updateAvailable": "有可用更新!",
"about.updateCheckFailed": "检查更新失败",
"about.updateDescription": "保持应用程序更新以获得最新功能和改进",
"about.viewChangelog": "查看更新日志",
"actions.actionName": "规则 {{number}}",
"actions.action_card.add": "添加",
"actions.action_card.all": "全部",
+17 -2
View File
@@ -1,11 +1,26 @@
{
"about.changelog": "更新日誌",
"about.changelogDescription": "查看每個版本的新功能",
"about.checkForUpdates": "檢查更新",
"about.feedbackInfo": "{{appName}} ({{commitSha}}) 正處於開發早期階段。如果您有任何回饋或建議,請隨時在我們的 GitHub 上 <OpenIssueLink>提交問題</OpenIssueLink> <ExternalLinkIcon />。",
"about.iconLibrary": "所使用的圖標庫版權由 <IconLibraryLink /> <ExternalLinkIcon /> 所有,不得重新分發。",
"about.checkNow": "立即檢查",
"about.checkingForUpdates": "正在檢查更新...",
"about.copyEnvironment": "複製環境",
"about.environmentCopied": "環境資訊已複製",
"about.feedbackInfo": "{{appName}} ({{commitSha}}) 正處於開發早期階段。如果您有任何回饋或建議,請隨時在我們的 GitHub 上 <OpenIssueLink>提交問題</OpenIssueLink> 。",
"about.iconLibrary": "所使用的圖標庫版權由 <IconLibraryLink /> 所有,不得重新分發。",
"about.legal": "法律資訊",
"about.licenseInfo": "版權所有 © {{currentYear}} {{appName}}。保留所有權利。",
"about.noUpdateAvailable": "已是最新版本",
"about.privacyPolicy": "隱私政策",
"about.projectLicense": "{{appName}} 採用 GNU 通用公共授權條款第3版授權,並附有額外的例外條款。",
"about.resources": "資源與貢獻",
"about.sidebar_title": "關於",
"about.socialMedia": "社群媒體",
"about.termsOfService": "服務條款",
"about.updateAvailable": "有可用更新!",
"about.updateCheckFailed": "檢查更新失敗",
"about.updateDescription": "保持應用程式更新以獲得最新功能和改進",
"about.viewChangelog": "查看更新日誌",
"actions.actionName": "規則 {{number}}",
"actions.action_card.add": "新增",
"actions.action_card.all": "全部",