mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-11 10:10:25 +01:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { ipcMain } from 'electron';
|
|
|
|
import { Main } from '../main';
|
|
|
|
const SyncInterval = 5 * 60 * 1000; // 5 minutes
|
|
|
|
export class MessagingMain {
|
|
private syncTimeout: NodeJS.Timer;
|
|
|
|
constructor(private main: Main) { }
|
|
|
|
init() {
|
|
this.scheduleNextSync();
|
|
ipcMain.on('messagingService', async (event: any, message: any) => this.onMessage(message));
|
|
}
|
|
|
|
onMessage(message: any) {
|
|
switch (message.command) {
|
|
case 'scheduleNextSync':
|
|
this.scheduleNextSync();
|
|
break;
|
|
case 'updateAppMenu':
|
|
this.main.menuMain.updateApplicationMenuState(message.isAuthenticated, message.isLocked);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private scheduleNextSync() {
|
|
if (this.syncTimeout) {
|
|
global.clearTimeout(this.syncTimeout);
|
|
}
|
|
|
|
this.syncTimeout = global.setTimeout(() => {
|
|
if (this.main.windowMain.win == null) {
|
|
return;
|
|
}
|
|
|
|
this.main.windowMain.win.webContents.send('messagingService', {
|
|
command: 'checkSyncVault',
|
|
});
|
|
}, SyncInterval);
|
|
}
|
|
}
|