From 212009a69b458808496b6ce32edf0f28a0038f83 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sun, 19 Mar 2023 23:42:27 +0200 Subject: [PATCH] create `sendToFront()` TODO: replace all `webcontents.send ` with `sendToFront = require('../providers/app-controls')` --- providers/app-controls.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/providers/app-controls.js b/providers/app-controls.js index 3567e22a..bed99157 100644 --- a/providers/app-controls.js +++ b/providers/app-controls.js @@ -1,12 +1,10 @@ const path = require("path"); -const is = require("electron-is"); - const { app, BrowserWindow, ipcMain, ipcRenderer } = require("electron"); const config = require("../config"); module.exports.restart = () => { - is.main() ? restart() : ipcRenderer.send('restart'); + process.type === 'browser' ? restart() : ipcRenderer.send('restart'); }; module.exports.setupAppControls = () => { @@ -21,3 +19,16 @@ function restart() { // execPath will be undefined if not running portable app, resulting in default behavior app.quit(); } + +function sendToFront(channel, ...args) { + BrowserWindow.getAllWindows().forEach(win => { + win.webContents.send(channel, ...args); + }); +} + +module.exports.sendToFront = + process.type === 'browser' + ? sendToFront + : () => { + console.error('sendToFront called from renderer'); + };