mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
commit e38dd346d9f796807ea71035c18e3533ec245ba6 Author: Michael Teeuw <michael@xonaymedia.nl> Date: Sat Apr 2 19:17:30 2016 +0200 Add the possibility to set the maximum number of days. commit 6f5c86775b708d19d3798267ffd23e491a1d2c62 Author: Sam Vendittelli <sam.vendittelli@hotmail.com> Date: Sat Apr 2 06:27:44 2016 +0100 Fixed cursor appearing in margin Cursor was appearing in the margin so moved `cursor: none` property to html. commit 576c668d84b34b8ad7a0fd51b146fde60f721682 Author: Domi-G <lessuseguy+githubdomig@gmail.com> Date: Fri Apr 1 22:52:32 2016 +0200 Huge cleanup of white space
148 lines
3.7 KiB
JavaScript
Executable File
148 lines
3.7 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
//load modules
|
|
const walk = require('walk');
|
|
const fs = require('fs');
|
|
const Server = require(__dirname + '/server.js');
|
|
const spawn = require('child_process').spawn;
|
|
const electron = require('electron');
|
|
const defaultModules = require(__dirname + '/../modules/default/defaultmodules.js');
|
|
|
|
// Config
|
|
var config = {};
|
|
// Module to control application life.
|
|
const app = electron.app;
|
|
// Module to create native browser window.
|
|
const BrowserWindow = electron.BrowserWindow;
|
|
|
|
var nodeHelpers = [];
|
|
|
|
// 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;
|
|
|
|
function createWindow () {
|
|
// Create the browser window.
|
|
mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true, autoHideMenuBar: true, webPreferences: {nodeIntegration: false}});
|
|
|
|
// and load the index.html of the app.
|
|
//mainWindow.loadURL('file://' + __dirname + '../../index.html');
|
|
mainWindow.loadURL('http://localhost:' + config.port);
|
|
|
|
// Open the DevTools.
|
|
//mainWindow.webContents.openDevTools();
|
|
|
|
// Emitted when the window is closed.
|
|
mainWindow.on('closed', function() {
|
|
// Dereference the window object, usually you would store windows
|
|
// in an array if your app supports multi windows, this is the time
|
|
// when you should delete the corresponding element.
|
|
mainWindow = null;
|
|
});
|
|
}
|
|
|
|
function loadConfig (callback) {
|
|
console.log("Loading config ...");
|
|
var defaults = require(__dirname + '/defaults.js');
|
|
var configFilename = __dirname + '/../config/config.js';
|
|
|
|
try {
|
|
fs.accessSync(configFilename, fs.R_OK);
|
|
var c = require(configFilename);
|
|
var config = Object.assign(defaults, c);
|
|
callback(config);
|
|
} catch (e) {
|
|
callback(defaults);
|
|
}
|
|
}
|
|
|
|
function loadModule(module) {
|
|
|
|
var elements = module.split('/');
|
|
var moduleName = elements[elements.length - 1];
|
|
var moduleFolder = __dirname + '/../modules/' + module;
|
|
|
|
if (defaultModules.indexOf(moduleName) !== -1) {
|
|
moduleFolder = __dirname + '/../modules/default/' + module;
|
|
}
|
|
|
|
var helperPath = moduleFolder + '/node_helper.js';
|
|
|
|
var loadModule = true;
|
|
try {
|
|
fs.accessSync(helperPath, fs.R_OK);
|
|
} catch (e) {
|
|
loadModule = false;
|
|
console.log("No helper found for module: " + moduleName + ".");
|
|
}
|
|
|
|
if (loadModule) {
|
|
var Module = require(helperPath);
|
|
var m = new Module();
|
|
m.setName(moduleName);
|
|
nodeHelpers.push(m);
|
|
}
|
|
}
|
|
|
|
function loadModules(modules) {
|
|
console.log("Loading module helpers ...");
|
|
|
|
for (var m in modules) {
|
|
loadModule(modules[m]);
|
|
}
|
|
|
|
console.log("All module helpers loaded.");
|
|
}
|
|
|
|
loadConfig(function(c) {
|
|
config = c;
|
|
|
|
var modules = [];
|
|
|
|
for (var m in config.modules) {
|
|
var module = config.modules[m];
|
|
if (modules.indexOf(module.module) === -1) {
|
|
modules.push(module.module);
|
|
}
|
|
}
|
|
|
|
loadModules(modules);
|
|
|
|
var server = new Server(config, function(io) {
|
|
console.log('Server started ...');
|
|
|
|
for (var h in nodeHelpers) {
|
|
var nodeHelper = nodeHelpers[h];
|
|
nodeHelper.setSocketIO(io);
|
|
nodeHelper.start();
|
|
}
|
|
|
|
console.log('Sockets connected & modules started ...');
|
|
|
|
});
|
|
});
|
|
|
|
// This method will be called when Electron has finished
|
|
// initialization and is ready to create browser windows.
|
|
app.on('ready', function() {
|
|
console.log('Launching application.');
|
|
createWindow();
|
|
});
|
|
|
|
// Quit when all windows are closed.
|
|
app.on('window-all-closed', function () {
|
|
// On OS X it is common for applications and their menu bar
|
|
// to stay active until the user quits explicitly with Cmd + Q
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|
|
|
|
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();
|
|
}
|
|
});
|