aboutsummaryrefslogtreecommitdiff
path: root/src/modules/window.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2023-04-29 00:30:29 +0200
committer0neGal <mail@0negal.com>2023-04-29 00:30:29 +0200
commit2a77d65c2276b9038bad4251692dc4a9c80029ce (patch)
tree3127ae172c8b91f466a55292d98f6f41c9122dc9 /src/modules/window.js
parent35b0836701fb337b5e9ae9effb9ed9d788c8403c (diff)
downloadViper-2a77d65c2276b9038bad4251692dc4a9c80029ce.tar.gz
Viper-2a77d65c2276b9038bad4251692dc4a9c80029ce.zip
win.alert() now uses Promise, and added .confirm()
win.alert() now has a Promise return value, which'll allow you to wait until an alert has been closed before continuing code execution. win.confirm() was also added it's the same as win.alert() except it runs confirm() in the renderer instead of alert(), and has a return boolean in the Promise resolve callback. This boolean being whether the user confirmed the action or not.
Diffstat (limited to 'src/modules/window.js')
-rw-r--r--src/modules/window.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/modules/window.js b/src/modules/window.js
index 3b5c76f..6cc573c 100644
--- a/src/modules/window.js
+++ b/src/modules/window.js
@@ -7,9 +7,38 @@ win.log = (msg) => {
ipcMain.emit("win-log", msg, msg);
}
+// 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
win.alert = (msg) => {
- ipcMain.emit("win-alert", msg, msg);
+ alert_id++;
+
+ return new Promise((resolve) => {
+ ipcMain.once(`alert-closed-${alert_id}`, () => {
+ resolve();
+ })
+
+ ipcMain.emit("win-alert", msg, msg, alert_id);
+ })
+}
+
+// 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
+win.confirm = (msg) => {
+ confirm_id++;
+
+ return new Promise((resolve) => {
+ ipcMain.once(`confirm-closed-${confirm_id}`, (event, confirmed) => {
+ resolve(confirmed);
+ })
+
+ ipcMain.emit("win-confirm", msg, msg, confirm_id);
+ })
}
module.exports = win;