You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
999 B
JavaScript
49 lines
999 B
JavaScript
const electron = require("electron");
|
|
const uuid = require("uuid");
|
|
|
|
module.exports = function() {
|
|
let windows = {};
|
|
|
|
function packFunction(func) {
|
|
return `;${func.toString()};${func.name}();`;
|
|
}
|
|
|
|
function loadLiveReload() {
|
|
let scriptTag = document.createElement("script");
|
|
scriptTag.src = "http://127.0.0.1:35729/livereload.js";
|
|
document.querySelector("head").appendChild(scriptTag);
|
|
}
|
|
|
|
return {
|
|
create: function(options) {
|
|
let id = uuid.v4();
|
|
let window = new electron.BrowserWindow(options);
|
|
|
|
if (options.url != null) {
|
|
window.loadURL(options.url);
|
|
}
|
|
|
|
if (options.loadDeveloperTools) {
|
|
window.webContents.openDevTools();
|
|
}
|
|
|
|
if (options.liveReload) {
|
|
window.webContents.on("dom-ready", () => {
|
|
window.webContents.executeJavaScript(packFunction(loadLiveReload));
|
|
});
|
|
}
|
|
|
|
windows[id] = window;
|
|
|
|
window.on("closed", () => {
|
|
delete windows[id];
|
|
});
|
|
|
|
return window;
|
|
},
|
|
get: function(id) {
|
|
return windows[id];
|
|
}
|
|
}
|
|
}
|