mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-22 19:23:22 +00:00
menu and main keytar storage service
This commit is contained in:
@@ -3,44 +3,18 @@ import {
|
||||
ipcMain,
|
||||
} from 'electron';
|
||||
|
||||
import {
|
||||
deletePassword,
|
||||
getPassword,
|
||||
setPassword,
|
||||
} from 'keytar';
|
||||
import { WindowMain } from 'jslib/electron/window.main';
|
||||
|
||||
import { Main } from '../main';
|
||||
|
||||
const KeytarService = 'Bitwarden';
|
||||
const SyncInterval = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
export class MessagingMain {
|
||||
private syncTimeout: NodeJS.Timer;
|
||||
|
||||
constructor(private main: Main) { }
|
||||
constructor(private windowMain: WindowMain) { }
|
||||
|
||||
init() {
|
||||
this.scheduleNextSync();
|
||||
ipcMain.on('messagingService', async (event: any, message: any) => this.onMessage(message));
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onMessage(message: any) {
|
||||
@@ -62,11 +36,11 @@ export class MessagingMain {
|
||||
}
|
||||
|
||||
this.syncTimeout = global.setTimeout(() => {
|
||||
if (this.main.windowMain.win == null) {
|
||||
if (this.windowMain.win == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.main.windowMain.win.webContents.send('messagingService', {
|
||||
this.windowMain.win.webContents.send('messagingService', {
|
||||
command: 'checkSyncVault',
|
||||
});
|
||||
}, SyncInterval);
|
||||
|
||||
Reference in New Issue
Block a user