From 6ddc56632edf38b3df13bc8b226b280c372b5231 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Mon, 17 Jul 2023 15:49:03 +0800 Subject: [PATCH] fix: disable updater button when app updating (#3268) (cherry picked from commit 81bad608bc0a138ee7ae28f7329235ce7edcf1cb) --- .../app-updater-button/index.css.ts | 3 ++ .../app-sidebar/app-updater-button/index.tsx | 29 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/component/src/components/app-sidebar/app-updater-button/index.css.ts b/packages/component/src/components/app-sidebar/app-updater-button/index.css.ts index 494df95959..99b7bfe4b3 100644 --- a/packages/component/src/components/app-sidebar/app-updater-button/index.css.ts +++ b/packages/component/src/components/app-sidebar/app-updater-button/index.css.ts @@ -125,6 +125,9 @@ export const versionLabel = style({ fontSize: '10px', lineHeight: '18px', borderRadius: '4px', + maxWidth: '100px', + overflow: 'hidden', + textOverflow: 'ellipsis', }); export const whatsNewLabel = style({ diff --git a/packages/component/src/components/app-sidebar/app-updater-button/index.tsx b/packages/component/src/components/app-sidebar/app-updater-button/index.tsx index e208f42993..31c4802ca0 100644 --- a/packages/component/src/components/app-sidebar/app-updater-button/index.tsx +++ b/packages/component/src/components/app-sidebar/app-updater-button/index.tsx @@ -1,9 +1,10 @@ +import { Tooltip } from '@affine/component'; import { isBrowser, Unreachable } from '@affine/env/constant'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { CloseIcon, NewIcon, ResetIcon } from '@blocksuite/icons'; import clsx from 'clsx'; import { atom, useAtomValue, useSetAtom } from 'jotai'; -import { startTransition, useCallback } from 'react'; +import { startTransition, useCallback, useState } from 'react'; import * as styles from './index.css'; import { @@ -48,6 +49,7 @@ export function AppUpdaterButton({ className, style }: AddPageButtonProps) { const currentVersion = useAtomValue(currentVersionAtom); const downloadProgress = useAtomValue(downloadProgressAtom); const setChangelogCheckAtom = useSetAtom(changelogCheckedAtom); + const [appQuitting, setAppQuitting] = useState(false); const onDismissCurrentChangelog = useCallback(() => { if (!currentVersion) { @@ -64,6 +66,7 @@ export function AppUpdaterButton({ className, style }: AddPageButtonProps) { }, [currentVersion, setChangelogCheckAtom]); const onClickUpdate = useCallback(() => { if (updateReady) { + setAppQuitting(true); window.apis?.updater.quitAndInstall().catch(err => { // TODO: add error toast here console.error(err); @@ -103,19 +106,37 @@ export function AppUpdaterButton({ className, style }: AddPageButtonProps) { const whatsNew = !updateAvailable && currentChangelogUnread ? renderWhatsNew() : null; - return ( + const wrapWithTooltip = ( + node: React.ReactElement, + tooltip?: React.ReactElement | string + ) => { + if (!tooltip) { + return node; + } + + return ( + + {node} + + ); + }; + + return wrapWithTooltip( + , + updateAvailable?.version ); function renderUpdateAvailableAllowAutoUpdate() {