1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-13 10:24:20 +01:00
bitwarden-browser/src/main/messaging.main.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

import { ipcMain } from 'electron';
2018-02-08 19:10:13 +01:00
2018-02-14 05:38:18 +01:00
import { Main } from '../main';
2018-02-09 21:49:00 +01:00
const SyncInterval = 5 * 60 * 1000; // 5 minutes
2018-02-08 19:10:13 +01:00
export class MessagingMain {
2018-02-09 21:49:00 +01:00
private syncTimeout: NodeJS.Timer;
2018-02-14 05:38:18 +01:00
constructor(private main: Main) { }
2018-02-09 21:49:00 +01:00
2018-02-08 19:10:13 +01:00
init() {
2018-02-09 21:49:00 +01:00
this.scheduleNextSync();
2018-02-11 05:24:22 +01:00
ipcMain.on('messagingService', async (event: any, message: any) => this.onMessage(message));
2018-02-08 19:10:13 +01:00
}
2018-02-09 21:49:00 +01:00
2018-02-11 05:24:22 +01:00
onMessage(message: any) {
switch (message.command) {
case 'scheduleNextSync':
this.scheduleNextSync();
break;
2018-02-14 06:26:32 +01:00
case 'updateAppMenu':
this.main.menuMain.updateApplicationMenuState(message.isAuthenticated, message.isLocked);
break;
2018-02-11 05:24:22 +01:00
default:
break;
}
}
2018-02-09 21:49:00 +01:00
private scheduleNextSync() {
if (this.syncTimeout) {
global.clearTimeout(this.syncTimeout);
}
this.syncTimeout = global.setTimeout(() => {
2018-02-16 15:59:03 +01:00
if (this.main.windowMain.win == null) {
return;
}
2018-02-14 05:38:18 +01:00
this.main.windowMain.win.webContents.send('messagingService', {
2018-02-09 21:49:00 +01:00
command: 'checkSyncVault',
});
}, SyncInterval);
}
2018-02-08 19:10:13 +01:00
}