From d76e0b8aab1efecd10fc1fc98dfcf594fd2f93d1 Mon Sep 17 00:00:00 2001 From: migueldev01 Date: Thu, 21 Mar 2024 14:47:25 -0500 Subject: [PATCH 01/11] feat: add sync menu item --- src/apps/main/remote-sync/handlers.ts | 11 +++++++---- src/apps/renderer/localize/locales/en.json | 1 + src/apps/renderer/localize/locales/es.json | 1 + src/apps/renderer/pages/Widget/Header.tsx | 12 ++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index c4462f76c..81987e0c2 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -77,14 +77,17 @@ ipcMain.handle('get-remote-sync-status', () => remoteSyncManager.getSyncStatus() ); +export async function updateRemoteSync(): Promise { + await sleep(2_000); + await remoteSyncManager.startRemoteSync(); + updateSyncEngine(); +} + eventBus.on('RECEIVED_REMOTE_CHANGES', async () => { // Wait before checking for updates, could be possible // that we received the notification, but if we check // for new data we don't receive it - await sleep(2_000); - - await remoteSyncManager.startRemoteSync(); - updateSyncEngine(); + await updateRemoteSync(); }); eventBus.on('USER_LOGGED_IN', async () => { diff --git a/src/apps/renderer/localize/locales/en.json b/src/apps/renderer/localize/locales/en.json index 59cfa584c..744a579ff 100644 --- a/src/apps/renderer/localize/locales/en.json +++ b/src/apps/renderer/localize/locales/en.json @@ -130,6 +130,7 @@ }, "dropdown": { "preferences": "Preferences", + "sync": "Sync", "issues": "Issues", "send-feedback": "Send feedback", "support": "Support", diff --git a/src/apps/renderer/localize/locales/es.json b/src/apps/renderer/localize/locales/es.json index 2ce257eaf..aa0fd9de3 100644 --- a/src/apps/renderer/localize/locales/es.json +++ b/src/apps/renderer/localize/locales/es.json @@ -130,6 +130,7 @@ }, "dropdown": { "preferences": "Preferencias", + "sync": "Sincronizar", "issues": "Lista de errores", "send-feedback": "Enviar feedback", "support": "Ayuda", diff --git a/src/apps/renderer/pages/Widget/Header.tsx b/src/apps/renderer/pages/Widget/Header.tsx index 33dca6632..cbd2525cd 100644 --- a/src/apps/renderer/pages/Widget/Header.tsx +++ b/src/apps/renderer/pages/Widget/Header.tsx @@ -195,6 +195,18 @@ export default function Header() { )} + + {({ active }) => ( +
+ window.electron.openSettingsWindow()} + > + {translate('widget.header.dropdown.sync')} + +
+ )} +
{({ active }) => (
From a6b0787869d7102cf411bb488bb2c1f17a832d53 Mon Sep 17 00:00:00 2001 From: migueldev01 Date: Thu, 21 Mar 2024 16:50:27 -0500 Subject: [PATCH 02/11] feat: logic to run sync manually using update remote sync --- src/apps/main/preload.d.ts | 1 + src/apps/main/preload.js | 3 +++ src/apps/main/remote-sync/handlers.ts | 5 +++++ src/apps/renderer/pages/Widget/Header.tsx | 9 +++++---- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/apps/main/preload.d.ts b/src/apps/main/preload.d.ts index bd484f6ab..6ea2ee4a0 100644 --- a/src/apps/main/preload.d.ts +++ b/src/apps/main/preload.d.ts @@ -167,5 +167,6 @@ declare interface Window { startRemoteSync: () => Promise; openUrl: (url: string) => Promise; getPreferredAppLanguage: () => Promise>; + syncManually: () => Promise; }; } diff --git a/src/apps/main/preload.js b/src/apps/main/preload.js index e988efa87..6c1475885 100644 --- a/src/apps/main/preload.js +++ b/src/apps/main/preload.js @@ -296,5 +296,8 @@ contextBridge.exposeInMainWorld('electron', { getPreferredAppLanguage() { return ipcRenderer.invoke('APP:PREFERRED_LANGUAGE'); }, + syncManually() { + return ipcRenderer.invoke('SYNC_MANUALLY'); + }, path, }); diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index 81987e0c2..b95ce6522 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -83,6 +83,11 @@ export async function updateRemoteSync(): Promise { updateSyncEngine(); } +ipcMain.handle('SYNC_MANUALLY', async () => { + Logger.info('[Manual Sync] Received manual sync event'); + await updateRemoteSync(); +}); + eventBus.on('RECEIVED_REMOTE_CHANGES', async () => { // Wait before checking for updates, could be possible // that we received the notification, but if we check diff --git a/src/apps/renderer/pages/Widget/Header.tsx b/src/apps/renderer/pages/Widget/Header.tsx index cbd2525cd..f50a632fa 100644 --- a/src/apps/renderer/pages/Widget/Header.tsx +++ b/src/apps/renderer/pages/Widget/Header.tsx @@ -45,6 +45,10 @@ export default function Header() { window.electron.quit(); } + function onSyncClick() { + window.electron.syncManually(); + } + const handleOpenURL = async (URL: string) => { try { await window.electron.openUrl(URL); @@ -198,10 +202,7 @@ export default function Header() { {({ active }) => (
- window.electron.openSettingsWindow()} - > + {translate('widget.header.dropdown.sync')}
From b2bde01bdda803201d297a5882b64d731dc15847 Mon Sep 17 00:00:00 2001 From: migueldev01 Date: Mon, 25 Mar 2024 16:47:19 -0500 Subject: [PATCH 03/11] feat: fallback sync implemented on manual sync --- src/apps/main/background-processes/sync-engine.ts | 8 ++++++++ src/apps/main/remote-sync/handlers.ts | 10 +++++++++- src/apps/sync-engine/BindingManager.ts | 3 ++- src/apps/sync-engine/index.ts | 8 ++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/apps/main/background-processes/sync-engine.ts b/src/apps/main/background-processes/sync-engine.ts index 122d927c5..f8d85fada 100644 --- a/src/apps/main/background-processes/sync-engine.ts +++ b/src/apps/main/background-processes/sync-engine.ts @@ -218,6 +218,14 @@ export function updateSyncEngine() { } } +export function fallbackSyncEngine() { + try { + worker?.webContents.send('FALLBACK_SYNC_ENGINE_PROCESS'); + } catch (err) { + Logger.error(err); + } +} + eventBus.on('USER_LOGGED_OUT', stopAndClearSyncEngineWatcher); eventBus.on('USER_WAS_UNAUTHORIZED', stopAndClearSyncEngineWatcher); eventBus.on('INITIAL_SYNC_READY', spawnSyncEngineWorker); diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index b95ce6522..ab1ef1947 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -9,7 +9,10 @@ import { ipcMain } from 'electron'; import { reportError } from '../bug-report/service'; import { sleep } from '../util'; import { broadcastToWindows } from '../windows'; -import { updateSyncEngine } from '../background-processes/sync-engine'; +import { + updateSyncEngine, + fallbackSyncEngine, +} from '../background-processes/sync-engine'; let initialSyncReady = false; const driveFilesCollection = new DriveFilesCollection(); @@ -82,10 +85,15 @@ export async function updateRemoteSync(): Promise { await remoteSyncManager.startRemoteSync(); updateSyncEngine(); } +export async function fallbackRemoteSync(): Promise { + await sleep(2_000); + fallbackSyncEngine(); +} ipcMain.handle('SYNC_MANUALLY', async () => { Logger.info('[Manual Sync] Received manual sync event'); await updateRemoteSync(); + await fallbackRemoteSync(); }); eventBus.on('RECEIVED_REMOTE_CHANGES', async () => { diff --git a/src/apps/sync-engine/BindingManager.ts b/src/apps/sync-engine/BindingManager.ts index 503b8690a..bb766ed12 100644 --- a/src/apps/sync-engine/BindingManager.ts +++ b/src/apps/sync-engine/BindingManager.ts @@ -325,13 +325,14 @@ export class BindingsManager { return this.container.pollingMonitorStart.run(this.polling.bind(this)); } - private async polling(): Promise { + async polling(): Promise { try { Logger.info('[SYNC ENGINE] Monitoring polling...'); const fileInPendingPaths = (await this.container.virtualDrive.getPlaceholderWithStatePending()) as Array; Logger.info('[SYNC ENGINE] fileInPendingPaths', fileInPendingPaths); + await this.container.fileSyncOrchestrator.run(fileInPendingPaths); ipcRenderer.send('CHECK_SYNC'); } catch (error) { diff --git a/src/apps/sync-engine/index.ts b/src/apps/sync-engine/index.ts index dfd5d9fb6..1d80d1947 100644 --- a/src/apps/sync-engine/index.ts +++ b/src/apps/sync-engine/index.ts @@ -57,6 +57,14 @@ async function setUp() { Logger.info('[SYNC ENGINE] sync engine updated successfully'); }); + ipcRenderer.on('FALLBACK_SYNC_ENGINE_PROCESS', async () => { + Logger.info('[SYNC ENGINE] Fallback sync engine'); + + await bindings.polling(); + + Logger.info('[SYNC ENGINE] sync engine fallback successfully'); + }); + ipcRenderer.on('STOP_AND_CLEAR_SYNC_ENGINE_PROCESS', async (event) => { Logger.info('[SYNC ENGINE] Stopping and clearing sync engine'); From 7bbac3757a063fe5d8a23a9e6c056372319b3143 Mon Sep 17 00:00:00 2001 From: migueldev01 Date: Wed, 27 Mar 2024 15:45:40 -0500 Subject: [PATCH 04/11] wip: * add handle to receive get sync status * add check sync status on fallback --- src/apps/main/remote-sync/handlers.ts | 12 +++++++----- src/apps/sync-engine/BindingManager.ts | 1 + .../shared/application/PollingMonitorStart.ts | 15 ++++++++++++++- .../shared/domain/PollingMonitor.ts | 18 ++++++++++++++---- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index ab1ef1947..6d0c6b76a 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -2,7 +2,7 @@ import eventBus from '../event-bus'; import { RemoteSyncManager } from './RemoteSyncManager'; import { DriveFilesCollection } from '../database/collections/DriveFileCollection'; import { DriveFoldersCollection } from '../database/collections/DriveFolderCollection'; -import { clearRemoteSyncStore } from './helpers'; +import { clearRemoteSyncStore, RemoteSyncStatus } from './helpers'; import { getNewTokenClient } from '../../shared/HttpClient/main-process-client'; import Logger from 'electron-log'; import { ipcMain } from 'electron'; @@ -120,10 +120,7 @@ eventBus.on('USER_LOGGED_OUT', () => { ipcMain.on('CHECK_SYNC', (event) => { Logger.info('Checking sync'); - event.sender.send( - 'CHECK_SYNC_ENGINE_RESPONSE', - 'Dato obtenido del proceso de sincronización' - ); + event.sender.send('CHECK_SYNC_ENGINE_RESPONSE', ''); }); ipcMain.on('CHECK_SYNC_CHANGE_STATUS', async (_, placeholderStates) => { @@ -133,3 +130,8 @@ ipcMain.on('CHECK_SYNC_CHANGE_STATUS', async (_, placeholderStates) => { await sleep(7_00); remoteSyncManager.placeholderStatus = placeholderStates; }); + +ipcMain.handle('CHECK_SYNC_IN_PROGRESS', async () => { + const syncingStatus: RemoteSyncStatus = 'SYNCING'; + return remoteSyncManager.getSyncStatus() === syncingStatus; +}); diff --git a/src/apps/sync-engine/BindingManager.ts b/src/apps/sync-engine/BindingManager.ts index bb766ed12..331030d65 100644 --- a/src/apps/sync-engine/BindingManager.ts +++ b/src/apps/sync-engine/BindingManager.ts @@ -322,6 +322,7 @@ export class BindingsManager { } private async pollingStart() { + Logger.debug('[SYNC ENGINE] Starting polling'); return this.container.pollingMonitorStart.run(this.polling.bind(this)); } diff --git a/src/context/virtual-drive/shared/application/PollingMonitorStart.ts b/src/context/virtual-drive/shared/application/PollingMonitorStart.ts index 6c0f2918c..82ff9ca94 100644 --- a/src/context/virtual-drive/shared/application/PollingMonitorStart.ts +++ b/src/context/virtual-drive/shared/application/PollingMonitorStart.ts @@ -1,8 +1,21 @@ import { MonitorFn, PollingMonitor } from '../domain/PollingMonitor'; +import { ipcRenderer } from 'electron'; +import Logger from 'electron-log'; export class PollingMonitorStart { constructor(private readonly polling: PollingMonitor) {} run(fn: MonitorFn) { - return this.polling.start(fn); + Logger.info('[SYNC ENGINE] check sync engine'); + + const permission = this.permissionFn.bind(this); + return this.polling.start(fn, permission); + } + + private async permissionFn() { + const isSyncing = await ipcRenderer.invoke('CHECK_SYNC_IN_PROGRESS'); + Logger.info('[SYNC ENGINE] is syncing', isSyncing); + + const isPermitted = !isSyncing; + return isPermitted; } } diff --git a/src/context/virtual-drive/shared/domain/PollingMonitor.ts b/src/context/virtual-drive/shared/domain/PollingMonitor.ts index ef232677a..3972e566c 100644 --- a/src/context/virtual-drive/shared/domain/PollingMonitor.ts +++ b/src/context/virtual-drive/shared/domain/PollingMonitor.ts @@ -1,4 +1,5 @@ export type MonitorFn = () => Promise; +export type PermissionFn = () => Promise; export class PollingMonitor { constructor(private readonly delay: number) {} @@ -11,16 +12,25 @@ export class PollingMonitor { } } - private setTimeout(fn: MonitorFn) { + private setTimeout(fn: MonitorFn, permissionFn: PermissionFn) { this.clearTimeout(); this.timeout = setTimeout(async () => { + if (!(await permissionFn())) { + // wait for the next interval + this.repeatDelay(fn, permissionFn); + return; + } await fn(); - this.setTimeout(fn); + this.repeatDelay(fn, permissionFn); }, this.delay); } - start(fn: MonitorFn) { - this.setTimeout(fn); + private repeatDelay(fn: MonitorFn, runPermissionFn: PermissionFn) { + this.setTimeout(fn, runPermissionFn); + } + + start(fn: MonitorFn, runPermissionFn: PermissionFn) { + this.setTimeout(fn, runPermissionFn); } stop() { From ad413322385fab55034c19a83dfb876c78ae4416 Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 29 Mar 2024 15:56:19 -0500 Subject: [PATCH 05/11] wip: change variable name - renamed to understand the flow of this logic --- .../files/application/FileCheckerStatusInRoot.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/context/virtual-drive/files/application/FileCheckerStatusInRoot.ts b/src/context/virtual-drive/files/application/FileCheckerStatusInRoot.ts index 80a10a329..3d4e66c62 100644 --- a/src/context/virtual-drive/files/application/FileCheckerStatusInRoot.ts +++ b/src/context/virtual-drive/files/application/FileCheckerStatusInRoot.ts @@ -27,16 +27,16 @@ export class FileCheckerStatusInRoot { const ps = placeholderStatus.pinState; const ss = placeholderStatus.syncState; - const status = + const notSynced = ps && ss && ps !== PinState.AlwaysLocal && ps !== PinState.OnlineOnly && ss !== SyncState.InSync; - if (status) { + if (notSynced) { Logger.debug( - `[File Checker Status In Root] item ${path} with status: ${status}` + `[File Checker Status In Root] item ${path} with status: ${notSynced}` ); finalStatus = 'SYNC_PENDING'; break; From 1c8b3cb7cbb0c8fb131e2c0016e30a6eaf8c1c7d Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 29 Mar 2024 17:41:46 -0500 Subject: [PATCH 06/11] feat: add last syncing timestamp - not allowed run fallback when recently was syncing - add time to wating for syncing --- .../main/remote-sync/RemoteSyncManager.ts | 25 +++++++++++++++++++ src/apps/main/remote-sync/handlers.ts | 10 ++++---- src/apps/main/remote-sync/helpers.ts | 1 + .../shared/application/PollingMonitorStart.ts | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/apps/main/remote-sync/RemoteSyncManager.ts b/src/apps/main/remote-sync/RemoteSyncManager.ts index 049056eeb..e8b4498dc 100644 --- a/src/apps/main/remote-sync/RemoteSyncManager.ts +++ b/src/apps/main/remote-sync/RemoteSyncManager.ts @@ -6,6 +6,7 @@ import { RemoteSyncedFile, SyncConfig, SYNC_OFFSET_MS, + WAITING_AFTER_SYNCING } from './helpers'; import { reportError } from '../bug-report/service'; @@ -24,6 +25,8 @@ export class RemoteSyncManager { > = []; private totalFilesSynced = 0; private totalFoldersSynced = 0; + private lastSyncingFinishedTimestamp: Date | null = null; + constructor( private db: { files: DatabaseCollectionAdapter; @@ -50,6 +53,9 @@ export class RemoteSyncManager { getSyncStatus(): RemoteSyncStatus { return this.status; } + getLastSyncingFinishedTimestamp() { + return this.lastSyncingFinishedTimestamp; + } /** * Check if the RemoteSyncManager is in SYNCED status @@ -60,10 +66,22 @@ export class RemoteSyncManager { return this.status === 'SYNCED'; } + /** + * Consult if recently the RemoteSyncManager was syncing + * @returns True if the RemoteSyncManager was syncing recently + * @returns False if the RemoteSyncManager was not syncing recently + */ + recentlyWasSyncing() { + const passedTime = Date.now() - (this.getLastSyncingFinishedTimestamp()?.getTime() || Date.now() ); + return passedTime < WAITING_AFTER_SYNCING; + } + resetRemoteSync() { this.changeStatus('IDLE'); this.filesSyncStatus = 'IDLE'; this.foldersSyncStatus = 'IDLE'; + this._placeholdersStatus = 'IDLE'; + this.lastSyncingFinishedTimestamp = null; this.totalFilesSynced = 0; this.totalFoldersSynced = 0; } @@ -148,6 +166,7 @@ export class RemoteSyncManager { return true; } private changeStatus(newStatus: RemoteSyncStatus) { + this.addLastSyncingFinishedTimestamp(); if (newStatus === this.status) return; Logger.info(`RemoteSyncManager ${this.status} -> ${newStatus}`); this.status = newStatus; @@ -157,6 +176,12 @@ export class RemoteSyncManager { }); } + private addLastSyncingFinishedTimestamp() { + if (this.status !== 'SYNCING') return; + Logger.info('Adding last syncing finished timestamp'); + this.lastSyncingFinishedTimestamp = new Date(); + } + private checkRemoteSyncStatus() { if (this._placeholdersStatus === 'SYNCING') { this.changeStatus('SYNCING'); diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index 6d0c6b76a..1f42e1d5e 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -124,14 +124,14 @@ ipcMain.on('CHECK_SYNC', (event) => { }); ipcMain.on('CHECK_SYNC_CHANGE_STATUS', async (_, placeholderStates) => { - await sleep(2_000); - Logger.info('[SYNC ENGINE] Changing status'); - remoteSyncManager.placeholderStatus = 'SYNCING'; - await sleep(7_00); + Logger.info('[SYNC ENGINE] Changing status', placeholderStates); + await sleep(5_00); remoteSyncManager.placeholderStatus = placeholderStates; }); ipcMain.handle('CHECK_SYNC_IN_PROGRESS', async () => { const syncingStatus: RemoteSyncStatus = 'SYNCING'; - return remoteSyncManager.getSyncStatus() === syncingStatus; + const isSyncing = remoteSyncManager.getSyncStatus() === syncingStatus; + const recentlySyncing = remoteSyncManager.recentlyWasSyncing(); + return isSyncing || recentlySyncing; // If it's syncing or recently was syncing }); diff --git a/src/apps/main/remote-sync/helpers.ts b/src/apps/main/remote-sync/helpers.ts index ee6b1fa30..4ad0a546b 100644 --- a/src/apps/main/remote-sync/helpers.ts +++ b/src/apps/main/remote-sync/helpers.ts @@ -99,6 +99,7 @@ export type SyncConfig = { }; export const SYNC_OFFSET_MS = 0; +export const WAITING_AFTER_SYNCING = 1000 * 60 * 3; // 5 minutes export const lastSyncedAtIsNewer = ( itemUpdatedAt: Date, diff --git a/src/context/virtual-drive/shared/application/PollingMonitorStart.ts b/src/context/virtual-drive/shared/application/PollingMonitorStart.ts index 82ff9ca94..ba33be8be 100644 --- a/src/context/virtual-drive/shared/application/PollingMonitorStart.ts +++ b/src/context/virtual-drive/shared/application/PollingMonitorStart.ts @@ -13,7 +13,7 @@ export class PollingMonitorStart { private async permissionFn() { const isSyncing = await ipcRenderer.invoke('CHECK_SYNC_IN_PROGRESS'); - Logger.info('[SYNC ENGINE] is syncing', isSyncing); + Logger.info('[SYNC ENGINE] Not permitted to start fallback sync: ', isSyncing); const isPermitted = !isSyncing; return isPermitted; From 82615b5de7b8c2db56db5cebbb26cd40a179f56c Mon Sep 17 00:00:00 2001 From: miguel Date: Mon, 1 Apr 2024 17:32:01 -0500 Subject: [PATCH 07/11] feat: permission to use sync - add contiion it is not allowed when recently was syncing - add syncing recently by three minutes --- src/apps/main/preload.d.ts | 1 + src/apps/main/preload.js | 4 ++++ src/apps/main/remote-sync/helpers.ts | 2 +- src/apps/renderer/pages/Widget/Header.tsx | 24 ++++++++++++++----- .../shared/application/PollingMonitorStart.ts | 4 ++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/apps/main/preload.d.ts b/src/apps/main/preload.d.ts index 6ea2ee4a0..63c33789c 100644 --- a/src/apps/main/preload.d.ts +++ b/src/apps/main/preload.d.ts @@ -168,5 +168,6 @@ declare interface Window { openUrl: (url: string) => Promise; getPreferredAppLanguage: () => Promise>; syncManually: () => Promise; + getRecentlywasSyncing: () => Promise; }; } diff --git a/src/apps/main/preload.js b/src/apps/main/preload.js index 6c1475885..7c6c6436d 100644 --- a/src/apps/main/preload.js +++ b/src/apps/main/preload.js @@ -299,5 +299,9 @@ contextBridge.exposeInMainWorld('electron', { syncManually() { return ipcRenderer.invoke('SYNC_MANUALLY'); }, + getRecentlywasSyncing() { + return ipcRenderer.invoke('CHECK_SYNC_IN_PROGRESS'); + }, + path, }); diff --git a/src/apps/main/remote-sync/helpers.ts b/src/apps/main/remote-sync/helpers.ts index 4ad0a546b..e35c0a6e1 100644 --- a/src/apps/main/remote-sync/helpers.ts +++ b/src/apps/main/remote-sync/helpers.ts @@ -99,7 +99,7 @@ export type SyncConfig = { }; export const SYNC_OFFSET_MS = 0; -export const WAITING_AFTER_SYNCING = 1000 * 60 * 3; // 5 minutes +export const WAITING_AFTER_SYNCING = 1000 * 60 * 3; export const lastSyncedAtIsNewer = ( itemUpdatedAt: Date, diff --git a/src/apps/renderer/pages/Widget/Header.tsx b/src/apps/renderer/pages/Widget/Header.tsx index f50a632fa..3f7be266b 100644 --- a/src/apps/renderer/pages/Widget/Header.tsx +++ b/src/apps/renderer/pages/Widget/Header.tsx @@ -12,6 +12,7 @@ import useUsage from '../../hooks/useUsage'; import useVirtualDriveStatus from '../../hooks/VirtualDriveStatus'; import { reportError } from '../../utils/errors'; + export default function Header() { const { translate } = useTranslationContext(); const { virtualDriveCanBeOpened } = useVirtualDriveStatus(); @@ -45,10 +46,19 @@ export default function Header() { window.electron.quit(); } - function onSyncClick() { + const wasSyncing = () => { + return window.electron.getRecentlywasSyncing(); + }; + + async function onSyncClick() { + const notAllowed = await wasSyncing(); + if (notAllowed) { + return; + } window.electron.syncManually(); } + const handleOpenURL = async (URL: string) => { try { await window.electron.openUrl(URL); @@ -200,13 +210,15 @@ export default function Header() { )}
- {({ active }) => ( -
- + {({active}) => { + + return (
+ {translate('widget.header.dropdown.sync')} -
- )} +
); + } + }
{({ active }) => ( diff --git a/src/context/virtual-drive/shared/application/PollingMonitorStart.ts b/src/context/virtual-drive/shared/application/PollingMonitorStart.ts index ba33be8be..5cef0729d 100644 --- a/src/context/virtual-drive/shared/application/PollingMonitorStart.ts +++ b/src/context/virtual-drive/shared/application/PollingMonitorStart.ts @@ -5,7 +5,7 @@ import Logger from 'electron-log'; export class PollingMonitorStart { constructor(private readonly polling: PollingMonitor) {} run(fn: MonitorFn) { - Logger.info('[SYNC ENGINE] check sync engine'); + Logger.info('[START FALLBAK] Starting fallback sync...'); const permission = this.permissionFn.bind(this); return this.polling.start(fn, permission); @@ -13,7 +13,7 @@ export class PollingMonitorStart { private async permissionFn() { const isSyncing = await ipcRenderer.invoke('CHECK_SYNC_IN_PROGRESS'); - Logger.info('[SYNC ENGINE] Not permitted to start fallback sync: ', isSyncing); + Logger.info('[START FALLBAK] Not permitted to start fallback sync: ', isSyncing); const isPermitted = !isSyncing; return isPermitted; From fe879cf6d6aa1ffb8bd694ef3d698f1c1107002c Mon Sep 17 00:00:00 2001 From: miguel Date: Tue, 2 Apr 2024 08:33:36 -0500 Subject: [PATCH 08/11] fix: changing || --- src/apps/main/remote-sync/RemoteSyncManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/main/remote-sync/RemoteSyncManager.ts b/src/apps/main/remote-sync/RemoteSyncManager.ts index e8b4498dc..8fd4f13e8 100644 --- a/src/apps/main/remote-sync/RemoteSyncManager.ts +++ b/src/apps/main/remote-sync/RemoteSyncManager.ts @@ -72,7 +72,7 @@ export class RemoteSyncManager { * @returns False if the RemoteSyncManager was not syncing recently */ recentlyWasSyncing() { - const passedTime = Date.now() - (this.getLastSyncingFinishedTimestamp()?.getTime() || Date.now() ); + const passedTime = Date.now() - ( this.getLastSyncingFinishedTimestamp()?.getTime() ?? Date.now() ); return passedTime < WAITING_AFTER_SYNCING; } From 20eb78b1fa45d6cef519419fb9a6b3229b98bd1e Mon Sep 17 00:00:00 2001 From: miguel Date: Tue, 2 Apr 2024 10:19:56 -0500 Subject: [PATCH 09/11] fix: typo solved --- src/apps/main/remote-sync/RemoteSyncManager.ts | 4 +++- src/apps/main/remote-sync/handlers.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/apps/main/remote-sync/RemoteSyncManager.ts b/src/apps/main/remote-sync/RemoteSyncManager.ts index 8fd4f13e8..3e46504f9 100644 --- a/src/apps/main/remote-sync/RemoteSyncManager.ts +++ b/src/apps/main/remote-sync/RemoteSyncManager.ts @@ -50,10 +50,12 @@ export class RemoteSyncManager { if (typeof callback !== 'function') return; this.onStatusChangeCallbacks.push(callback); } + getSyncStatus(): RemoteSyncStatus { return this.status; } - getLastSyncingFinishedTimestamp() { + + private getLastSyncingFinishedTimestamp() { return this.lastSyncingFinishedTimestamp; } diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index 1f42e1d5e..77621ad10 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -125,7 +125,7 @@ ipcMain.on('CHECK_SYNC', (event) => { ipcMain.on('CHECK_SYNC_CHANGE_STATUS', async (_, placeholderStates) => { Logger.info('[SYNC ENGINE] Changing status', placeholderStates); - await sleep(5_00); + await sleep(5_000); remoteSyncManager.placeholderStatus = placeholderStates; }); From 664a95b0ac32407d7ce829c54cb74e9c7d6fc5e3 Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 3 Apr 2024 16:47:55 -0500 Subject: [PATCH 10/11] modify comments --- src/apps/main/remote-sync/handlers.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index ab1ef1947..c0d4940cc 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -81,6 +81,9 @@ ipcMain.handle('get-remote-sync-status', () => ); export async function updateRemoteSync(): Promise { + // Wait before checking for updates, could be possible + // that we received the notification, but if we check + // for new data we don't receive it await sleep(2_000); await remoteSyncManager.startRemoteSync(); updateSyncEngine(); @@ -97,9 +100,6 @@ ipcMain.handle('SYNC_MANUALLY', async () => { }); eventBus.on('RECEIVED_REMOTE_CHANGES', async () => { - // Wait before checking for updates, could be possible - // that we received the notification, but if we check - // for new data we don't receive it await updateRemoteSync(); }); From cad1cc3e15125a1e8e74c4f9a23008222483ea10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Gonz=C3=A1lez?= Date: Fri, 5 Apr 2024 10:46:34 -0400 Subject: [PATCH 11/11] feat: run fallback syncronizer after start --- src/apps/sync-engine/BindingManager.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/apps/sync-engine/BindingManager.ts b/src/apps/sync-engine/BindingManager.ts index 331030d65..a66fc1f35 100644 --- a/src/apps/sync-engine/BindingManager.ts +++ b/src/apps/sync-engine/BindingManager.ts @@ -244,6 +244,8 @@ export class BindingsManager { await this.container.virtualDrive.connectSyncRoot(); await this.load(); + + await this.polling(); } watch() {