MagicMirror/js/electron.js

100 lines
2.3 KiB
JavaScript
Raw Normal View History

/* jshint esversion: 6 */
2016-04-05 14:35:11 -04:00
"use strict";
2016-03-27 20:40:07 +02:00
2016-04-05 14:35:11 -04:00
const Server = require(__dirname + "/server.js");
const electron = require("electron");
2016-04-08 22:16:22 +02:00
const core = require(__dirname + "/app.js");
// Config
var config = {};
2016-03-27 20:40:07 +02:00
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
2016-04-05 14:35:11 -04:00
function createWindow() {
var electronOptions = {
width: 800,
height: 600,
x: 0,
y: 0,
darkTheme: true,
webPreferences: {
nodeIntegration: false,
zoomFactor: config.zoom
}
}
2016-07-27 12:50:59 +02:00
if (config.kioskmode) {
electronOptions.kiosk = true;
2016-07-27 12:50:59 +02:00
} else {
electronOptions.fullscreen = true;
electronOptions.autoHideMenuBar = true;
2016-07-27 12:50:59 +02:00
}
// Create the browser window.
mainWindow = new BrowserWindow(electronOptions);
// and load the index.html of the app.
//mainWindow.loadURL('file://' + __dirname + '../../index.html');
2016-04-05 14:35:11 -04:00
mainWindow.loadURL("http://localhost:" + config.port);
2016-07-30 09:42:31 -04:00
// Open the DevTools if run with "npm start dev"
if(process.argv[2] == "dev") {
2016-07-30 15:58:51 +02:00
mainWindow.webContents.openDevTools();
}
// Set responders for window events.
2016-04-05 14:35:11 -04:00
mainWindow.on("closed", function() {
mainWindow = null;
});
if (config.kioskmode) {
mainWindow.on("blur", function() {
mainWindow.focus();
});
mainWindow.on("leave-full-screen", function() {
mainWindow.setFullScreen(true);
});
mainWindow.on("resize", function() {
setTimeout(function() {
mainWindow.reload();
}, 1000);
});
}
2016-03-27 20:40:07 +02:00
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
2016-04-05 14:35:11 -04:00
app.on("ready", function() {
console.log("Launching application.");
createWindow();
});
2016-03-27 20:40:07 +02:00
// Quit when all windows are closed.
2016-04-05 14:35:11 -04:00
app.on("window-all-closed", function() {
createWindow();
2016-03-27 20:40:07 +02:00
});
2016-04-05 14:35:11 -04:00
app.on("activate", function() {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
2016-03-27 20:40:07 +02:00
});
2016-04-08 22:16:22 +02:00
// Start the core application.
// This starts all node helpers and starts the webserver.
core.start(function(c) {
config = c;
});