mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-05 23:53:21 +00:00
* Split jslib * Change hook to preinstall * Install gyp (ci) * Fix rebuild command * Review comments * Add tsconfig-paths-plugin to webpack.cli. * Bump jslib * Install old version of prebuild-install to bypass bug in pkg
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import {
|
|
app,
|
|
ipcMain,
|
|
} from 'electron';
|
|
|
|
import { TrayMain } from 'jslib-electron/tray.main';
|
|
import { UpdaterMain } from 'jslib-electron/updater.main';
|
|
import { WindowMain } from 'jslib-electron/window.main';
|
|
|
|
import { MenuMain } from './menu.main';
|
|
|
|
const SyncCheckInterval = 60 * 1000; // 1 minute
|
|
|
|
export class MessagingMain {
|
|
private syncTimeout: NodeJS.Timer;
|
|
|
|
constructor(private windowMain: WindowMain, private menuMain: MenuMain,
|
|
private updaterMain: UpdaterMain, private trayMain: TrayMain) { }
|
|
|
|
init() {
|
|
ipcMain.on('messagingService', async (event: any, message: any) => this.onMessage(message));
|
|
}
|
|
|
|
onMessage(message: any) {
|
|
switch (message.command) {
|
|
case 'checkForUpdate':
|
|
this.updaterMain.checkForUpdate(true);
|
|
break;
|
|
case 'scheduleNextDirSync':
|
|
this.scheduleNextSync();
|
|
break;
|
|
case 'cancelDirSync':
|
|
this.windowMain.win.webContents.send('messagingService', {
|
|
command: 'syncScheduleStopped',
|
|
});
|
|
if (this.syncTimeout) {
|
|
global.clearTimeout(this.syncTimeout);
|
|
}
|
|
break;
|
|
case 'hideToTray':
|
|
this.trayMain.hideToTray();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private scheduleNextSync() {
|
|
this.windowMain.win.webContents.send('messagingService', {
|
|
command: 'syncScheduleStarted',
|
|
});
|
|
|
|
if (this.syncTimeout) {
|
|
global.clearTimeout(this.syncTimeout);
|
|
}
|
|
|
|
this.syncTimeout = global.setTimeout(() => {
|
|
if (this.windowMain.win == null) {
|
|
return;
|
|
}
|
|
|
|
this.windowMain.win.webContents.send('messagingService', {
|
|
command: 'checkDirSync',
|
|
});
|
|
}, SyncCheckInterval);
|
|
}
|
|
}
|