Run prettier over ALL files once

No other changes done in this commit
This commit is contained in:
Veeck
2020-05-11 22:22:32 +02:00
parent 3a5a29efc0
commit abb5dc5739
160 changed files with 2369 additions and 2210 deletions

View File

@@ -44,7 +44,7 @@ process.on("uncaughtException", function (err) {
/* App - The core app.
*/
var App = function() {
var App = function () {
var nodeHelpers = [];
/* loadConfig(callback)
@@ -53,14 +53,14 @@ var App = function() {
*
* argument callback function - The callback function.
*/
var loadConfig = function(callback) {
var loadConfig = function (callback) {
console.log("Loading config ...");
var defaults = require(__dirname + "/defaults.js");
// For this check proposed to TestSuite
// https://forum.magicmirror.builders/topic/1456/test-suite-for-magicmirror/8
var configFilename = path.resolve(global.root_path + "/config/config.js");
if (typeof(global.configuration_file) !== "undefined") {
if (typeof global.configuration_file !== "undefined") {
configFilename = path.resolve(global.configuration_file);
}
@@ -82,23 +82,19 @@ var App = function() {
}
};
var checkDeprecatedOptions = function(userConfig) {
var checkDeprecatedOptions = function (userConfig) {
var deprecated = require(global.root_path + "/js/deprecated.js");
var deprecatedOptions = deprecated.configs;
var usedDeprecated = [];
deprecatedOptions.forEach(function(option) {
deprecatedOptions.forEach(function (option) {
if (userConfig.hasOwnProperty(option)) {
usedDeprecated.push(option);
}
});
if (usedDeprecated.length > 0) {
console.warn(Utils.colors.warn(
"WARNING! Your config is using deprecated options: " +
usedDeprecated.join(", ") +
". Check README and CHANGELOG for more up-to-date ways of getting the same functionality.")
);
console.warn(Utils.colors.warn("WARNING! Your config is using deprecated options: " + usedDeprecated.join(", ") + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality."));
}
};
@@ -107,8 +103,7 @@ var App = function() {
*
* argument module string - The name of the module (including subpath).
*/
var loadModule = function(module, callback) {
var loadModule = function (module, callback) {
var elements = module.split("/");
var moduleName = elements[elements.length - 1];
var moduleFolder = __dirname + "/../modules/" + module;
@@ -156,13 +151,13 @@ var App = function() {
*
* argument module string - The name of the module (including subpath).
*/
var loadModules = function(modules, callback) {
var loadModules = function (modules, callback) {
console.log("Loading module helpers ...");
var loadNextModule = function() {
var loadNextModule = function () {
if (modules.length > 0) {
var nextModule = modules[0];
loadModule(nextModule, function() {
loadModule(nextModule, function () {
modules = modules.slice(1);
loadNextModule();
});
@@ -205,9 +200,8 @@ var App = function() {
*
* argument callback function - The callback function.
*/
this.start = function(callback) {
loadConfig(function(c) {
this.start = function (callback) {
loadConfig(function (c) {
config = c;
var modules = [];
@@ -219,8 +213,8 @@ var App = function() {
}
}
loadModules(modules, function() {
var server = new Server(config, function(app, io) {
loadModules(modules, function () {
var server = new Server(config, function (app, io) {
console.log("Server started ...");
for (var h in nodeHelpers) {
@@ -245,7 +239,7 @@ var App = function() {
* This calls each node_helper's STOP() function, if it exists.
* Added to fix #1056
*/
this.stop = function() {
this.stop = function () {
for (var h in nodeHelpers) {
var nodeHelper = nodeHelpers[h];
if (typeof nodeHelper.stop === "function") {
@@ -262,7 +256,9 @@ var App = function() {
*/
process.on("SIGINT", () => {
console.log("[SIGINT] Received. Shutting down server...");
setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds
setTimeout(() => {
process.exit(0);
}, 3000); // Force quit after 3 seconds
this.stop();
process.exit(0);
});
@@ -271,7 +267,9 @@ var App = function() {
*/
process.on("SIGTERM", () => {
console.log("[SIGTERM] Received. Shutting down server...");
setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds
setTimeout(() => {
process.exit(0);
}, 3000); // Force quit after 3 seconds
this.stop();
process.exit(0);
});

View File

@@ -53,13 +53,15 @@ function checkConfigFile() {
console.info(Utils.colors.info("Checking file... "), configFileName);
// I'm not sure if all ever is utf-8
fs.readFile(configFileName, "utf-8", function (err, data) {
if (err) { throw err; }
if (err) {
throw err;
}
const messages = linter.verify(data, config);
if (messages.length === 0) {
console.log("Your configuration file doesn't contain syntax errors :)");
return true;
} else {
messages.forEach(error => {
messages.forEach((error) => {
console.log("Line", error.line, "col", error.column, error.message);
});
}

View File

@@ -9,10 +9,14 @@
*/
(function () {
var initializing = false;
var fnTest = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/;
var fnTest = /xyz/.test(function () {
xyz;
})
? /\b_super\b/
: /.*/;
// The base Class implementation (does nothing)
this.Class = function () { };
this.Class = function () {};
// Create a new Class that inherits from this class
Class.extend = function (prop) {
@@ -32,23 +36,25 @@
// Copy the properties over onto the new prototype
for (var name in prop) {
// Check if we're overwriting an existing function
prototype[name] = typeof prop[name] === "function" &&
typeof _super[name] === "function" && fnTest.test(prop[name]) ? (function (name, fn) {
return function () {
var tmp = this._super;
prototype[name] =
typeof prop[name] === "function" && typeof _super[name] === "function" && fnTest.test(prop[name])
? (function (name, fn) {
return function () {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];
// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]) : prop[name];
return ret;
};
})(name, prop[name])
: prop[name];
}
// The dummy class constructor

View File

@@ -8,7 +8,7 @@
*/
var address = "localhost";
var port = 8080;
if (typeof(mmPort) !== "undefined") {
if (typeof mmPort !== "undefined") {
port = mmPort;
}
var defaults = {
@@ -68,14 +68,16 @@ var defaults = {
config: {
text: "www.michaelteeuw.nl"
}
},
}
],
paths: {
modules: "modules",
vendor: "vendor"
},
}
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = defaults;}
if (typeof module !== "undefined") {
module.exports = defaults;
}

View File

@@ -7,8 +7,10 @@
*/
var deprecated = {
configs: ["kioskmode"],
configs: ["kioskmode"]
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = deprecated;}
if (typeof module !== "undefined") {
module.exports = deprecated;
}

View File

@@ -62,21 +62,21 @@ function createWindow() {
}
// Set responders for window events.
mainWindow.on("closed", function() {
mainWindow.on("closed", function () {
mainWindow = null;
});
if (config.kioskmode) {
mainWindow.on("blur", function() {
mainWindow.on("blur", function () {
mainWindow.focus();
});
mainWindow.on("leave-full-screen", function() {
mainWindow.on("leave-full-screen", function () {
mainWindow.setFullScreen(true);
});
mainWindow.on("resize", function() {
setTimeout(function() {
mainWindow.on("resize", function () {
setTimeout(function () {
mainWindow.reload();
}, 1000);
});
@@ -85,17 +85,17 @@ function createWindow() {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on("ready", function() {
app.on("ready", function () {
console.log("Launching application.");
createWindow();
});
// Quit when all windows are closed.
app.on("window-all-closed", function() {
app.on("window-all-closed", function () {
createWindow();
});
app.on("activate", function() {
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) {
@@ -112,7 +112,9 @@ app.on("activate", function() {
app.on("before-quit", (event) => {
console.log("Shutting down server...");
event.preventDefault();
setTimeout(() => { process.exit(0); }, 3000); // Force-quit after 3 seconds.
setTimeout(() => {
process.exit(0);
}, 3000); // Force-quit after 3 seconds.
core.stop();
process.exit(0);
});
@@ -120,7 +122,7 @@ app.on("before-quit", (event) => {
// Start the core application if server is run on localhost
// This starts all node helpers and starts the webserver.
if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].indexOf(config.address) > -1) {
core.start(function(c) {
core.start(function (c) {
config = c;
});
}

View File

@@ -6,8 +6,7 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var Loader = (function() {
var Loader = (function () {
/* Create helper variables */
var loadedModuleFiles = [];
@@ -19,14 +18,13 @@ var Loader = (function() {
/* loadModules()
* Loops thru all modules and requests load for every module.
*/
var loadModules = function() {
var loadModules = function () {
var moduleData = getModuleData();
var loadNextModule = function() {
var loadNextModule = function () {
if (moduleData.length > 0) {
var nextModule = moduleData[0];
loadModule(nextModule, function() {
loadModule(nextModule, function () {
moduleData = moduleData.slice(1);
loadNextModule();
});
@@ -35,11 +33,10 @@ var Loader = (function() {
// This is done after all the modules so we can
// overwrite all the defined styles.
loadFile(config.customCss, function() {
loadFile(config.customCss, function () {
// custom.css loaded. Start all modules.
startModules();
});
}
};
@@ -49,7 +46,7 @@ var Loader = (function() {
/* startModules()
* Loops thru all modules and requests start for every module.
*/
var startModules = function() {
var startModules = function () {
for (var m in moduleObjects) {
var module = moduleObjects[m];
module.start();
@@ -64,7 +61,7 @@ var Loader = (function() {
*
* return array - module data as configured in config
*/
var getAllModules = function() {
var getAllModules = function () {
return config.modules;
};
@@ -73,7 +70,7 @@ var Loader = (function() {
*
* return array - Module information.
*/
var getModuleData = function() {
var getModuleData = function () {
var modules = getAllModules();
var moduleFiles = [];
@@ -97,12 +94,12 @@ var Loader = (function() {
index: m,
identifier: "module_" + m + "_" + module,
name: moduleName,
path: moduleFolder + "/" ,
path: moduleFolder + "/",
file: moduleName + ".js",
position: moduleData.position,
header: moduleData.header,
config: moduleData.config,
classes: (typeof moduleData.classes !== "undefined") ? moduleData.classes + " " + module : module
classes: typeof moduleData.classes !== "undefined" ? moduleData.classes + " " + module : module
});
}
@@ -115,13 +112,13 @@ var Loader = (function() {
* argument callback function - Function called when done.
* argument module object - Information about the module we want to load.
*/
var loadModule = function(module, callback) {
var loadModule = function (module, callback) {
var url = module.path + "/" + module.file;
var afterLoad = function() {
var afterLoad = function () {
var moduleObject = Module.create(module.name);
if (moduleObject) {
bootstrapModule(module, moduleObject, function() {
bootstrapModule(module, moduleObject, function () {
callback();
});
} else {
@@ -132,7 +129,7 @@ var Loader = (function() {
if (loadedModuleFiles.indexOf(url) !== -1) {
afterLoad();
} else {
loadFile(url, function() {
loadFile(url, function () {
loadedModuleFiles.push(url);
afterLoad();
});
@@ -146,16 +143,16 @@ var Loader = (function() {
* argument mObj object - Modules instance.
* argument callback function - Function called when done.
*/
var bootstrapModule = function(module, mObj, callback) {
var bootstrapModule = function (module, mObj, callback) {
Log.info("Bootstrapping module: " + module.name);
mObj.setData(module);
mObj.loadScripts(function() {
mObj.loadScripts(function () {
Log.log("Scripts loaded for: " + module.name);
mObj.loadStyles(function() {
mObj.loadStyles(function () {
Log.log("Styles loaded for: " + module.name);
mObj.loadTranslations(function() {
mObj.loadTranslations(function () {
Log.log("Translations loaded for: " + module.name);
moduleObjects.push(mObj);
callback();
@@ -170,52 +167,58 @@ var Loader = (function() {
* argument fileName string - Path of the file we want to load.
* argument callback function - Function called when done.
*/
var loadFile = function(fileName, callback) {
var loadFile = function (fileName, callback) {
var extension = fileName.slice((Math.max(0, fileName.lastIndexOf(".")) || Infinity) + 1);
switch (extension.toLowerCase()) {
case "js":
Log.log("Load script: " + fileName);
var script = document.createElement("script");
script.type = "text/javascript";
script.src = fileName;
script.onload = function() {
if (typeof callback === "function") {callback();}
};
script.onerror = function() {
console.error("Error on loading script:", fileName);
if (typeof callback === "function") {callback();}
};
case "js":
Log.log("Load script: " + fileName);
var script = document.createElement("script");
script.type = "text/javascript";
script.src = fileName;
script.onload = function () {
if (typeof callback === "function") {
callback();
}
};
script.onerror = function () {
console.error("Error on loading script:", fileName);
if (typeof callback === "function") {
callback();
}
};
document.getElementsByTagName("body")[0].appendChild(script);
break;
case "css":
Log.log("Load stylesheet: " + fileName);
var stylesheet = document.createElement("link");
stylesheet.rel = "stylesheet";
stylesheet.type = "text/css";
stylesheet.href = fileName;
stylesheet.onload = function() {
if (typeof callback === "function") {callback();}
};
stylesheet.onerror = function() {
console.error("Error on loading stylesheet:", fileName);
if (typeof callback === "function") {callback();}
};
document.getElementsByTagName("body")[0].appendChild(script);
break;
case "css":
Log.log("Load stylesheet: " + fileName);
var stylesheet = document.createElement("link");
stylesheet.rel = "stylesheet";
stylesheet.type = "text/css";
stylesheet.href = fileName;
stylesheet.onload = function () {
if (typeof callback === "function") {
callback();
}
};
stylesheet.onerror = function () {
console.error("Error on loading stylesheet:", fileName);
if (typeof callback === "function") {
callback();
}
};
document.getElementsByTagName("head")[0].appendChild(stylesheet);
break;
document.getElementsByTagName("head")[0].appendChild(stylesheet);
break;
}
};
/* Public Methods */
return {
/* loadModules()
* Load all modules as defined in the config.
*/
loadModules: function() {
loadModules: function () {
loadModules();
},
@@ -227,8 +230,7 @@ var Loader = (function() {
* argument module Module Object - the module that calls the loadFile function.
* argument callback function - Function called when done.
*/
loadFile: function(fileName, module, callback) {
loadFile: function (fileName, module, callback) {
if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
Log.log("File already loaded: " + fileName);
callback();

View File

@@ -6,10 +6,10 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
const Log = (function() {
const Log = (function () {
return {
info: Function.prototype.bind.call(console.info, console),
log: Function.prototype.bind.call(console.log, console),
log: Function.prototype.bind.call(console.log, console),
error: Function.prototype.bind.call(console.error, console),
warn: Function.prototype.bind.call(console.warn, console),
group: Function.prototype.bind.call(console.group, console),

View File

@@ -6,8 +6,7 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var MM = (function() {
var MM = (function () {
var modules = [];
/* Private Methods */
@@ -16,10 +15,10 @@ var MM = (function() {
* Create dom objects for all modules that
* are configured for a specific position.
*/
var createDomObjects = function() {
var createDomObjects = function () {
var domCreationPromises = [];
modules.forEach(function(module) {
modules.forEach(function (module) {
if (typeof module.data.position !== "string") {
return;
}
@@ -52,14 +51,16 @@ var MM = (function() {
var domCreationPromise = updateDom(module, 0);
domCreationPromises.push(domCreationPromise);
domCreationPromise.then(function() {
sendNotification("MODULE_DOM_CREATED", null, null, module);
}).catch(Log.error);
domCreationPromise
.then(function () {
sendNotification("MODULE_DOM_CREATED", null, null, module);
})
.catch(Log.error);
});
updateWrapperStates();
Promise.all(domCreationPromises).then(function() {
Promise.all(domCreationPromises).then(function () {
sendNotification("DOM_OBJECTS_CREATED");
});
};
@@ -69,8 +70,8 @@ var MM = (function() {
*
* argument position string - The name of the position.
*/
var selectWrapper = function(position) {
var classes = position.replace("_"," ");
var selectWrapper = function (position) {
var classes = position.replace("_", " ");
var parentWrapper = document.getElementsByClassName(classes);
if (parentWrapper.length > 0) {
var wrapper = parentWrapper[0].getElementsByClassName("container");
@@ -88,7 +89,7 @@ var MM = (function() {
* argument sender Module - The module that sent the notification.
* argument sendTo Module - The module to send the notification to. (optional)
*/
var sendNotification = function(notification, payload, sender, sendTo) {
var sendNotification = function (notification, payload, sender, sendTo) {
for (var m in modules) {
var module = modules[m];
if (module !== sender && (!sendTo || module === sendTo)) {
@@ -105,8 +106,8 @@ var MM = (function() {
*
* return Promise - Resolved when the dom is fully updated.
*/
var updateDom = function(module, speed) {
return new Promise(function(resolve) {
var updateDom = function (module, speed) {
return new Promise(function (resolve) {
var newContentPromise = module.getDom();
var newHeader = module.getHeader();
@@ -115,11 +116,13 @@ var MM = (function() {
newContentPromise = Promise.resolve(newContentPromise);
}
newContentPromise.then(function(newContent) {
var updatePromise = updateDomWithContent(module, speed, newHeader, newContent);
newContentPromise
.then(function (newContent) {
var updatePromise = updateDomWithContent(module, speed, newHeader, newContent);
updatePromise.then(resolve).catch(Log.error);
}).catch(Log.error);
updatePromise.then(resolve).catch(Log.error);
})
.catch(Log.error);
});
};
@@ -133,8 +136,8 @@ var MM = (function() {
*
* return Promise - Resolved when the module dom has been updated.
*/
var updateDomWithContent = function(module, speed, newHeader, newContent) {
return new Promise(function(resolve) {
var updateDomWithContent = function (module, speed, newHeader, newContent) {
return new Promise(function (resolve) {
if (module.hidden || !speed) {
updateModuleContent(module, newHeader, newContent);
resolve();
@@ -152,7 +155,7 @@ var MM = (function() {
return;
}
hideModule(module, speed / 2, function() {
hideModule(module, speed / 2, function () {
updateModuleContent(module, newHeader, newContent);
if (!module.hidden) {
showModule(module, speed / 2);
@@ -171,7 +174,7 @@ var MM = (function() {
*
* return bool - Does the module need an update?
*/
var moduleNeedsUpdate = function(module, newHeader, newContent) {
var moduleNeedsUpdate = function (module, newHeader, newContent) {
var moduleWrapper = document.getElementById(module.identifier);
if (moduleWrapper === null) {
return false;
@@ -201,9 +204,11 @@ var MM = (function() {
* argument newHeader String - The new header that is generated.
* argument newContent Domobject - The new content that is generated.
*/
var updateModuleContent = function(module, newHeader, newContent) {
var updateModuleContent = function (module, newHeader, newContent) {
var moduleWrapper = document.getElementById(module.identifier);
if (moduleWrapper === null) {return;}
if (moduleWrapper === null) {
return;
}
var headerWrapper = moduleWrapper.getElementsByClassName("module-header");
var contentWrapper = moduleWrapper.getElementsByClassName("module-content");
@@ -221,7 +226,7 @@ var MM = (function() {
* argument speed Number - The speed of the hide animation.
* argument callback function - Called when the animation is done.
*/
var hideModule = function(module, speed, callback, options) {
var hideModule = function (module, speed, callback, options) {
options = options || {};
// set lockString if set in options.
@@ -238,7 +243,7 @@ var MM = (function() {
moduleWrapper.style.opacity = 0;
clearTimeout(module.showHideTimer);
module.showHideTimer = setTimeout(function() {
module.showHideTimer = setTimeout(function () {
// To not take up any space, we just make the position absolute.
// since it's fade out anyway, we can see it lay above or
// below other modules. This works way better than adjusting
@@ -247,11 +252,15 @@ var MM = (function() {
updateWrapperStates();
if (typeof callback === "function") { callback(); }
if (typeof callback === "function") {
callback();
}
}, speed);
} else {
// invoke callback even if no content, issue 1308
if (typeof callback === "function") { callback(); }
if (typeof callback === "function") {
callback();
}
}
};
@@ -262,13 +271,13 @@ var MM = (function() {
* argument speed Number - The speed of the show animation.
* argument callback function - Called when the animation is done.
*/
var showModule = function(module, speed, callback, options) {
var showModule = function (module, speed, callback, options) {
options = options || {};
// remove lockString if set in options.
if (options.lockString) {
var index = module.lockStrings.indexOf(options.lockString);
if ( index !== -1) {
if (index !== -1) {
module.lockStrings.splice(index, 1);
}
}
@@ -301,12 +310,16 @@ var MM = (function() {
moduleWrapper.style.opacity = 1;
clearTimeout(module.showHideTimer);
module.showHideTimer = setTimeout(function() {
if (typeof callback === "function") { callback(); }
module.showHideTimer = setTimeout(function () {
if (typeof callback === "function") {
callback();
}
}, speed);
} else {
// invoke callback
if (typeof callback === "function") { callback(); }
if (typeof callback === "function") {
callback();
}
}
};
@@ -321,15 +334,15 @@ var MM = (function() {
* an ugly top margin. By using this function, the top bar will be hidden if the
* update notification is not visible.
*/
var updateWrapperStates = function() {
var updateWrapperStates = function () {
var positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
positions.forEach(function(position) {
positions.forEach(function (position) {
var wrapper = selectWrapper(position);
var moduleWrappers = wrapper.getElementsByClassName("module");
var showWrapper = false;
Array.prototype.forEach.call(moduleWrappers, function(moduleWrapper) {
Array.prototype.forEach.call(moduleWrappers, function (moduleWrapper) {
if (moduleWrapper.style.position === "" || moduleWrapper.style.position === "static") {
showWrapper = true;
}
@@ -342,7 +355,7 @@ var MM = (function() {
/* loadConfig()
* Loads the core config and combines it with de system defaults.
*/
var loadConfig = function() {
var loadConfig = function () {
// FIXME: Think about how to pass config around without breaking tests
/* eslint-disable */
if (typeof config === "undefined") {
@@ -360,8 +373,7 @@ var MM = (function() {
*
* argument modules array - Array of modules.
*/
var setSelectionMethodsForModules = function(modules) {
var setSelectionMethodsForModules = function (modules) {
/* withClass(className)
* calls modulesByClass to filter modules with the specified classes.
*
@@ -369,7 +381,7 @@ var MM = (function() {
*
* return array - Filtered collection of modules.
*/
var withClass = function(className) {
var withClass = function (className) {
return modulesByClass(className, true);
};
@@ -380,7 +392,7 @@ var MM = (function() {
*
* return array - Filtered collection of modules.
*/
var exceptWithClass = function(className) {
var exceptWithClass = function (className) {
return modulesByClass(className, false);
};
@@ -392,13 +404,13 @@ var MM = (function() {
*
* return array - Filtered collection of modules.
*/
var modulesByClass = function(className, include) {
var modulesByClass = function (className, include) {
var searchClasses = className;
if (typeof className === "string") {
searchClasses = className.split(" ");
}
var newModules = modules.filter(function(module) {
var newModules = modules.filter(function (module) {
var classes = module.data.classes.toLowerCase().split(" ");
for (var c in searchClasses) {
@@ -422,8 +434,8 @@ var MM = (function() {
*
* return array - Filtered collection of modules.
*/
var exceptModule = function(module) {
var newModules = modules.filter(function(mod) {
var exceptModule = function (module) {
var newModules = modules.filter(function (mod) {
return mod.identifier !== module.identifier;
});
@@ -436,16 +448,24 @@ var MM = (function() {
*
* argument callback function - The function to execute with the module as an argument.
*/
var enumerate = function(callback) {
modules.map(function(module) {
var enumerate = function (callback) {
modules.map(function (module) {
callback(module);
});
};
if (typeof modules.withClass === "undefined") { Object.defineProperty(modules, "withClass", {value: withClass, enumerable: false}); }
if (typeof modules.exceptWithClass === "undefined") { Object.defineProperty(modules, "exceptWithClass", {value: exceptWithClass, enumerable: false}); }
if (typeof modules.exceptModule === "undefined") { Object.defineProperty(modules, "exceptModule", {value: exceptModule, enumerable: false}); }
if (typeof modules.enumerate === "undefined") { Object.defineProperty(modules, "enumerate", {value: enumerate, enumerable: false}); }
if (typeof modules.withClass === "undefined") {
Object.defineProperty(modules, "withClass", { value: withClass, enumerable: false });
}
if (typeof modules.exceptWithClass === "undefined") {
Object.defineProperty(modules, "exceptWithClass", { value: exceptWithClass, enumerable: false });
}
if (typeof modules.exceptModule === "undefined") {
Object.defineProperty(modules, "exceptModule", { value: exceptModule, enumerable: false });
}
if (typeof modules.enumerate === "undefined") {
Object.defineProperty(modules, "enumerate", { value: enumerate, enumerable: false });
}
};
return {
@@ -454,7 +474,7 @@ var MM = (function() {
/* init()
* Main init method.
*/
init: function() {
init: function () {
Log.info("Initializing MagicMirror.");
loadConfig();
Translator.loadCoreTranslations(config.language);
@@ -466,7 +486,7 @@ var MM = (function() {
*
* argument moduleObjects array<Module> - All module instances.
*/
modulesStarted: function(moduleObjects) {
modulesStarted: function (moduleObjects) {
modules = [];
for (var m in moduleObjects) {
var module = moduleObjects[m];
@@ -486,7 +506,7 @@ var MM = (function() {
* argument payload mixed - The payload of the notification.
* argument sender Module - The module that sent the notification.
*/
sendNotification: function(notification, payload, sender) {
sendNotification: function (notification, payload, sender) {
if (arguments.length < 3) {
Log.error("sendNotification: Missing arguments.");
return;
@@ -512,7 +532,7 @@ var MM = (function() {
* argument module Module - The module that needs an update.
* argument speed Number - The number of microseconds for the animation. (optional)
*/
updateDom: function(module, speed) {
updateDom: function (module, speed) {
if (!(module instanceof Module)) {
Log.error("updateDom: Sender should be a module.");
return;
@@ -527,7 +547,7 @@ var MM = (function() {
*
* return array - A collection of all modules currently active.
*/
getModules: function() {
getModules: function () {
setSelectionMethodsForModules(modules);
return modules;
},
@@ -540,7 +560,7 @@ var MM = (function() {
* argument callback function - Called when the animation is done.
* argument options object - Optional settings for the hide method.
*/
hideModule: function(module, speed, callback, options) {
hideModule: function (module, speed, callback, options) {
module.hidden = true;
hideModule(module, speed, callback, options);
},
@@ -553,18 +573,17 @@ var MM = (function() {
* argument callback function - Called when the animation is done.
* argument options object - Optional settings for the hide method.
*/
showModule: function(module, speed, callback, options) {
showModule: function (module, speed, callback, options) {
// do not change module.hidden yet, only if we really show it later
showModule(module, speed, callback, options);
}
};
})();
// Add polyfill for Object.assign.
if (typeof Object.assign !== "function") {
(function() {
Object.assign = function(target) {
(function () {
Object.assign = function (target) {
"use strict";
if (target === undefined || target === null) {
throw new TypeError("Cannot convert undefined or null to object");

View File

@@ -7,7 +7,6 @@
* MIT Licensed.
*/
var Module = Class.extend({
/*********************************************************
* All methods (and properties) below can be subclassed. *
*********************************************************/
@@ -80,7 +79,7 @@ var Module = Class.extend({
*/
getDom: function () {
var self = this;
return new Promise(function(resolve) {
return new Promise(function (resolve) {
var div = document.createElement("div");
var template = self.getTemplate();
var templateData = self.getTemplateData();
@@ -126,7 +125,7 @@ var Module = Class.extend({
* return string - The template string of filename.
*/
getTemplate: function () {
return "<div class=\"normal\">" + this.name + "</div><div class=\"small dimmed\">" + this.identifier + "</div>";
return '<div class="normal">' + this.name + '</div><div class="small dimmed">' + this.identifier + "</div>";
},
/* getTemplateData()
@@ -161,18 +160,18 @@ var Module = Class.extend({
* @returns Nunjucks Environment
*/
nunjucksEnvironment: function() {
nunjucksEnvironment: function () {
if (this._nunjucksEnvironment !== null) {
return this._nunjucksEnvironment;
}
var self = this;
this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), {async: true}), {
this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), { async: true }), {
trimBlocks: true,
lstripBlocks: true
});
this._nunjucksEnvironment.addFilter("translate", function(str) {
this._nunjucksEnvironment.addFilter("translate", function (str) {
return self.translate(str);
});
@@ -313,7 +312,9 @@ var Module = Class.extend({
// The variable `first` will contain the first
// defined translation after the following line.
for (var first in translations) { break; }
for (var first in translations) {
break;
}
if (translations) {
var translationFile = translations[lang] || undefined;
@@ -337,11 +338,11 @@ var Module = Class.extend({
* Request the translation for a given key with optional variables and default value.
*
* argument key string - The key of the string to translate
* argument defaultValueOrVariables string/object - The default value or variables for translating. (Optional)
* argument defaultValue string - The default value with variables. (Optional)
* argument defaultValueOrVariables string/object - The default value or variables for translating. (Optional)
* argument defaultValue string - The default value with variables. (Optional)
*/
translate: function (key, defaultValueOrVariables, defaultValue) {
if(typeof defaultValueOrVariables === "object") {
if (typeof defaultValueOrVariables === "object") {
return Translator.translate(this, key, defaultValueOrVariables) || defaultValue || "";
}
return Translator.translate(this, key) || defaultValueOrVariables || "";
@@ -386,17 +387,22 @@ var Module = Class.extend({
hide: function (speed, callback, options) {
if (typeof callback === "object") {
options = callback;
callback = function () { };
callback = function () {};
}
callback = callback || function () { };
callback = callback || function () {};
options = options || {};
var self = this;
MM.hideModule(self, speed, function () {
self.suspend();
callback();
}, options);
MM.hideModule(
self,
speed,
function () {
self.suspend();
callback();
},
options
);
},
/* showModule(module, speed, callback)
@@ -409,24 +415,28 @@ var Module = Class.extend({
show: function (speed, callback, options) {
if (typeof callback === "object") {
options = callback;
callback = function () { };
callback = function () {};
}
callback = callback || function () { };
callback = callback || function () {};
options = options || {};
var self = this;
MM.showModule(this, speed, function () {
self.resume();
callback;
}, options);
MM.showModule(
this,
speed,
function () {
self.resume();
callback;
},
options
);
}
});
Module.definitions = {};
Module.create = function (name) {
// Make sure module definition is available.
if (!Module.definitions[name]) {
return;
@@ -442,11 +452,11 @@ Module.create = function (name) {
};
/* cmpVersions(a,b)
* Compare two semantic version numbers and return the difference.
*
* argument a string - Version number a.
* argument a string - Version number b.
*/
* Compare two semantic version numbers and return the difference.
*
* argument a string - Version number a.
* argument a string - Version number b.
*/
function cmpVersions(a, b) {
var i, diff;
var regExStrip0 = /(\.0+)+$/;
@@ -464,7 +474,6 @@ function cmpVersions(a, b) {
}
Module.register = function (name, moduleDefinition) {
if (moduleDefinition.requiresVersion) {
Log.log("Check MagicMirror version for module '" + name + "' - Minimum version: " + moduleDefinition.requiresVersion + " - Current version: " + window.version);
if (cmpVersions(window.version, moduleDefinition.requiresVersion) >= 0) {

View File

@@ -8,16 +8,16 @@ const Class = require("./class.js");
const express = require("express");
var NodeHelper = Class.extend({
init: function() {
init: function () {
console.log("Initializing new module helper ...");
},
loaded: function(callback) {
loaded: function (callback) {
console.log("Module helper loaded: " + this.name);
callback();
},
start: function() {
start: function () {
console.log("Starting module helper: " + this.name);
},
@@ -27,7 +27,7 @@ var NodeHelper = Class.extend({
* gracefully exit the module.
*
*/
stop: function() {
stop: function () {
console.log("Stopping module helper: " + this.name);
},
@@ -37,7 +37,7 @@ var NodeHelper = Class.extend({
* argument notification string - The identifier of the notification.
* argument payload mixed - The payload of the notification.
*/
socketNotificationReceived: function(notification, payload) {
socketNotificationReceived: function (notification, payload) {
console.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
},
@@ -46,7 +46,7 @@ var NodeHelper = Class.extend({
*
* argument name string - Module name.
*/
setName: function(name) {
setName: function (name) {
this.name = name;
},
@@ -55,7 +55,7 @@ var NodeHelper = Class.extend({
*
* argument path string - Module path.
*/
setPath: function(path) {
setPath: function (path) {
this.path = path;
},
@@ -65,7 +65,7 @@ var NodeHelper = Class.extend({
* argument notification string - The identifier of the notification.
* argument payload mixed - The payload of the notification.
*/
sendSocketNotification: function(notification, payload) {
sendSocketNotification: function (notification, payload) {
this.io.of(this.name).emit(notification, payload);
},
@@ -75,7 +75,7 @@ var NodeHelper = Class.extend({
*
* argument app Express app - The Express app object.
*/
setExpressApp: function(app) {
setExpressApp: function (app) {
this.expressApp = app;
var publicPath = this.path + "/public";
@@ -88,16 +88,16 @@ var NodeHelper = Class.extend({
*
* argument io Socket.io - The Socket io object.
*/
setSocketIO: function(io) {
setSocketIO: function (io) {
var self = this;
self.io = io;
console.log("Connecting socket for: " + this.name);
var namespace = this.name;
io.of(namespace).on("connection", function(socket) {
io.of(namespace).on("connection", function (socket) {
// add a catch all event.
var onevent = socket.onevent;
socket.onevent = function(packet) {
socket.onevent = function (packet) {
var args = packet.data || [];
onevent.call(this, packet); // original call
packet.data = ["*"].concat(args);
@@ -105,7 +105,7 @@ var NodeHelper = Class.extend({
};
// register catch all.
socket.on("*", function(notification, payload) {
socket.on("*", function (notification, payload) {
if (notification !== "*") {
//console.log('received message in namespace: ' + namespace);
self.socketNotificationReceived(notification, payload);
@@ -115,9 +115,11 @@ var NodeHelper = Class.extend({
}
});
NodeHelper.create = function(moduleDefinition) {
NodeHelper.create = function (moduleDefinition) {
return NodeHelper.extend(moduleDefinition);
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = NodeHelper;}
if (typeof module !== "undefined") {
module.exports = NodeHelper;
}

View File

@@ -13,21 +13,20 @@ var fs = require("fs");
var helmet = require("helmet");
var Utils = require(__dirname + "/utils.js");
var Server = function(config, callback) {
var Server = function (config, callback) {
var port = config.port;
if (process.env.MM_PORT) {
port = process.env.MM_PORT;
}
var server = null;
if(config.useHttps){
if (config.useHttps) {
var options = {
key: fs.readFileSync(config.httpsPrivateKey),
cert: fs.readFileSync(config.httpsCertificate)
};
server = require("https").Server(options, app);
}else{
} else {
server = require("http").Server(app);
}
var io = require("socket.io")(server);
@@ -40,8 +39,8 @@ var Server = function(config, callback) {
console.info(Utils.colors.warn("You're using a full whitelist configuration to allow for all IPs"));
}
app.use(function(req, res, next) {
var result = ipfilter(config.ipWhitelist, {mode: config.ipWhitelist.length === 0 ? "deny" : "allow", log: false})(req, res, function(err) {
app.use(function (req, res, next) {
var result = ipfilter(config.ipWhitelist, { mode: config.ipWhitelist.length === 0 ? "deny" : "allow", log: false })(req, res, function (err) {
if (err === undefined) {
return next();
}
@@ -59,20 +58,20 @@ var Server = function(config, callback) {
app.use(directory, express.static(path.resolve(global.root_path + directory)));
}
app.get("/version", function(req,res) {
app.get("/version", function (req, res) {
res.send(global.version);
});
app.get("/config", function(req,res) {
app.get("/config", function (req, res) {
res.send(config);
});
app.get("/", function(req, res) {
var html = fs.readFileSync(path.resolve(global.root_path + "/index.html"), {encoding: "utf8"});
app.get("/", function (req, res) {
var html = fs.readFileSync(path.resolve(global.root_path + "/index.html"), { encoding: "utf8" });
html = html.replace("#VERSION#", global.version);
var configFile = "config/config.js";
if (typeof(global.configuration_file) !== "undefined") {
if (typeof global.configuration_file !== "undefined") {
configFile = global.configuration_file;
}
html = html.replace("#CONFIG_FILE#", configFile);

View File

@@ -6,7 +6,7 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var MMSocket = function(moduleName) {
var MMSocket = function (moduleName) {
var self = this;
if (typeof moduleName !== "string") {
@@ -17,16 +17,16 @@ var MMSocket = function(moduleName) {
// Private Methods
var base = "/";
if ((typeof config !== "undefined") && (typeof config.basePath !== "undefined")) {
if (typeof config !== "undefined" && typeof config.basePath !== "undefined") {
base = config.basePath;
}
self.socket = io("/" + self.moduleName, {
path: base + "socket.io"
});
var notificationCallback = function() {};
var notificationCallback = function () {};
var onevent = self.socket.onevent;
self.socket.onevent = function(packet) {
self.socket.onevent = function (packet) {
var args = packet.data || [];
onevent.call(this, packet); // original call
packet.data = ["*"].concat(args);
@@ -34,18 +34,18 @@ var MMSocket = function(moduleName) {
};
// register catch all.
self.socket.on("*", function(notification, payload) {
self.socket.on("*", function (notification, payload) {
if (notification !== "*") {
notificationCallback(notification, payload);
}
});
// Public Methods
this.setNotificationCallback = function(callback) {
this.setNotificationCallback = function (callback) {
notificationCallback = callback;
};
this.sendNotification = function(notification, payload) {
this.sendNotification = function (notification, payload) {
if (typeof payload === "undefined") {
payload = {};
}

View File

@@ -6,8 +6,7 @@
* By Christopher Fenner https://github.com/CFenner
* MIT Licensed.
*/
var Translator = (function() {
var Translator = (function () {
/* loadJSON(file, callback)
* Load a JSON file via XHR.
*
@@ -62,7 +61,7 @@ var Translator = (function() {
currentChar = str[i];
nextChar = str[i + 1];
if (!insideComment && currentChar === "\"") {
if (!insideComment && currentChar === '"') {
var escaped = str[i - 1] === "\\" && str[i - 2] !== "\\";
if (!escaped) {
insideString = !insideString;
@@ -119,7 +118,7 @@ var Translator = (function() {
* argument key string - The key of the text to translate.
* argument variables - The variables to use within the translation template (optional)
*/
translate: function(module, key, variables) {
translate: function (module, key, variables) {
variables = variables || {}; //Empty object by default
// Combines template and variables like:
@@ -127,18 +126,18 @@ var Translator = (function() {
// variables: {timeToWait: "2 hours", work: "painting"}
// to: "Please wait for 2 hours before continuing with painting."
function createStringFromTemplate(template, variables) {
if(Object.prototype.toString.call(template) !== "[object String]") {
if (Object.prototype.toString.call(template) !== "[object String]") {
return template;
}
if(variables.fallback && !template.match(new RegExp("{.+}"))) {
if (variables.fallback && !template.match(new RegExp("{.+}"))) {
template = variables.fallback;
}
return template.replace(new RegExp("{([^}]+)}", "g"), function(_unused, varName){
return variables[varName] || "{"+varName+"}";
return template.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
return variables[varName] || "{" + varName + "}";
});
}
if(this.translations[module.name] && key in this.translations[module.name]) {
if (this.translations[module.name] && key in this.translations[module.name]) {
// Log.log("Got translation for " + key + " from module translation: ");
return createStringFromTemplate(this.translations[module.name][key], variables);
}
@@ -169,7 +168,7 @@ var Translator = (function() {
* argument isFallback boolean - Flag to indicate fallback translations.
* argument callback function - Function called when done.
*/
load: function(module, file, isFallback, callback) {
load: function (module, file, isFallback, callback) {
if (!isFallback) {
Log.log(module.name + " - Load translation: " + file);
} else {
@@ -177,8 +176,8 @@ var Translator = (function() {
}
var self = this;
if(!this.translationsFallback[module.name]) {
loadJSON(module.file(file), function(json) {
if (!this.translationsFallback[module.name]) {
loadJSON(module.file(file), function (json) {
if (!isFallback) {
self.translations[module.name] = json;
} else {
@@ -196,12 +195,12 @@ var Translator = (function() {
*
* argument lang String - The language identifier of the core language.
*/
loadCoreTranslations: function(lang) {
loadCoreTranslations: function (lang) {
var self = this;
if (lang in translations) {
Log.log("Loading core translation file: " + translations[lang]);
loadJSON(translations[lang], function(translations) {
loadJSON(translations[lang], function (translations) {
self.coreTranslations = translations;
});
} else {
@@ -215,19 +214,21 @@ var Translator = (function() {
* Load the core translations fallback.
* The first language defined in translations.js will be used.
*/
loadCoreTranslationsFallback: function() {
loadCoreTranslationsFallback: function () {
var self = this;
// The variable `first` will contain the first
// defined translation after the following line.
for (var first in translations) {break;}
for (var first in translations) {
break;
}
if (first) {
Log.log("Loading core translation fallback file: " + translations[first]);
loadJSON(translations[first], function(translations) {
loadJSON(translations[first], function (translations) {
self.coreTranslationsFallback = translations;
});
}
},
}
};
})();

View File

@@ -14,4 +14,6 @@ var Utils = {
}
};
if (typeof module !== "undefined") {module.exports = Utils;}
if (typeof module !== "undefined") {
module.exports = Utils;
}