diff options
author | 0neGal <mail@0negal.com> | 2024-02-04 17:16:00 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2024-02-04 17:16:00 +0100 |
commit | ee816e6a1aa908df381dcc488b1193d1e78e0ca6 (patch) | |
tree | 88dc2820edfcbe025ad8c6c75e812c619c6363c4 /src/win.js | |
parent | f165e540d0d74946eed2b8e5c857e7ee56227f8a (diff) | |
download | Viper-ee816e6a1aa908df381dcc488b1193d1e78e0ca6.tar.gz Viper-ee816e6a1aa908df381dcc488b1193d1e78e0ca6.zip |
merge src/modules/window.js into src/win.js
I intended to do this when creating src/win.js, but wanted it to be in a
different commit, as that commit made pretty large changes as well.
So no more `main_win`, `win_show` and confusion between what `win` is.
Diffstat (limited to 'src/win.js')
-rw-r--r-- | src/win.js | 57 |
1 files changed, 56 insertions, 1 deletions
@@ -1,5 +1,56 @@ +const ipcMain = require("electron").ipcMain; + +// logs into the dev tools of the renderer +log = (...args) => { + win.send("log", ...args); +} + +// this increments for every alert that's created, the ID is used to +// keep track of popups being opened or closed. +let alert_id = 0; + +// sends an alert to the renderer +alert = async (msg) => { + alert_id++; + + return new Promise((resolve) => { + ipcMain.once(`alert-closed-${alert_id}`, () => { + resolve(); + }) + + win.send("alert", { + id: alert_id, + message: msg + }) + }) +} + +// this increments for every confirm alert that's created, the ID is +// used to keep track of popups being opened or closed. +let confirm_id = 0; + +// sends an alert to the renderer +confirm = async (msg) => { + confirm_id++; + + return new Promise((resolve) => { + ipcMain.once(`confirm-closed-${confirm_id}`, (event, confirmed) => { + resolve(confirmed); + }) + + win.send("confirm", { + message: msg, + id: confirm_id + }) + }) +} + let win = { - send: () => {} + send: () => {}, + + log: log, + alert: alert, + confirm: confirm } let func = () => { @@ -8,6 +59,10 @@ let func = () => { func.set = (main_window) => { win = main_window; + + win.log = log; + win.alert = alert; + win.confirm = confirm; } module.exports = func; |