From da11b8727e6ae52903781a455a281c0aa55cfbef Mon Sep 17 00:00:00 2001 From: huhuanming Date: Sat, 9 Nov 2024 14:31:41 +0800 Subject: [PATCH] feat: Clear cache page and Support Quit/Zoom In/Zoom Out shortcuts on Windows & Linux (OK-33706 OK-33652) (#6157) --- apps/desktop/src-electron/app.ts | 26 +- .../Setting/pages/ClearAppCache/index.tsx | 242 ++++++++++++++++++ .../SecuritySection/CleanDataItem/index.tsx | 214 +--------------- .../kit/src/views/Setting/router/index.tsx | 7 + packages/shared/src/routes/setting.ts | 2 + 5 files changed, 286 insertions(+), 205 deletions(-) create mode 100644 packages/kit/src/views/Setting/pages/ClearAppCache/index.tsx diff --git a/apps/desktop/src-electron/app.ts b/apps/desktop/src-electron/app.ts index cd5969db87a..1be90cc744c 100644 --- a/apps/desktop/src-electron/app.ts +++ b/apps/desktop/src-electron/app.ts @@ -154,7 +154,7 @@ const initMenu = () => { }, }, { type: 'separator' }, - { + isMac && { role: 'hide', accelerator: 'Alt+CmdOrCtrl+H', label: i18nText(ETranslations.menu_hide_onekey_wallet), @@ -166,6 +166,7 @@ const initMenu = () => { { type: 'separator' }, { role: 'quit', + accelerator: 'CmdOrCtrl+Q', label: i18nText(ETranslations.menu_quit_onekey_wallet), }, ].filter(Boolean), @@ -201,9 +202,26 @@ const initMenu = () => { { type: 'separator' }, ] : []), - { role: 'resetZoom', label: i18nText(ETranslations.menu_actual_size) }, - { role: 'zoomIn', label: i18nText(ETranslations.menu_zoom_in) }, - { role: 'zoomOut', label: i18nText(ETranslations.menu_zoom_out) }, + { + role: 'resetZoom', + label: i18nText(ETranslations.menu_actual_size), + accelerator: 'CmdOrCtrl+0', + }, + isMac + ? { + role: 'zoomIn', + label: i18nText(ETranslations.menu_zoom_in), + } + : { + role: 'zoomIn', + label: i18nText(ETranslations.menu_zoom_in), + accelerator: 'CmdOrCtrl+Shift+]', + }, + { + role: 'zoomOut', + label: i18nText(ETranslations.menu_zoom_out), + accelerator: isMac ? 'CmdOrCtrl+-' : 'CmdOrCtrl+Shift+[', + }, { type: 'separator' }, { role: 'togglefullscreen', diff --git a/packages/kit/src/views/Setting/pages/ClearAppCache/index.tsx b/packages/kit/src/views/Setting/pages/ClearAppCache/index.tsx new file mode 100644 index 00000000000..741ce8f85d4 --- /dev/null +++ b/packages/kit/src/views/Setting/pages/ClearAppCache/index.tsx @@ -0,0 +1,242 @@ +import type { FC } from 'react'; +import { useCallback, useMemo, useRef, useState } from 'react'; + +import { useIntl } from 'react-intl'; + +import type { INavSearchBarProps } from '@onekeyhq/components'; +import { + Checkbox, + Dialog, + Empty, + Form, + Page, + SectionList, + Stack, + Toast, + YStack, + useClipboard, + useForm, +} from '@onekeyhq/components'; +import {} from '@onekeyhq/components/src/layouts/SectionList'; +import backgroundApiProxy from '@onekeyhq/kit/src/background/instance/backgroundApiProxy'; +import { ListItem } from '@onekeyhq/kit/src/components/ListItem'; +import { + useCurrencyPersistAtom, + useSettingsPersistAtom, +} from '@onekeyhq/kit-bg/src/states/jotai/atoms'; +import { ETranslations } from '@onekeyhq/shared/src/locale'; +import platformEnv from '@onekeyhq/shared/src/platformEnv'; +import type { IClearCacheOnAppState } from '@onekeyhq/shared/types/setting'; + +const keyExtractor = (_: unknown, index: number) => `${index}`; + +// onPress: () => { +// Dialog.show({ +// title: intl.formatMessage({ +// id: ETranslations.settings_clear_cache_on_app, +// }), +// renderContent: , +// tone: 'destructive', +// confirmButtonProps: { +// disabledOn: ({ getForm }) => { +// const { getValues } = getForm() || {}; +// if (getValues) { +// const values = getValues(); +// return !Object.values(values).some((o) => Boolean(o)); +// } +// return true; +// }, +// }, +// onConfirm: async (dialogInstance) => { + +// }, +// }); +// }, +export default function ClearAppCache() { + const intl = useIntl(); + const form = useForm({ + defaultValues: { + tokenAndNFT: true, + transactionHistory: true, + swapHistory: true, + browserCache: true, + appUpdateCache: true, + browserHistory: false, + connectSites: false, + signatureRecord: false, + customToken: false, + customRpc: false, + serverNetworks: false, + } as IClearCacheOnAppState, + }); + const { copyText } = useClipboard(); + + const values = form.watch(); + const disabled = !Object.values(values).some((o) => Boolean(o)); + return ( + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ close()} + onConfirm={async (close) => { + if (values) { + await backgroundApiProxy.serviceSetting.clearCacheOnApp(values); + Toast.success({ + title: intl.formatMessage({ + id: ETranslations.global_success, + }), + }); + if ( + values?.browserCache && + (platformEnv.isWeb || platformEnv.isExtension) + ) { + if (platformEnv.isRuntimeChrome || platformEnv.isRuntimeEdge) { + let settingPath = 'chrome://settings/clearBrowserData'; + if (platformEnv.isRuntimeEdge) { + settingPath = 'edge://settings/clearBrowserData'; + } + Dialog.show({ + title: intl.formatMessage({ + id: ETranslations.settings_clear_browser_cache, + }), + description: intl.formatMessage( + { + id: ETranslations.settings_clear_browser_cache_desc, + }, + { url: settingPath }, + ), + onConfirm: () => { + copyText(settingPath); + close(); + }, + showCancelButton: false, + confirmButtonProps: { + variant: 'primary', + size: 'large', + icon: 'Copy3Outline', + }, + onConfirmText: intl.formatMessage({ + id: ETranslations.global_copy, + }), + }); + } else { + Dialog.show({ + title: intl.formatMessage({ + id: ETranslations.settings_clear_browser_cache, + }), + description: intl.formatMessage({ + id: ETranslations.settings_clear_browser_cache_desc2, + }), + showCancelButton: false, + confirmButtonProps: { + variant: 'primary', + size: 'large', + icon: 'Copy1Outline', + }, + onConfirm: () => { + close(); + }, + }); + } + } else { + close(); + } + } + }} + confirmButtonProps={{ + disabled, + }} + /> +
+ ); +} diff --git a/packages/kit/src/views/Setting/pages/List/SecuritySection/CleanDataItem/index.tsx b/packages/kit/src/views/Setting/pages/List/SecuritySection/CleanDataItem/index.tsx index caedef1a578..990e4fbc8b8 100644 --- a/packages/kit/src/views/Setting/pages/List/SecuritySection/CleanDataItem/index.tsx +++ b/packages/kit/src/views/Setting/pages/List/SecuritySection/CleanDataItem/index.tsx @@ -1,132 +1,29 @@ +import { useCallback } from 'react'; + import { useIntl } from 'react-intl'; -import { - ActionList, - Checkbox, - Dialog, - Stack, - Toast, - useClipboard, -} from '@onekeyhq/components'; +import type { IPageNavigationProp } from '@onekeyhq/components'; +import { ActionList, Dialog, Toast } from '@onekeyhq/components'; import backgroundApiProxy from '@onekeyhq/kit/src/background/instance/backgroundApiProxy'; import { ListItem } from '@onekeyhq/kit/src/components/ListItem'; +import useAppNavigation from '@onekeyhq/kit/src/hooks/useAppNavigation'; import { useResetApp } from '@onekeyhq/kit/src/views/Setting/hooks'; import { EAppEventBusNames, appEventBus, } from '@onekeyhq/shared/src/eventBus/appEventBus'; import { ETranslations } from '@onekeyhq/shared/src/locale'; -import platformEnv from '@onekeyhq/shared/src/platformEnv'; -import type { IClearCacheOnAppState } from '@onekeyhq/shared/types/setting'; - -const ClearCacheOnAppContent = () => { - const intl = useIntl(); - return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ); -}; +import { EModalSettingRoutes } from '@onekeyhq/shared/src/routes'; +import type { IModalSettingParamList } from '@onekeyhq/shared/src/routes'; export const CleanDataItem = () => { - const { copyText } = useClipboard(); const intl = useIntl(); const resetApp = useResetApp(); + const navigation = + useAppNavigation>(); + const toSettingClearAppCachePage = useCallback(() => { + navigation.push(EModalSettingRoutes.SettingClearAppCache); + }, [navigation]); return ( { label: intl.formatMessage({ id: ETranslations.settings_clear_cache_on_app, }), - onPress: () => { - Dialog.show({ - title: intl.formatMessage({ - id: ETranslations.settings_clear_cache_on_app, - }), - renderContent: , - tone: 'destructive', - confirmButtonProps: { - disabledOn: ({ getForm }) => { - const { getValues } = getForm() || {}; - if (getValues) { - const values = getValues(); - return !Object.values(values).some((o) => Boolean(o)); - } - return true; - }, - }, - onConfirm: async (dialogInstance) => { - const values = dialogInstance.getForm()?.getValues() as - | IClearCacheOnAppState - | undefined; - if (values) { - await backgroundApiProxy.serviceSetting.clearCacheOnApp( - values, - ); - Toast.success({ - title: intl.formatMessage({ - id: ETranslations.global_success, - }), - }); - if ( - values?.browserCache && - (platformEnv.isWeb || platformEnv.isExtension) - ) { - if ( - platformEnv.isRuntimeChrome || - platformEnv.isRuntimeEdge - ) { - let settingPath = 'chrome://settings/clearBrowserData'; - if (platformEnv.isRuntimeEdge) { - settingPath = 'edge://settings/clearBrowserData'; - } - Dialog.show({ - title: intl.formatMessage({ - id: ETranslations.settings_clear_browser_cache, - }), - description: intl.formatMessage( - { - id: ETranslations.settings_clear_browser_cache_desc, - }, - { url: settingPath }, - ), - onConfirm: () => { - copyText(settingPath); - }, - showCancelButton: false, - confirmButtonProps: { - variant: 'primary', - size: 'large', - icon: 'Copy3Outline', - }, - onConfirmText: intl.formatMessage({ - id: ETranslations.global_copy, - }), - }); - } else { - Dialog.show({ - title: intl.formatMessage({ - id: ETranslations.settings_clear_browser_cache, - }), - description: intl.formatMessage({ - id: ETranslations.settings_clear_browser_cache_desc2, - }), - showCancelButton: false, - confirmButtonProps: { - variant: 'primary', - size: 'large', - icon: 'Copy1Outline', - }, - }); - } - } - } - }, - }); - }, + onPress: toSettingClearAppCachePage, }, { label: intl.formatMessage({ diff --git a/packages/kit/src/views/Setting/router/index.tsx b/packages/kit/src/views/Setting/router/index.tsx index d66a7c3e842..54c2088f46e 100644 --- a/packages/kit/src/views/Setting/router/index.tsx +++ b/packages/kit/src/views/Setting/router/index.tsx @@ -20,6 +20,9 @@ const SettingAppAutoLockModal = LazyLoadPage( const SettingCurrencyModal = LazyLoadPage( () => import('@onekeyhq/kit/src/views/Setting/pages/Currency'), ); +const SettingClearAppCacheModal = LazyLoadPage( + () => import('@onekeyhq/kit/src/views/Setting/pages/ClearAppCache'), +); const SettingListModal = LazyLoadPage( () => import('@onekeyhq/kit/src/views/Setting/pages/List'), ); @@ -112,6 +115,10 @@ export const ModalSettingStack: IModalFlowNavigatorConfig< name: EModalSettingRoutes.SettingProtectModal, component: SettingProtectionModal, }, + { + name: EModalSettingRoutes.SettingClearAppCache, + component: SettingClearAppCacheModal, + }, { name: EModalSettingRoutes.SettingSignatureRecordModal, component: SettingSignatureRecordModal, diff --git a/packages/shared/src/routes/setting.ts b/packages/shared/src/routes/setting.ts index 5a1605e21ef..694393fcc1c 100644 --- a/packages/shared/src/routes/setting.ts +++ b/packages/shared/src/routes/setting.ts @@ -1,6 +1,7 @@ export enum EModalSettingRoutes { SettingListModal = 'SettingListModal', SettingCurrencyModal = 'SettingCurrencyModal', + SettingClearAppCache = 'SettingClearAppCache', SettingAccountDerivationModal = 'SettingAccountDerivationModal', SettingSpendUTXOModal = 'SettingSpendUTXOModal', SettingCustomRPC = 'SettingCustomRPC', @@ -20,6 +21,7 @@ export enum EModalSettingRoutes { export type IModalSettingParamList = { [EModalSettingRoutes.SettingListModal]: { flag?: string } | undefined; [EModalSettingRoutes.SettingCurrencyModal]: undefined; + [EModalSettingRoutes.SettingClearAppCache]: undefined; [EModalSettingRoutes.SettingAccountDerivationModal]: undefined; [EModalSettingRoutes.SettingSpendUTXOModal]: undefined; [EModalSettingRoutes.SettingCustomRPC]: undefined;