-
Notifications
You must be signed in to change notification settings - Fork 0
/
popupWindow.js
57 lines (50 loc) · 1.42 KB
/
popupWindow.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
/*
* PopupWindow module
*
* usage:
* popupWindow({
* content: '<div className="test"><button>Test</button></div>',
* show: true,
* css: 'body { background: red }',
* url: 'http://google.com'
* })
*/
'use strict';
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
function popupWindow(options) {
var defaults = {
frame: false,
width: 480,
height: 320,
resizable: false,
show: false,
url: 'file://' + __dirname + '/popup.html'
};
if (typeof(options) === 'undefined') {
options = {};
}
Object.keys(options).forEach(function(key) { defaults[key] = options[key]; });
options = defaults;
var win = new BrowserWindow(options);
win.on('closed', function() {
win = null;
});
win.webContents.on('did-finish-load', function() {
if (options.css) {
win.webContents.send('add-css', options.css);
}
if (options.content) {
win.webContents.send('set-content', options.content);
}
});
if (options.pos) {
win.setPosition(options.pos.x, options.pos.y);
}
win.loadURL(options.url);
if (options.debug) {
win.webContents.openDevTools();
}
return win;
}
module.exports = popupWindow;