-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
71 lines (55 loc) · 1.82 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow || electron.remote.BrowserWindow;
const ipcMain = electron.ipcMain || electron.remote.ipcMain;
const url = require('url');
const path = require('path');
function InputPrompt (_label = 'Please enter a value', _placeholder = '', _icon = './icon.png', _masked = false) {
return new Promise((resolve, reject) => {
if (process.platform !== 'darwin' || process.platform !== 'win32') {
let err = 'electron-osx-prompt is intended for use on macOS or Windows.';
console.warn(err);
}
if (_icon == null) {
_icon = './icon.png';
}
let promptWindow = new BrowserWindow({
width: 450,
height: 160,
skipTaskbar: true,
alwaysOnTop: true,
backgroundColor: '#ECECEC',
show: false,
frame: false,
resizable: false,
parent: BrowserWindow.getFocusedWindow(),
modal: true
});
promptWindow.setMenu(null);
const promptUrl = url.format({
protocol: 'file',
slashes: true,
pathname: path.join(__dirname, './prompt.html')
});
promptWindow.loadURL(promptUrl);
let options = {
label: _label.toString(),
placeholder: _placeholder.toString(),
icon: _icon.toString(),
masked: _masked
};
promptWindow.webContents.on('did-finish-load', () => {
promptWindow.webContents.send('electron-osx-prompt-settings', options);
// promptWindow.webContents.openDevTools({ detach: true });
});
promptWindow.once('ready-to-show', promptWindow.show);
const returnValue = (event, value) => {
resolve(value);
if (promptWindow) {
promptWindow.close();
promptWindow = null;
}
};
ipcMain.on('electron-osx-prompt-return-value', returnValue);
});
}
module.exports = InputPrompt;