mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
Apply Prettier (#581)
This commit is contained in:
@@ -1,58 +1,66 @@
|
||||
import { app, dialog, ipcMain, Menu, MenuItem, nativeTheme } from 'electron';
|
||||
import { promises as fs } from 'fs';
|
||||
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
|
||||
import { RendererMenuItem } from '../utils';
|
||||
import { app, dialog, ipcMain, Menu, MenuItem, nativeTheme } from "electron";
|
||||
import { promises as fs } from "fs";
|
||||
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
||||
import { RendererMenuItem } from "../utils";
|
||||
|
||||
import { ThemeType } from 'jslib-common/enums/themeType';
|
||||
import { ThemeType } from "jslib-common/enums/themeType";
|
||||
|
||||
import { WindowMain } from '../window.main';
|
||||
import { WindowMain } from "../window.main";
|
||||
|
||||
export class ElectronMainMessagingService implements MessagingService {
|
||||
constructor(private windowMain: WindowMain, private onMessage: (message: any) => void) {
|
||||
ipcMain.handle('appVersion', () => {
|
||||
return app.getVersion();
|
||||
});
|
||||
constructor(private windowMain: WindowMain, private onMessage: (message: any) => void) {
|
||||
ipcMain.handle("appVersion", () => {
|
||||
return app.getVersion();
|
||||
});
|
||||
|
||||
ipcMain.handle('systemTheme', () => {
|
||||
return nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light;
|
||||
});
|
||||
ipcMain.handle("systemTheme", () => {
|
||||
return nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light;
|
||||
});
|
||||
|
||||
ipcMain.handle('showMessageBox', (event, options) => {
|
||||
return dialog.showMessageBox(options);
|
||||
});
|
||||
ipcMain.handle("showMessageBox", (event, options) => {
|
||||
return dialog.showMessageBox(options);
|
||||
});
|
||||
|
||||
ipcMain.handle('openContextMenu', (event, options: {menu: RendererMenuItem[]}) => {
|
||||
return new Promise(resolve => {
|
||||
const menu = new Menu();
|
||||
options.menu.forEach((m, index) => {
|
||||
menu.append(new MenuItem({
|
||||
label: m.label,
|
||||
type: m.type,
|
||||
click: () => {
|
||||
resolve(index);
|
||||
},
|
||||
}));
|
||||
});
|
||||
menu.popup({ window: windowMain.win, callback: () => {
|
||||
resolve(-1);
|
||||
}});
|
||||
});
|
||||
ipcMain.handle("openContextMenu", (event, options: { menu: RendererMenuItem[] }) => {
|
||||
return new Promise((resolve) => {
|
||||
const menu = new Menu();
|
||||
options.menu.forEach((m, index) => {
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: m.label,
|
||||
type: m.type,
|
||||
click: () => {
|
||||
resolve(index);
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
menu.popup({
|
||||
window: windowMain.win,
|
||||
callback: () => {
|
||||
resolve(-1);
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.handle('windowVisible', () => {
|
||||
return windowMain.win?.isVisible();
|
||||
});
|
||||
ipcMain.handle("windowVisible", () => {
|
||||
return windowMain.win?.isVisible();
|
||||
});
|
||||
|
||||
nativeTheme.on('updated', () => {
|
||||
windowMain.win?.webContents.send('systemThemeUpdated', nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light);
|
||||
});
|
||||
}
|
||||
|
||||
send(subscriber: string, arg: any = {}) {
|
||||
const message = Object.assign({}, { command: subscriber }, arg);
|
||||
this.onMessage(message);
|
||||
if (this.windowMain.win != null) {
|
||||
this.windowMain.win.webContents.send('messagingService', message);
|
||||
}
|
||||
nativeTheme.on("updated", () => {
|
||||
windowMain.win?.webContents.send(
|
||||
"systemThemeUpdated",
|
||||
nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
send(subscriber: string, arg: any = {}) {
|
||||
const message = Object.assign({}, { command: subscriber }, arg);
|
||||
this.onMessage(message);
|
||||
if (this.windowMain.win != null) {
|
||||
this.windowMain.win.webContents.send("messagingService", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user