From 060cabd5f9dc6ac6d7ba904dbbb01821f4064164 Mon Sep 17 00:00:00 2001 From: troyeguo <13820674+troyeguo@users.noreply.github.com> Date: Fri, 19 Dec 2025 08:34:40 +0800 Subject: [PATCH] feat: Refactor cloud sync handling and add user info fetching in relevant components --- src/containers/header/component.tsx | 1 + .../settings/accountSetting/component.tsx | 4 ++-- src/containers/settings/syncSetting/component.tsx | 3 ++- src/containers/settings/syncSetting/index.tsx | 2 ++ src/containers/settings/syncSetting/interface.tsx | 1 + src/pages/login/component.tsx | 4 ++-- src/utils/common.ts | 14 +++++++++++++- 7 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/containers/header/component.tsx b/src/containers/header/component.tsx index 8bd959e9..ce6067b9 100644 --- a/src/containers/header/component.tsx +++ b/src/containers/header/component.tsx @@ -461,6 +461,7 @@ class Header extends React.Component { default_sync_option: this.props.defaultSyncOption, default_sync_token: encryptedToken || "", }); + await this.props.handleFetchUserInfo(); toast.success(this.props.t("Setup successful")); this.handleCloudSync(); } diff --git a/src/containers/settings/accountSetting/component.tsx b/src/containers/settings/accountSetting/component.tsx index 1559d381..bfc6926d 100644 --- a/src/containers/settings/accountSetting/component.tsx +++ b/src/containers/settings/accountSetting/component.tsx @@ -8,7 +8,7 @@ import { formatTimestamp, getServerRegion, getWebsiteUrl, - handleCloudSync, + handleAutoCloudSync, handleContextMenu, openInBrowser, reloadManager, @@ -190,7 +190,7 @@ class AccountSetting extends React.Component< }); this.props.handleFetchAuthed(); this.props.handleFetchLoginOptionList(); - let result = await handleCloudSync(); + let result = await handleAutoCloudSync(); if (result) { this.props.cloudSyncFunc(); } else { diff --git a/src/containers/settings/syncSetting/component.tsx b/src/containers/settings/syncSetting/component.tsx index 2a39aa36..04fe036b 100644 --- a/src/containers/settings/syncSetting/component.tsx +++ b/src/containers/settings/syncSetting/component.tsx @@ -242,12 +242,13 @@ class SyncSetting extends React.Component { let encryptToken = await TokenService.getToken( this.props.defaultSyncOption + "_token" ); - updateUserConfig({ + await updateUserConfig({ is_enable_koodo_sync: ConfigService.getReaderConfig("isEnableKoodoSync"), default_sync_option: this.props.defaultSyncOption, default_sync_token: encryptToken || "", }); + await this.props.handleFetchUserInfo(); if ( ConfigService.getReaderConfig("isEnableKoodoSync") === "yes" diff --git a/src/containers/settings/syncSetting/index.tsx b/src/containers/settings/syncSetting/index.tsx index 3409015f..2bd2ac9b 100644 --- a/src/containers/settings/syncSetting/index.tsx +++ b/src/containers/settings/syncSetting/index.tsx @@ -14,6 +14,7 @@ import { handleLoadingDialog, handleFetchAuthed, handleLoginOptionList, + handleFetchUserInfo, } from "../../../store/actions"; import { stateType } from "../../../store"; import { withRouter } from "react-router-dom"; @@ -48,6 +49,7 @@ const actionCreator = { handleLoadingDialog, handleFetchAuthed, handleLoginOptionList, + handleFetchUserInfo, }; export default connect( mapStateToProps, diff --git a/src/containers/settings/syncSetting/interface.tsx b/src/containers/settings/syncSetting/interface.tsx index f266b885..c26749cf 100644 --- a/src/containers/settings/syncSetting/interface.tsx +++ b/src/containers/settings/syncSetting/interface.tsx @@ -20,6 +20,7 @@ export interface SettingInfoProps extends RouteComponentProps { handleFetchBooks: () => void; handleFetchPlugins: () => void; cloudSyncFunc: () => Promise; + handleFetchUserInfo: () => Promise; bookmarks: BookmarkModel[]; notes: NoteModel[]; isOpenTokenDialog: boolean; diff --git a/src/pages/login/component.tsx b/src/pages/login/component.tsx index 78f2eb7a..5ba438d6 100644 --- a/src/pages/login/component.tsx +++ b/src/pages/login/component.tsx @@ -8,7 +8,7 @@ import { loginList } from "../../constants/loginList"; import { generateSyncRecord, getServerRegion, - handleCloudSync, + handleAutoCloudSync, handleContextMenu, openInBrowser, removeSearchParams, @@ -89,7 +89,7 @@ class Login extends React.Component { let res = await loginRegister(service, code); if (res.code === 200) { this.props.handleLoadingDialog(false); - let result = await handleCloudSync(); + let result = await handleAutoCloudSync(); if (result) { this.props.cloudSyncFunc(); } else { diff --git a/src/utils/common.ts b/src/utils/common.ts index 5d3342d5..6dae97e5 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1006,13 +1006,25 @@ export const resetKoodoSync = async () => { }); }, 1000); }; -export const handleCloudSync = async () => { +export const handleAutoCloudSync = async () => { let syncRes = await getCloudSyncToken(); if ( syncRes.code === 200 && syncRes.data.default_sync_option && syncRes.data.default_sync_token ) { + let supportedSources = driveList + .filter((item) => { + if (isElectron) { + return item.support.includes("desktop"); + } else { + return item.support.includes("browser"); + } + }) + .map((item) => item.value); + if (!supportedSources.includes(syncRes.data.default_sync_option)) { + return false; + } ConfigService.setItem( "defaultSyncOption", syncRes.data.default_sync_option