aboutsummaryrefslogtreecommitdiff
path: root/src/modules/window.js
blob: 6cc573ca7979fb3bbc78adf8742db18d0fdf481e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const ipcMain = require("electron").ipcMain;

let win = {};

// logs into the dev tools of the renderer
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) => {
	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;