feat: add auto sync option and update related settings in header and sync components

This commit is contained in:
troyeguo
2025-05-16 17:05:42 +08:00
parent 6cd23b03c0
commit 21d35d145a
10 changed files with 65 additions and 37 deletions

View File

File diff suppressed because one or more lines are too long

View File

File diff suppressed because one or more lines are too long

View File

File diff suppressed because one or more lines are too long

View File

@@ -590,6 +590,8 @@
"Upgrade to Pro": "升级专业版",
"To ensure a smooth synchronization experience, your reading progress, notes, highlights, bookmarks, and other data will be stored and synced through our cloud service": "为了确保流畅的同步体验,您的阅读进度、笔记、高亮、书签等数据将通过我们的云服务进行存储和同步",
"Enable Koodo Sync": "启用 Koodo Sync",
"Disable automatic sync": "禁用自动同步",
"By default, Koodo Reader will automatically synchronize your data when you open the app and exit reading": "默认情况下Koodo Reader 会在您打开应用和退出阅读时自动同步数据",
"Backup to": "备份到",
"Restore from": "恢复自",
"Sync and backup": "同步和备份",

View File

@@ -247,7 +247,7 @@ export const driveInputConfig: DriveInputConfig = {
{
label: "AccessKeyId",
value: "accessKeyId",
type: "text",
type: "password",
required: true,
},
{

View File

@@ -73,6 +73,12 @@ export const appearanceSettingList = [
},
];
export const syncSettingList = [
{
isElectron: false,
title: "Disable automatic sync",
desc: "By default, Koodo Reader will automatically synchronize your data when you open the app and exit reading",
propName: "isDisableAutoSync",
},
{
isElectron: false,
title: "Enable Koodo Sync",

View File

@@ -50,6 +50,7 @@ class Header extends React.Component<HeaderProps, HeaderState> {
isDeveloperVer: false,
isHidePro: false,
isSync: false,
isAutoSync: ConfigService.getReaderConfig("isDisableAutoSync") !== "yes",
};
}
async componentDidMount() {
@@ -135,6 +136,10 @@ class Header extends React.Component<HeaderProps, HeaderState> {
console.error(error);
}
}
if (this.state.isAutoSync) {
this.setState({ isSync: true });
await this.handleCloudSync();
}
nextProps.handleFetchUserConfig();
}
if (!nextProps.isAuthed && nextProps.isAuthed !== this.props.isAuthed) {
@@ -216,16 +221,20 @@ class Header extends React.Component<HeaderProps, HeaderState> {
return false;
}
checkMissingBook(this.props.books);
toast.loading(
this.props.t("Start syncing") +
" (" +
this.props.t(
driveList.find((item) => item.value === this.props.defaultSyncOption)
?.label || ""
) +
")",
{ id: "syncing" }
);
if (ConfigService.getReaderConfig("isEnableKoodoSync") !== "yes") {
toast.loading(
this.props.t("Start syncing") +
" (" +
this.props.t(
driveList.find(
(item) => item.value === this.props.defaultSyncOption
)?.label || ""
) +
")",
{ id: "syncing" }
);
}
return true;
};
getCompareResult = async () => {
@@ -243,7 +252,10 @@ class Header extends React.Component<HeaderProps, HeaderState> {
let config = {};
let service = ConfigService.getItem("defaultSyncOption");
if (!service) {
toast.error(this.props.t("Please add data source in the setting"));
if (!this.state.isAutoSync) {
toast.error(this.props.t("Please add data source in the setting"));
}
this.setState({ isSync: false });
return false;
}
@@ -266,31 +278,35 @@ class Header extends React.Component<HeaderProps, HeaderState> {
let stats = await window
.require("electron")
.ipcRenderer.invoke("cloud-stats", config);
toast.loading(
this.props.t("Start Transfering Data") +
" (" +
stats.completed +
"/" +
stats.total +
")",
{
id: "syncing",
}
);
if (stats.total > 0) {
toast.loading(
this.props.t("Start Transfering Data") +
" (" +
stats.completed +
"/" +
stats.total +
")",
{
id: "syncing",
}
);
}
} else {
let syncUtil = await SyncService.getSyncUtil();
let stats = await syncUtil.getStats();
toast.loading(
this.props.t("Start Transfering Data") +
" (" +
stats.completed +
"/" +
stats.total +
")",
{
id: "syncing",
}
);
if (stats.total > 0) {
toast.loading(
this.props.t("Start Transfering Data") +
" (" +
stats.completed +
"/" +
stats.total +
")",
{
id: "syncing",
}
);
}
}
}, 1000);
let res = await this.beforeSync();

View File

@@ -40,4 +40,5 @@ export interface HeaderState {
isDeveloperVer: boolean;
isHidePro: boolean;
isSync: boolean;
isAutoSync: boolean;
}

View File

@@ -58,6 +58,8 @@ class SyncSetting extends React.Component<SettingInfoProps, SettingInfoState> {
appSkin: ConfigService.getReaderConfig("appSkin"),
isUseBuiltIn: ConfigService.getReaderConfig("isUseBuiltIn") === "yes",
isKeepLocal: ConfigService.getReaderConfig("isKeepLocal") === "yes",
isDisableAutoSync:
ConfigService.getReaderConfig("isDisableAutoSync") === "yes",
isEnableKoodoSync:
ConfigService.getReaderConfig("isEnableKoodoSync") === "yes",
isDisablePDFCover:

View File

@@ -48,6 +48,7 @@ export interface SettingInfoState {
isPrecacheBook: boolean;
isKeepLocal: boolean;
isEnableKoodoSync: boolean;
isDisableAutoSync: boolean;
isUseBuiltIn: boolean;
isDisablePDFCover: boolean;
isAutoFullscreen: boolean;