Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[_]: manual-sync-permission-delay #480

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading