1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-24 03:32:51 +02:00
bitwarden-browser/src/main/messaging.main.ts

68 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-02-08 19:10:13 +01:00
import { app, ipcMain } from 'electron';
// import { getPassword, setPassword, deletePassword } from 'keytar';
2018-02-09 21:49:00 +01:00
import { WindowMain } from './window.main';
2018-02-08 19:10:13 +01:00
const KeytarService = 'bitwarden';
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;
constructor(private windowMain: WindowMain) { }
2018-02-08 19:10:13 +01:00
init() {
2018-02-09 21:49:00 +01:00
this.scheduleNextSync();
2018-02-08 19:10:13 +01:00
ipcMain.on('messagingService', async (event: any, message: any) => {
switch (message.command) {
case 'loggedIn':
break;
case 'logout':
break;
case 'syncCompleted':
break;
2018-02-09 21:49:00 +01:00
case 'scheduleNextSync':
this.scheduleNextSync();
break;
2018-02-08 19:10:13 +01:00
default:
break;
}
});
/*
ipcMain.on('keytar', async (event: any, message: any) => {
try {
let val: string = null;
if (message.action && message.key) {
if (message.action === 'getPassword') {
val = await getPassword(KeytarService, message.key);
} else if (message.action === 'setPassword' && message.value) {
await setPassword(KeytarService, message.key, message.value);
} else if (message.action === 'deletePassword') {
await deletePassword(KeytarService, message.key);
}
}
event.returnValue = val;
}
catch {
event.returnValue = null;
}
});
*/
}
2018-02-09 21:49:00 +01:00
private scheduleNextSync() {
if (this.syncTimeout) {
global.clearTimeout(this.syncTimeout);
}
this.syncTimeout = global.setTimeout(() => {
this.windowMain.win.webContents.send('messagingService', {
command: 'checkSyncVault',
});
}, SyncInterval);
}
2018-02-08 19:10:13 +01:00
}