From d76e0b8aab1efecd10fc1fc98dfcf594fd2f93d1 Mon Sep 17 00:00:00 2001 From: migueldev01 Date: Thu, 21 Mar 2024 14:47:25 -0500 Subject: [PATCH 01/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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 da89c1bac77a43a2d498b85a6bb31ad284fad1b1 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Fri, 5 Apr 2024 13:37:51 +0200 Subject: [PATCH 11/20] fix: close any instance that does not have the lock --- src/apps/main/main.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/apps/main/main.ts b/src/apps/main/main.ts index 1b3e9d76f..a2a2f468c 100644 --- a/src/apps/main/main.ts +++ b/src/apps/main/main.ts @@ -54,6 +54,12 @@ import { setCleanUpFunction } from './quit'; import { stopSyncEngineWatcher } from './background-processes/sync-engine'; import { Theme } from '../shared/types/Theme'; +const gotTheLock = app.requestSingleInstanceLock(); + +if (!gotTheLock) { + app.quit(); +} + Logger.log(`Running ${packageJson.version}`); Logger.log('Initializing Sentry for main process'); From ea697177950418aba0f8d824b7206658b65a266f Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 10 Apr 2024 13:45:56 -0500 Subject: [PATCH 12/20] feat: add secods to wait for sync manual --- src/apps/main/preload.js | 3 ++- src/apps/main/remote-sync/RemoteSyncManager.ts | 7 ++++--- src/apps/main/remote-sync/handlers.ts | 6 +++--- src/apps/main/remote-sync/helpers.ts | 2 +- .../shared/application/PollingMonitorStart.ts | 1 - 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/apps/main/preload.js b/src/apps/main/preload.js index 7c6c6436d..5e4336e9d 100644 --- a/src/apps/main/preload.js +++ b/src/apps/main/preload.js @@ -300,7 +300,8 @@ contextBridge.exposeInMainWorld('electron', { return ipcRenderer.invoke('SYNC_MANUALLY'); }, getRecentlywasSyncing() { - return ipcRenderer.invoke('CHECK_SYNC_IN_PROGRESS'); + const FIVE_SECONDS = 5000; + return ipcRenderer.invoke('CHECK_SYNC_IN_PROGRESS', FIVE_SECONDS); }, path, diff --git a/src/apps/main/remote-sync/RemoteSyncManager.ts b/src/apps/main/remote-sync/RemoteSyncManager.ts index 3e46504f9..07e6030f5 100644 --- a/src/apps/main/remote-sync/RemoteSyncManager.ts +++ b/src/apps/main/remote-sync/RemoteSyncManager.ts @@ -6,7 +6,7 @@ import { RemoteSyncedFile, SyncConfig, SYNC_OFFSET_MS, - WAITING_AFTER_SYNCING + WAITING_AFTER_SYNCING_DEFAULT } from './helpers'; import { reportError } from '../bug-report/service'; @@ -72,10 +72,11 @@ export class RemoteSyncManager { * Consult if recently the RemoteSyncManager was syncing * @returns True if the RemoteSyncManager was syncing recently * @returns False if the RemoteSyncManager was not syncing recently + * @param milliseconds Time in milliseconds to check if the RemoteSyncManager was syncing */ - recentlyWasSyncing() { + recentlyWasSyncing( milliseconds: number) { const passedTime = Date.now() - ( this.getLastSyncingFinishedTimestamp()?.getTime() ?? Date.now() ); - return passedTime < WAITING_AFTER_SYNCING; + return passedTime < ( milliseconds ?? WAITING_AFTER_SYNCING_DEFAULT ); } resetRemoteSync() { diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index 9dc854c67..05f73dfdc 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -129,9 +129,9 @@ ipcMain.on('CHECK_SYNC_CHANGE_STATUS', async (_, placeholderStates) => { remoteSyncManager.placeholderStatus = placeholderStates; }); -ipcMain.handle('CHECK_SYNC_IN_PROGRESS', async () => { +ipcMain.handle('CHECK_SYNC_IN_PROGRESS', async (_, milliSeconds : number) => { const syncingStatus: RemoteSyncStatus = 'SYNCING'; const isSyncing = remoteSyncManager.getSyncStatus() === syncingStatus; - const recentlySyncing = remoteSyncManager.recentlyWasSyncing(); - return isSyncing || recentlySyncing; // If it's syncing or recently was syncing + const recentlySyncing = remoteSyncManager.recentlyWasSyncing(milliSeconds); + return isSyncing || recentlySyncing; // syncing or recently was syncing }); diff --git a/src/apps/main/remote-sync/helpers.ts b/src/apps/main/remote-sync/helpers.ts index e35c0a6e1..128f447d9 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; +export const WAITING_AFTER_SYNCING_DEFAULT = 1000 * 60 * 3; 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 5cef0729d..c4c3449bb 100644 --- a/src/context/virtual-drive/shared/application/PollingMonitorStart.ts +++ b/src/context/virtual-drive/shared/application/PollingMonitorStart.ts @@ -14,7 +14,6 @@ export class PollingMonitorStart { private async permissionFn() { const isSyncing = await ipcRenderer.invoke('CHECK_SYNC_IN_PROGRESS'); Logger.info('[START FALLBAK] Not permitted to start fallback sync: ', isSyncing); - const isPermitted = !isSyncing; return isPermitted; } From adfa3d0393d4c4756342bbfe599d10cecccc1bca Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 10 Apr 2024 13:49:19 -0500 Subject: [PATCH 13/20] feat: add running sync fallback - fallback running app - fallback login app - fallback health check app --- 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() { From 5b1c6228610363ac9813d929688126c2dc74ab6f Mon Sep 17 00:00:00 2001 From: miguel Date: Thu, 11 Apr 2024 11:10:14 -0500 Subject: [PATCH 14/20] fix: force starting engine --- .../main/background-processes/sync-engine.ts | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/apps/main/background-processes/sync-engine.ts b/src/apps/main/background-processes/sync-engine.ts index f8d85fada..53a3b0e94 100644 --- a/src/apps/main/background-processes/sync-engine.ts +++ b/src/apps/main/background-processes/sync-engine.ts @@ -8,6 +8,19 @@ let worker: BrowserWindow | null = null; let workerIsRunning = false; let startingWorker = false; let healthCheckSchedule: nodeSchedule.Job | null = null; +let attemptsAlreadyStarting = 0; + +ipcMain.once('SYNC_ENGINE_PROCESS_SETUP_SUCCESSFUL', () => { + Logger.debug('[MAIN] SYNC ENGINE RUNNING'); + workerIsRunning = true; + startingWorker = false; +}); + +ipcMain.on('SYNC_ENGINE_PROCESS_SETUP_FAILED', () => { + Logger.debug('[MAIN] SYNC ENGINE FAILED'); + workerIsRunning = false; + startingWorker = false; +}); async function healthCheck() { const responsePromise = new Promise((resolve, reject) => { @@ -45,6 +58,11 @@ function scheduleHeathCheck() { Logger.warn('Health check failed, relaunching the worker'); workerIsRunning = false; worker?.destroy(); + if (attemptsAlreadyStarting >= 3) { + attemptsAlreadyStarting = 0; + startingWorker = false; + return; + } spawnSyncEngineWorker(); }); @@ -56,6 +74,7 @@ function scheduleHeathCheck() { function spawnSyncEngineWorker() { if (startingWorker) { Logger.info('[MAIN] Worker is already starting'); + attemptsAlreadyStarting++; return; } if (workerIsRunning) { @@ -96,18 +115,6 @@ function spawnSyncEngineWorker() { spawnSyncEngineWorker(); } }); - - ipcMain.once('SYNC_ENGINE_PROCESS_SETUP_SUCCESSFUL', () => { - Logger.debug('[MAIN] SYNC ENGINE RUNNING'); - workerIsRunning = true; - startingWorker = false; - }); - - ipcMain.on('SYNC_ENGINE_PROCESS_SETUP_FAILED', () => { - Logger.debug('[MAIN] SYNC ENGINE NOT RUNNING'); - workerIsRunning = false; - startingWorker = false; - }); } export async function stopSyncEngineWatcher() { @@ -211,7 +218,9 @@ async function stopAndClearSyncEngineWatcher() { export function updateSyncEngine() { try { - worker?.webContents.send('UPDATE_SYNC_ENGINE_PROCESS'); + if ( worker && worker?.webContents && !worker.isDestroyed() ) { + worker?.webContents.send('UPDATE_SYNC_ENGINE_PROCESS'); + } } catch (err) { // TODO: handle error Logger.error(err); @@ -220,7 +229,9 @@ export function updateSyncEngine() { export function fallbackSyncEngine() { try { - worker?.webContents.send('FALLBACK_SYNC_ENGINE_PROCESS'); + if ( worker && worker?.webContents && !worker.isDestroyed() ) { + worker?.webContents.send('FALLBACK_SYNC_ENGINE_PROCESS'); + } } catch (err) { Logger.error(err); } From 4ea607a6d6ae532a61fbbff9ff990e530b399e6e Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 17 Apr 2024 10:47:23 -0500 Subject: [PATCH 15/20] add version 8 --- package.json | 2 +- release/app/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0643150e4..94a3a92b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "internxt-drive", - "version": "2.0.7", + "version": "2.0.8", "author": "Internxt ", "description": "Internxt Drive client UI", "license": "AGPL-3.0", diff --git a/release/app/package.json b/release/app/package.json index 7e869261d..a811ff997 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -1,6 +1,6 @@ { "name": "internxt-drive", - "version": "2.0.7", + "version": "2.0.8", "description": "Internxt Drive client UI", "main": "./dist/main/main.js", "author": "Internxt ", From ac98a9b597f724f010809c670015637d437ad32b Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 17 Apr 2024 10:51:35 -0500 Subject: [PATCH 16/20] update version --- package.json | 2 +- release/app/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 94a3a92b4..0643150e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "internxt-drive", - "version": "2.0.8", + "version": "2.0.7", "author": "Internxt ", "description": "Internxt Drive client UI", "license": "AGPL-3.0", diff --git a/release/app/package.json b/release/app/package.json index a811ff997..7e869261d 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -1,6 +1,6 @@ { "name": "internxt-drive", - "version": "2.0.8", + "version": "2.0.7", "description": "Internxt Drive client UI", "main": "./dist/main/main.js", "author": "Internxt ", From 32b09b72744ae3144d533fc21430fcef2ae867c5 Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 17 Apr 2024 10:51:58 -0500 Subject: [PATCH 17/20] update version 8 --- package.json | 2 +- release/app/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0643150e4..94a3a92b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "internxt-drive", - "version": "2.0.7", + "version": "2.0.8", "author": "Internxt ", "description": "Internxt Drive client UI", "license": "AGPL-3.0", diff --git a/release/app/package.json b/release/app/package.json index 7e869261d..a811ff997 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -1,6 +1,6 @@ { "name": "internxt-drive", - "version": "2.0.7", + "version": "2.0.8", "description": "Internxt Drive client UI", "main": "./dist/main/main.js", "author": "Internxt ", From f1bba7b191cf2b589b41c72b5551d504b0d0c1d3 Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 5 Apr 2024 11:30:57 -0500 Subject: [PATCH 18/20] wip: add fileIdentityUpdater - add updateIdentity of nodewin - add updateIdentity to update content --- .../dependency-injection/files/FilesContainer.ts | 2 ++ .../sync-engine/dependency-injection/files/builder.ts | 5 +++++ .../files/application/FileIndetityUpdater.ts | 10 ++++++++++ .../virtual-drive/files/application/FileSyncronizer.ts | 3 +++ .../files/domain/file-systems/LocalFileSystem.ts | 5 +++++ .../files/infrastructure/NodeWinLocalFileSystem.ts | 7 ++++++- 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/context/virtual-drive/files/application/FileIndetityUpdater.ts diff --git a/src/apps/sync-engine/dependency-injection/files/FilesContainer.ts b/src/apps/sync-engine/dependency-injection/files/FilesContainer.ts index 06359dc19..c692474e1 100644 --- a/src/apps/sync-engine/dependency-injection/files/FilesContainer.ts +++ b/src/apps/sync-engine/dependency-injection/files/FilesContainer.ts @@ -15,6 +15,7 @@ import { FilePlaceholderConverter } from '../../../../context/virtual-drive/file import { FileSyncStatusUpdater } from '../../../../context/virtual-drive/files/application/FileSyncStatusUpdater'; import { FileCheckerStatusInRoot } from '../../../../context/virtual-drive/files/application/FileCheckerStatusInRoot'; import { FilesPlaceholderDeleter } from '../../../../context/virtual-drive/files/application/FilesPlaceholderDeleter'; +import { FileIdentityUpdater } from '../../../../context/virtual-drive/files/application/FileIndetityUpdater'; export interface FilesContainer { fileFinderByContentsId: FileFinderByContentsId; @@ -34,4 +35,5 @@ export interface FilesContainer { filePlaceholderConverter: FilePlaceholderConverter; fileSyncStatusUpdater: FileSyncStatusUpdater; filesCheckerStatusInRoot: FileCheckerStatusInRoot; + fileIdentityUpdater: FileIdentityUpdater; } diff --git a/src/apps/sync-engine/dependency-injection/files/builder.ts b/src/apps/sync-engine/dependency-injection/files/builder.ts index 8a57d6db0..4cebc5297 100644 --- a/src/apps/sync-engine/dependency-injection/files/builder.ts +++ b/src/apps/sync-engine/dependency-injection/files/builder.ts @@ -31,6 +31,7 @@ import { FileSyncStatusUpdater } from '../../../../context/virtual-drive/files/a import { FileContentsUpdater } from '../../../../context/virtual-drive/files/application/FileContentsUpdater'; import { FileCheckerStatusInRoot } from '../../../../context/virtual-drive/files/application/FileCheckerStatusInRoot'; import { FilesPlaceholderDeleter } from '../../../../context/virtual-drive/files/application/FilesPlaceholderDeleter'; +import { FileIdentityUpdater } from '../../../../context/virtual-drive/files/application/FileIndetityUpdater'; export async function buildFilesContainer( folderContainer: FoldersContainer, @@ -144,10 +145,13 @@ export async function buildFilesContainer( remoteFileSystem ); + const fileIdentityUpdater = new FileIdentityUpdater(localFileSystem); + const fileSyncronizer = new FileSyncronizer( repository, fileSyncStatusUpdater, filePlaceholderConverter, + fileIdentityUpdater, fileCreator, sharedContainer.absolutePathToRelativeConverter, folderContainer.folderCreator, @@ -176,6 +180,7 @@ export async function buildFilesContainer( filePlaceholderConverter, fileSyncStatusUpdater, filesCheckerStatusInRoot, + fileIdentityUpdater, }; return { container, subscribers: [] }; diff --git a/src/context/virtual-drive/files/application/FileIndetityUpdater.ts b/src/context/virtual-drive/files/application/FileIndetityUpdater.ts new file mode 100644 index 000000000..6fb40e3c9 --- /dev/null +++ b/src/context/virtual-drive/files/application/FileIndetityUpdater.ts @@ -0,0 +1,10 @@ +import { File } from '../domain/File'; +import { LocalFileSystem } from '../domain/file-systems/LocalFileSystem'; + +export class FileIdentityUpdater { + constructor(private readonly localFileSystem: LocalFileSystem) {} + + async run(file: File) { + await this.localFileSystem.updateFileIdentity(file.path, file.placeholderId); + } +} diff --git a/src/context/virtual-drive/files/application/FileSyncronizer.ts b/src/context/virtual-drive/files/application/FileSyncronizer.ts index 6d97c3124..5ae1ad7d2 100644 --- a/src/context/virtual-drive/files/application/FileSyncronizer.ts +++ b/src/context/virtual-drive/files/application/FileSyncronizer.ts @@ -15,6 +15,7 @@ import { File } from '../domain/File'; import { FileSyncStatusUpdater } from './FileSyncStatusUpdater'; import { FilePlaceholderConverter } from './FIlePlaceholderConverter'; import { FileContentsUpdater } from './FileContentsUpdater'; +import { FileIdentityUpdater } from './FileIndetityUpdater'; export class FileSyncronizer { // queue of files to be uploaded @@ -23,6 +24,7 @@ export class FileSyncronizer { private readonly repository: FileRepository, private readonly fileSyncStatusUpdater: FileSyncStatusUpdater, private readonly filePlaceholderConverter: FilePlaceholderConverter, + private readonly fileIdentityUpdater: FileIdentityUpdater, private readonly fileCreator: FileCreator, private readonly absolutePathToRelativeConverter: AbsolutePathToRelativeConverter, private readonly folderCreator: FolderCreator, @@ -148,6 +150,7 @@ export class FileSyncronizer { private async convertAndUpdateSyncStatus(file: File) { await Promise.all([ this.filePlaceholderConverter.run(file), + this.fileIdentityUpdater.run(file), this.fileSyncStatusUpdater.run(file), ]); } diff --git a/src/context/virtual-drive/files/domain/file-systems/LocalFileSystem.ts b/src/context/virtual-drive/files/domain/file-systems/LocalFileSystem.ts index 7b8145823..84a201134 100644 --- a/src/context/virtual-drive/files/domain/file-systems/LocalFileSystem.ts +++ b/src/context/virtual-drive/files/domain/file-systems/LocalFileSystem.ts @@ -19,4 +19,9 @@ export interface LocalFileSystem { getPlaceholderStateByRelativePath( relativePath: string ): Promise; + + updateFileIdentity( + path: File['path'], + newIdentity: string + ): Promise; } diff --git a/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts b/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts index d656a751f..123082091 100644 --- a/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts +++ b/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts @@ -15,7 +15,7 @@ export class NodeWinLocalFileSystem implements LocalFileSystem { async getLocalFileId(file: File): Promise<`${string}-${string}`> { const win32AbsolutePath = this.relativePathToAbsoluteConverter.run( file.path - ); + ); const { ino, dev } = await fs.stat(win32AbsolutePath); @@ -72,4 +72,9 @@ export class NodeWinLocalFileSystem implements LocalFileSystem { relativePath ) as Promise; } + + async updateFileIdentity(path: string, newIdentity: `${string}-${string}`): Promise { + const isNotDirectory = true; + return this.virtualDrive.updateFileIdentity(path, newIdentity, isNotDirectory); + } } From 01716646ee68c1c59160d21ad059e31dc07902ba Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 17 Apr 2024 11:51:16 -0500 Subject: [PATCH 19/20] add sync on french --- src/apps/renderer/localize/locales/fr.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/apps/renderer/localize/locales/fr.json b/src/apps/renderer/localize/locales/fr.json index f873319a9..0b24c8502 100644 --- a/src/apps/renderer/localize/locales/fr.json +++ b/src/apps/renderer/localize/locales/fr.json @@ -130,6 +130,7 @@ }, "dropdown": { "preferences": "Préférences", + "sync": "Synchroniser", "issues": "Liste d'erreurs", "support": "Aide", "logout": "Déconnecter", From 5b62c84a234b2361c98fb5c05e3b194e64046a14 Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 17 Apr 2024 17:36:06 -0500 Subject: [PATCH 20/20] fix update identity by unsyced file --- .../files/infrastructure/InMemoryFileRepository.ts | 7 +++++-- .../files/infrastructure/NodeWinLocalFileSystem.ts | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/context/virtual-drive/files/infrastructure/InMemoryFileRepository.ts b/src/context/virtual-drive/files/infrastructure/InMemoryFileRepository.ts index 431850df0..966fcf7c7 100644 --- a/src/context/virtual-drive/files/infrastructure/InMemoryFileRepository.ts +++ b/src/context/virtual-drive/files/infrastructure/InMemoryFileRepository.ts @@ -92,10 +92,13 @@ export class InMemoryFileRepository implements FileRepository { if (!this.files.has(file.contentsId)) { throw new Error('File not found'); } - + const oldContentsId = file.contentsId; const updatedFile = file.replaceContestsAndSize(newContentsId, newSize); + // first delete the old file to be able to add the new one + this.files.delete(oldContentsId); this.files.set(updatedFile.contentsId, updatedFile.attributes()); - this.files.delete(file.contentsId); return updatedFile; } + + } diff --git a/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts b/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts index 123082091..0f722dcf2 100644 --- a/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts +++ b/src/context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem.ts @@ -5,6 +5,7 @@ import { LocalFileSystem } from '../domain/file-systems/LocalFileSystem'; import { RelativePathToAbsoluteConverter } from '../../shared/application/RelativePathToAbsoluteConverter'; import fs from 'fs/promises'; import { PlaceholderState } from '../domain/PlaceholderState'; +import Logger from 'electron-log'; export class NodeWinLocalFileSystem implements LocalFileSystem { constructor( @@ -74,6 +75,7 @@ export class NodeWinLocalFileSystem implements LocalFileSystem { } async updateFileIdentity(path: string, newIdentity: `${string}-${string}`): Promise { + Logger.info('[updateFileIdentity]: ', path, newIdentity); const isNotDirectory = true; return this.virtualDrive.updateFileIdentity(path, newIdentity, isNotDirectory); }