diff --git a/src/constants/gallery/index.ts b/src/constants/gallery/index.ts index a227c2637..66b7759d6 100644 --- a/src/constants/gallery/index.ts +++ b/src/constants/gallery/index.ts @@ -11,3 +11,5 @@ export enum PLAN_PERIOD { MONTH = 'month', YEAR = 'year', } + +export const SYNC_INTERVAL_IN_MICROSECONDS = 1000 * 60 * 5; // 5 minutes diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 3b8fe5225..f42dc7b1f 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -105,6 +105,8 @@ import { User } from 'types/user'; import { getData, LS_KEYS } from 'utils/storage/localStorage'; import { CenteredFlex } from 'components/Container'; import { checkConnectivity } from 'utils/error/ui'; +import { SYNC_INTERVAL_IN_MICROSECONDS } from 'constants/gallery'; +import ElectronService from 'services/electron/common'; import uploadManager from 'services/upload/uploadManager'; export const DeadCenter = styled('div')` @@ -262,6 +264,12 @@ export default function Gallery() { setIsFirstLoad(false); setJustSignedUp(false); setIsFirstFetch(false); + setInterval(() => { + syncWithRemote(false, true); + }, SYNC_INTERVAL_IN_MICROSECONDS); + ElectronService.registerForegroundEventListener(() => + syncWithRemote(false, true) + ); }; main(); }, []); diff --git a/src/services/electron/common.ts b/src/services/electron/common.ts index e110a3892..d0d031120 100644 --- a/src/services/electron/common.ts +++ b/src/services/electron/common.ts @@ -39,6 +39,11 @@ class ElectronService { return this.electronAPIs.logRendererProcessMemoryUsage(message); } } + registerForegroundEventListener(onForeground: () => void) { + if (this.electronAPIs?.registerForegroundEventListener) { + this.electronAPIs.registerForegroundEventListener(onForeground); + } + } } export default new ElectronService(); diff --git a/src/types/electron/index.ts b/src/types/electron/index.ts index 2a34ae8bd..4a50a48db 100644 --- a/src/types/electron/index.ts +++ b/src/types/electron/index.ts @@ -93,4 +93,5 @@ export interface ElectronAPIs { maxSize: number ) => Promise; logRendererProcessMemoryUsage: (message: string) => Promise; + registerForegroundEventListener: (onForeground: () => void) => void; }