-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathipc.js
44 lines (40 loc) · 1.32 KB
/
ipc.js
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
function ipcManager(ipcMain, BrowserWindow) {
/**
* Taken from https://github.com/konsumer/electron-prompt/blob/master/main.js
*/
ipcMain.on('terminate', process.exit);
let promptResponse;
ipcMain.on('prompt', (eventRet, arg) => {
promptResponse = null;
let promptWindow = new BrowserWindow({
width: 200,
height: 100,
show: false,
resizable: false,
movable: false,
alwaysOnTop: true,
frame: false
});
arg.val = arg.val || '';
const promptHtml = `<label for="val">${arg.title}</label>
<input id="val" value="${arg.val}" autofocus />
<button onclick="require('electron').ipcRenderer.send('prompt-response', document.getElementById('val').value);window.close()">Ok</button>
<button onclick="window.close()">Cancel</button>
<style>
body {font-family: sans-serif;}
button {float:right; margin-left: 10px;}
label,input {margin-bottom: 10px; width: 100%; display:block;}
</style>`;
promptWindow.loadURL(`data:text/html,${promptHtml}`);
promptWindow.show();
promptWindow.on('closed', () => {
eventRet.returnValue = promptResponse;
promptWindow = null;
});
});
ipcMain.on('prompt-response', (event, arg) => {
if (arg === '') { arg = null; }
promptResponse = arg;
});
}
module.exports = ipcManager;