From 5e1cb49cdc322a9e37c8ea358439cbed6a523723 Mon Sep 17 00:00:00 2001 From: troyeguo <13820674+troyeguo@users.noreply.github.com> Date: Sat, 20 Jun 2026 09:25:08 +0800 Subject: [PATCH] feat: add confirmBrowserExtensionAsync function and integrate it into DataSetting and SyncSetting components --- .../settings/dataSetting/component.tsx | 13 +++++++++++++ .../settings/syncSetting/component.tsx | 16 ++-------------- src/utils/common.ts | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/containers/settings/dataSetting/component.tsx b/src/containers/settings/dataSetting/component.tsx index aa90f9da..e0a96290 100644 --- a/src/containers/settings/dataSetting/component.tsx +++ b/src/containers/settings/dataSetting/component.tsx @@ -3,6 +3,7 @@ import { SettingInfoProps, SettingInfoState } from "./interface"; import { Trans } from "react-i18next"; import { clearAllData, + confirmBrowserExtensionAsync, generateSyncRecord, getStorageLocation, getWebsiteUrl, @@ -98,6 +99,12 @@ class DataSetting extends React.Component { return; } + if (!isElectron) { + if (!(await confirmBrowserExtensionAsync())) { + return; + } + } + const savedConfig = ConfigService.getObjectConfig( "koReaderSyncConfig", @@ -207,6 +214,12 @@ class DataSetting extends React.Component { const currentlyEnabled = this.state[item.propName]; if (!currentlyEnabled && item.requiresAuth) { + if (!isElectron) { + if (!(await confirmBrowserExtensionAsync())) { + return; + } + } + // Special case: Markdown sync uses a folder picker in Electron if (item.propName === "isEnableMarkdownSync" && isElectron) { const { ipcRenderer } = window.require("electron"); diff --git a/src/containers/settings/syncSetting/component.tsx b/src/containers/settings/syncSetting/component.tsx index 80f8ed37..ce13de49 100644 --- a/src/containers/settings/syncSetting/component.tsx +++ b/src/containers/settings/syncSetting/component.tsx @@ -9,6 +9,7 @@ import { syncSettingList } from "../../../constants/settingList"; import toast from "react-hot-toast"; import { + confirmBrowserExtensionAsync, generateSyncRecord, getICloudDrivePath, getServerRegion, @@ -99,20 +100,7 @@ class SyncSetting extends React.Component { !isElectron && driveList.find((item) => item.value === targetDrive)?.needExtension ) { - let result = await vexComfirmAsync( - "Due to browser security restrictions, you may not be able to use this data source properly. If you encounter any issues, you can resolve them by installing our browser extension.", - "Confirm", - "Install extension" - ); - if (!result) { - if ( - ConfigService.getReaderConfig("lang") && - ConfigService.getReaderConfig("lang").startsWith("zh") - ) { - openExternalUrl(getWebsiteUrl() + "/zh/use-extension"); - } else { - openExternalUrl(getWebsiteUrl() + "/en/use-extension"); - } + if (!(await confirmBrowserExtensionAsync())) { return; } } diff --git a/src/utils/common.ts b/src/utils/common.ts index 38ed372e..608af4b0 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -137,6 +137,22 @@ export const vexComfirmAsync = ( }); }); }; +export const confirmBrowserExtensionAsync = async (): Promise => { + const result = await vexComfirmAsync( + "Due to browser security restrictions, you may not be able to use this data source properly. If you encounter any issues, you can resolve them by installing our browser extension.", + "Confirm", + "Install extension" + ); + if (!result) { + const lang = ConfigService.getReaderConfig("lang"); + openExternalUrl( + getWebsiteUrl() + + (lang?.startsWith("zh") ? "/zh/use-extension" : "/en/use-extension") + ); + return false; + } + return true; +}; export const vexOpenAsync = ( config: Record, message: string,