From 82615b5de7b8c2db56db5cebbb26cd40a179f56c Mon Sep 17 00:00:00 2001 From: miguel Date: Mon, 1 Apr 2024 17:32:01 -0500 Subject: [PATCH] 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;