Skip to content

Commit

Permalink
Merge pull request #480 from internxt/feat/block-manual-sync-in-syncing
Browse files Browse the repository at this point in the history
[_]: manual-sync-permission-delay
  • Loading branch information
miguelsw authored Apr 3, 2024
2 parents 20eb78b + 82615b5 commit 24bd89d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/apps/main/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@ declare interface Window {
openUrl: (url: string) => Promise<void>;
getPreferredAppLanguage: () => Promise<Array<string>>;
syncManually: () => Promise<void>;
getRecentlywasSyncing: () => Promise<boolean>;
};
}
4 changes: 4 additions & 0 deletions src/apps/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,9 @@ contextBridge.exposeInMainWorld('electron', {
syncManually() {
return ipcRenderer.invoke('SYNC_MANUALLY');
},
getRecentlywasSyncing() {
return ipcRenderer.invoke('CHECK_SYNC_IN_PROGRESS');
},

path,
});
2 changes: 1 addition & 1 deletion src/apps/main/remote-sync/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 18 additions & 6 deletions src/apps/renderer/pages/Widget/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -200,13 +210,15 @@ export default function Header() {
)}
</Menu.Item>
<Menu.Item>
{({ active }) => (
<div>
<DropdownItem active={active} onClick={onSyncClick}>
{({active}) => {

return (<div>
<DropdownItem active={active} onClick={onSyncClick} >
<span>{translate('widget.header.dropdown.sync')}</span>
</DropdownItem>
</div>
)}
</div>);
}
}
</Menu.Item>
<Menu.Item>
{({ active }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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);
}

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;
Expand Down

0 comments on commit 24bd89d

Please sign in to comment.