aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/main.js10
-rw-r--r--src/index.js14
-rw-r--r--src/modules/window.js31
3 files changed, 52 insertions, 3 deletions
diff --git a/src/app/main.js b/src/app/main.js
index 73537a2..72e0e09 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -232,7 +232,15 @@ ipcRenderer.on("newpath", (event, newpath) => {
// Continuation of log()
ipcRenderer.on("log", (event, msg) => {log(msg)})
-ipcRenderer.on("alert", (event, msg) => {alert(msg)})
+ipcRenderer.on("alert", (event, data) => {
+ alert(data.message);
+ ipcRenderer.send("alert-closed-" + data.id);
+})
+
+ipcRenderer.on("confirm", (event, data) => {
+ let confirmed = confirm(data.message);
+ ipcRenderer.send("confirm-closed-" + data.id, confirmed);
+})
// Updates the installed mods
ipcRenderer.on("mods", (event, mods_obj) => {
diff --git a/src/index.js b/src/index.js
index fbe9bfb..c6179e0 100644
--- a/src/index.js
+++ b/src/index.js
@@ -82,7 +82,19 @@ function start() {
// passthrough to renderer from main
ipcMain.on("win-log", (event, ...args) => {send("log", ...args)});
- ipcMain.on("win-alert", (event, ...args) => {send("alert", ...args)});
+ ipcMain.on("win-alert", (event, msg, id) => {
+ send("alert", {
+ id: id,
+ message: msg,
+ })
+ });
+
+ ipcMain.on("win-confirm", (event, msg, id) => {
+ send("confirm", {
+ id: id,
+ message: msg,
+ })
+ });
// mod states
ipcMain.on("duped-mod", (event, modname) => {send("duped-mod", modname)});
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;