Merge branch 'develop' into russian_translations2

This commit is contained in:
Sergey Morozov 2017-01-06 11:24:52 -08:00 committed by GitHub
commit d019f88e26
6 changed files with 62 additions and 22 deletions

View File

@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [2.1.1] - Unreleased
### Added
- Add loaded function to modules, providing an async callback.
- Russian Translation
### Fixed

View File

@ -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();
}
};
loadNextModule();
};
/* cmpVersions(a,b)
@ -164,8 +178,7 @@ var App = function() {
}
}
loadModules(modules);
loadModules(modules, function() {
var server = new Server(config, function(app, io) {
console.log("Server started ...");
@ -184,6 +197,7 @@ var App = function() {
});
});
});
};
};

View File

@ -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:

View File

@ -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);
};

View File

@ -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);
},

View File

@ -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": {