sync: fix redundant progress sync when changing window size (#265)

This commit is contained in:
Huang Xin
2025-01-29 12:29:26 +01:00
committed by GitHub
parent 27eca300fa
commit 01ff687472
3 changed files with 6 additions and 12 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
"default-src": "'self' 'unsafe-inline' blob: customprotocol: asset: http://asset.localhost ipc: http://ipc.localhost",
"connect-src": "'self' blob: asset: http://asset.localhost ipc: http://ipc.localhost https://*.sentry.io https://*.posthog.com https://*.deepl.com https://*.wikipedia.org https://*.wiktionary.org https://*.supabase.co https://*.readest.com wss://speech.platform.bing.com https://*.cloudflarestorage.com",
"img-src": "'self' blob: data: asset: http://asset.localhost https://*",
"style-src": "'self' 'unsafe-inline' blob: asset: http://asset.localhost https://cdn.jsdelivr.net",
"style-src": "'self' 'unsafe-inline' blob: asset: http://asset.localhost https://cdn.jsdelivr.net https://fonts.googleapis.com",
"font-src": "'self' data: asset: http://asset.localhost tauri: https://fonts.gstatic.com https://db.onlinewebfonts.com https://cdn.jsdelivr.net",
"frame-src": "'self' blob: asset: http://asset.localhost",
"script-src": "'self' 'unsafe-inline' 'unsafe-eval' blob: asset: http://asset.localhost https://*.sentry.io https://*.posthog.com"
@@ -50,11 +50,10 @@ export const useProgressSync = (bookKey: string) => {
};
useEffect(() => {
if (!progress) return;
if (!firstPulled.current) {
firstPulled.current = true;
pullConfig(bookKey);
}
if (!progress || firstPulled.current) return;
firstPulled.current = true;
pullConfig(bookKey);
return () => {
syncConfig();
};
+1 -6
View File
@@ -1,5 +1,4 @@
import { useEffect, useState } from 'react';
import { useEnv } from '@/context/EnvContext';
import { useSyncContext } from '@/context/SyncContext';
import { SyncData, SyncOp, SyncResult, SyncType } from '@/libs/sync';
import { useSettingsStore } from '@/store/settingsStore';
@@ -34,8 +33,7 @@ const computeMaxTimestamp = (records: BookDataRecord[]): number => {
const SEVEN_DAYS_IN_MS = 7 * 24 * 60 * 60 * 1000;
export function useSync(bookKey?: string) {
const { envConfig } = useEnv();
const { settings, setSettings, saveSettings } = useSettingsStore();
const { settings, setSettings } = useSettingsStore();
const { getConfig, setConfig } = useBookDataStore();
const config = bookKey ? getConfig(bookKey) : null;
@@ -95,13 +93,11 @@ export function useSync(bookKey?: string) {
case 'books':
settings.lastSyncedAtBooks = maxTime;
setSettings(settings);
saveSettings(envConfig, settings);
break;
case 'configs':
if (!bookId) {
settings.lastSyncedAtConfigs = maxTime;
setSettings(settings);
saveSettings(envConfig, settings);
} else if (bookKey && config) {
config.lastSyncedAtConfig = maxTime;
setConfig(bookKey, config);
@@ -111,7 +107,6 @@ export function useSync(bookKey?: string) {
if (!bookId) {
settings.lastSyncedAtNotes = maxTime;
setSettings(settings);
saveSettings(envConfig, settings);
} else if (bookKey && config) {
config.lastSyncedAtNotes = maxTime;
setConfig(bookKey, config);