From 3ba16f17734c7da7aa8505943dd03d155bb732e0 Mon Sep 17 00:00:00 2001 From: Thomas Bachmann Date: Wed, 11 Jan 2017 11:32:20 +0100 Subject: [PATCH] Merge remote-tracking branch 'MichMich/develop' --- .gitignore | 1 + CHANGELOG.md | 12 ++++- LICENSE.md | 2 +- installers/raspberry.sh | 3 ++ js/app.js | 54 ++++++++++++++--------- js/electron.js | 3 +- modules/README.md | 15 +++++++ modules/default/newsfeed/fetcher.js | 7 ++- modules/node_modules/node_helper/index.js | 5 +++ package.json | 2 +- 10 files changed, 79 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 67feae54..1e17ef8b 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ Temporary Items # Ignore all modules except the default modules. /modules/** +!/modules/default !/modules/default/** !/modules/README.md** diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb6b70a..65119703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,19 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [develop] - release date to be defined +## [2.1.1] - Unreleased + +### Changed +- Installer: Use init config.js from config.js.sample. + +### Added +- Add loaded function to modules, providing an async callback. - Made default newsfeed module aware of gesture events from [MMM-Gestures](https://github.com/thobach/MMM-Gestures) +### Fixed +- Update .gitignore to not ignore default modules folder. +- Remove white flash on boot up. + ## [2.1.0] - 2016-12-31 **Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install` diff --git a/LICENSE.md b/LICENSE.md index d4765af2..09ac7e6f 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ The MIT License (MIT) ===================== -Copyright © 2016 Michael Teeuw +Copyright © 2016-2017 Michael Teeuw Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/installers/raspberry.sh b/installers/raspberry.sh index cd995a1e..b970d02e 100644 --- a/installers/raspberry.sh +++ b/installers/raspberry.sh @@ -113,6 +113,9 @@ else exit; fi +# Use sample config for start MagicMirror +cp config/config.js.sample config/config.js + # Check if plymouth is installed (default with PIXEL desktop environment), then install custom splashscreen. echo -e "\e[96mCheck plymouth installation ...\e[0m" if command_exists plymouth; then diff --git a/js/app.js b/js/app.js index ba6cd1a9..91149906 100644 --- a/js/app.js +++ b/js/app.js @@ -66,7 +66,7 @@ var App = function() { * * argument module string - The name of the module (including subpath). */ - var loadModule = function(module) { + var loadModule = function(module, callback) { var elements = module.split("/"); var moduleName = elements[elements.length - 1]; @@ -103,6 +103,10 @@ var App = function() { m.setName(moduleName); m.setPath(path.resolve(moduleFolder)); nodeHelpers.push(m); + + m.loaded(callback); + } else { + callback(); } }; @@ -111,14 +115,24 @@ var App = function() { * * argument module string - The name of the module (including subpath). */ - var loadModules = function(modules) { + var loadModules = function(modules, callback) { console.log("Loading module helpers ..."); - for (var m in modules) { - loadModule(modules[m]); - } + var loadNextModule = function() { + if (modules.length > 0) { + var nextModule = modules[0]; + loadModule(nextModule, function() { + modules = modules.slice(1); + loadNextModule(); + }); + } else { + // All modules are loaded + console.log("All module helpers loaded."); + callback(); + } + }; - console.log("All module helpers loaded."); + loadNextModule(); }; /* cmpVersions(a,b) @@ -164,24 +178,24 @@ var App = function() { } } - loadModules(modules); + loadModules(modules, function() { + var server = new Server(config, function(app, io) { + console.log("Server started ..."); - var server = new Server(config, function(app, io) { - console.log("Server started ..."); + for (var h in nodeHelpers) { + var nodeHelper = nodeHelpers[h]; + nodeHelper.setExpressApp(app); + nodeHelper.setSocketIO(io); + nodeHelper.start(); + } - for (var h in nodeHelpers) { - var nodeHelper = nodeHelpers[h]; - nodeHelper.setExpressApp(app); - nodeHelper.setSocketIO(io); - nodeHelper.start(); - } + console.log("Sockets connected & modules started ..."); - console.log("Sockets connected & modules started ..."); - - if (typeof callback === "function") { - callback(config); - } + if (typeof callback === "function") { + callback(config); + } + }); }); }); }; diff --git a/js/electron.js b/js/electron.js index 173abe68..1f16092b 100644 --- a/js/electron.js +++ b/js/electron.js @@ -28,7 +28,8 @@ function createWindow() { webPreferences: { nodeIntegration: false, zoomFactor: config.zoom - } + }, + backgroundColor: "#000000" } // DEPRECATED: "kioskmode" backwards compatibility, to be removed diff --git a/modules/README.md b/modules/README.md index 42a31dfa..03664b15 100644 --- a/modules/README.md +++ b/modules/README.md @@ -96,6 +96,21 @@ requiresVersion: "2.1.0", ####`init()` This method is called when a module gets instantiated. In most cases you do not need to subclass this method. +####`loaded(callback)` + +*Introduced in version: 2.1.1.* + +This method is called when a module is loaded. Subsequent modules in the config are not yet loaded. The `callback` function MUST be called when the module is done loading. In most cases you do not need to subclass this method. + +**Example:** +````javascript +loaded: function(callback) { + this.finishLoading(); + Log.log(this.name + ' is loaded!'); + callback(); +} +```` + ####`start()` This method is called when all modules are loaded an the system is ready to boot up. Keep in mind that the dom object for the module is not yet created. The start method is a perfect place to define any additional module properties: diff --git a/modules/default/newsfeed/fetcher.js b/modules/default/newsfeed/fetcher.js index b7511de9..f4fb44d9 100644 --- a/modules/default/newsfeed/fetcher.js +++ b/modules/default/newsfeed/fetcher.js @@ -85,7 +85,12 @@ var Fetcher = function(url, reloadInterval, encoding) { nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]); headers = {"User-Agent": "Mozilla/5.0 (Node.js "+ nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)"} - request({uri: url, encoding: null, headers: headers}).pipe(iconv.decodeStream(encoding)).pipe(parser); + request({uri: url, encoding: null, headers: headers}) + .on("error", function(error) { + fetchFailedCallback(self, error); + scheduleTimer(); + }) + .pipe(iconv.decodeStream(encoding)).pipe(parser); }; diff --git a/modules/node_modules/node_helper/index.js b/modules/node_modules/node_helper/index.js index dc57ef36..bdeccf8b 100644 --- a/modules/node_modules/node_helper/index.js +++ b/modules/node_modules/node_helper/index.js @@ -14,6 +14,11 @@ NodeHelper = Class.extend({ console.log("Initializing new module helper ..."); }, + loaded: function(callback) { + console.log("Module helper loaded: " + this.name); + callback(); + }, + start: function() { console.log("Staring module helper: " + this.name); }, diff --git a/package.json b/package.json index 118c9837..54c60f92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "magicmirror", - "version": "2.1.0", + "version": "2.1.1", "description": "A modular interface for smart mirrors.", "main": "js/electron.js", "scripts": {