Skip to content

Commit b2bc43d

Browse files
authored
Merge pull request #1113 from MichMich/develop
Release v2.2.0.
2 parents b799609 + cb12e54 commit b2bc43d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+8251
-121
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"max-len": ["error", 250],
66
"curly": "error",
77
"camelcase": ["error", {"properties": "never"}],
8-
"no-trailing-spaces": ["error"],
8+
"no-trailing-spaces": ["error", {"ignoreComments": false }],
99
"no-irregular-whitespace": ["error"]
1010
},
1111
"env": {

CHANGELOG.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [2.2.0] - 2018-01-01
6+
7+
**Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install`
8+
9+
### Changed
10+
- Calender week is now handled with a variable translation in order to move number language specific.
11+
- Reverted the Electron dependency back to 1.4.15 since newer version don't seem to work on the Raspberry Pi very well.
12+
13+
### Added
14+
- Add option to use [Nunjucks](https://mozilla.github.io/nunjucks/) templates in modules. (See `helloworld` module as an example.)
15+
- Add Bulgarian translations for MagicMirror² and Alert module.
16+
- Add graceful shutdown of modules by calling `stop` function of each `node_helper` on SIGINT before exiting.
17+
- Link update subtext to Github diff of current version versus tracking branch.
18+
- Add Catalan translation.
19+
- Add ability to filter out newsfeed items based on prohibited words found in title (resolves #1071)
20+
- Add options to truncate description support of a feed in newsfeed module
21+
- Add reloadInterval option for particular feed in newsfeed module
22+
- Add no-cache entries of HTTP headers in newsfeed module (fetcher)
23+
- Add Czech translation.
24+
- Add option for decimal symbols other than the decimal point for temperature values in both default weather modules: WeatherForecast and CurrentWeather.
25+
26+
### Updated
27+
28+
### Fixed
29+
- Fixed issue with calendar module showing more than `maximumEntries` allows
30+
- WeatherForecast and CurrentWeather are now using HTTPS instead of HTTP
31+
- Correcting translation for Indonesian language
32+
- Fix issue where calendar icons wouldn't align correctly
33+
534
## [2.1.3] - 2017-10-01
635

736
**Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install`
@@ -29,7 +58,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2958
- Changed 'default.js' - listen on all attached interfaces by default.
3059
- Add execution of `npm list` after the test are ran in Travis CI.
3160
- Change hooks for the vendors e2e tests.
32-
- Add log when clientonly failed on starting.
61+
- Add log when clientonly failed on starting.
3362
- Add warning color when are using full ip whitelist.
3463
- Set version of the `express-ipfilter` on 0.3.1.
3564

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The following properties can be configured:
122122
| **Option** | **Description** |
123123
| --- | --- |
124124
| `port` | The port on which the MagicMirror² server will run on. The default value is `8080`. |
125-
| `address` | The ip address the accept connections. The default open bind `::` is IPv6 is available or `0.0.0.0` IPv4 run on. Example config: `192.168.10.100`. |
125+
| `address` | The ip address the accept connections. The default open bind `localhost`. Example config: `192.168.10.100`. |
126126
| `ipWhitelist` | The list of IPs from which you are allowed to access the MagicMirror². The default value is `["127.0.0.1", "::ffff:127.0.0.1", "::1"]`. It is possible to specify IPs with subnet masks (`["127.0.0.1", "127.0.0.1/24"]`) or define ip ranges (`["127.0.0.1", ["192.168.0.1", "192.168.0.100"]]`). Set `[]` to allow all IP addresses. For more information about how configure this directive see the [follow post ipWhitelist HowTo](https://forum.magicmirror.builders/topic/1326/ipwhitelist-howto) |
127127
| `zoom` | This allows to scale the mirror contents with a given zoom factor. The default value is `1.0`|
128128
| `language` | The language of the interface. (Note: Not all elements will be localized.) Possible values are `en`, `nl`, `ru`, `fr`, etc., but the default value is `en`. |

fonts/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fonts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"url": "https://github.com/MichMich/MagicMirror/issues"
1111
},
1212
"dependencies": {
13-
"roboto-fontface": "^0.8.0"
13+
"roboto-fontface": "^0.8.0"
1414
}
1515
}

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
</div>
3939
<div class="region fullscreen above"><div class="container"></div></div>
4040
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
41+
<script type="text/javascript" src="vendor/node_modules/nunjucks/browser/nunjucks.min.js"></script>
4142
<script type="text/javascript" src="js/defaults.js"></script>
4243
<script type="text/javascript" src="#CONFIG_FILE#"></script>
4344
<script type="text/javascript" src="vendor/vendor.js"></script>

js/app.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,33 @@ var App = function() {
236236
});
237237
});
238238
};
239+
240+
/* stop()
241+
* This methods stops the core app.
242+
* This calls each node_helper's STOP() function, if it exists.
243+
* Added to fix #1056
244+
*/
245+
this.stop = function() {
246+
for (var h in nodeHelpers) {
247+
var nodeHelper = nodeHelpers[h];
248+
if (typeof nodeHelper.stop === "function") {
249+
nodeHelper.stop();
250+
}
251+
}
252+
};
253+
254+
/* Listen for SIGINT signal and call stop() function.
255+
*
256+
* Added to fix #1056
257+
* Note: this is only used if running `server-only`. Otherwise
258+
* this.stop() is called by app.on("before-quit"... in `electron.js`
259+
*/
260+
process.on("SIGINT", () => {
261+
console.log("[SIGINT] Received. Shutting down server...");
262+
setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds
263+
this.stop();
264+
process.exit(0);
265+
});
239266
};
240267

241268
module.exports = new App();

js/electron.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ app.on("activate", function() {
9696
}
9797
});
9898

99+
/* This method will be called when SIGINT is received and will call
100+
* each node_helper's stop function if it exists. Added to fix #1056
101+
*
102+
* Note: this is only used if running Electron. Otherwise
103+
* core.stop() is called by process.on("SIGINT"... in `app.js`
104+
*/
105+
app.on("before-quit", (event) => {
106+
console.log("Shutting down server...");
107+
event.preventDefault();
108+
setTimeout(() => { process.exit(0); }, 3000); // Force-quit after 3 seconds.
109+
core.stop();
110+
process.exit(0);
111+
});
112+
99113
// Start the core application if server is run on localhost
100114
// This starts all node helpers and starts the webserver.
101115
if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].indexOf(config.address) > -1) {

js/module.js

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ var Module = Class.extend({
2727
// visibility when hiding and showing module.
2828
lockStrings: [],
2929

30+
// Storage of the nunjuck Environment,
31+
// This should not be referenced directly.
32+
// Use the nunjucksEnvironment() to get it.
33+
_nunjucksEnvironment: null,
34+
3035
/* init()
3136
* Is called when the module is instantiated.
3237
*/
@@ -70,23 +75,35 @@ var Module = Class.extend({
7075

7176
/* getDom()
7277
* This method generates the dom which needs to be displayed. This method is called by the Magic Mirror core.
73-
* This method needs to be subclassed if the module wants to display info on the mirror.
78+
* This method can to be subclassed if the module wants to display info on the mirror.
79+
* Alternatively, the getTemplete method could be subclassed.
7480
*
7581
* return domobject - The dom to display.
7682
*/
7783
getDom: function () {
78-
var nameWrapper = document.createElement("div");
79-
var name = document.createTextNode(this.name);
80-
nameWrapper.appendChild(name);
81-
82-
var identifierWrapper = document.createElement("div");
83-
var identifier = document.createTextNode(this.identifier);
84-
identifierWrapper.appendChild(identifier);
85-
identifierWrapper.className = "small dimmed";
86-
8784
var div = document.createElement("div");
88-
div.appendChild(nameWrapper);
89-
div.appendChild(identifierWrapper);
85+
var template = this.getTemplate();
86+
var templateData = this.getTemplateData();
87+
88+
// Check to see if we need to render a template string or a file.
89+
if (/^.*((\.html)|(\.njk))$/.test(template)) {
90+
// the template is a filename
91+
this.nunjucksEnvironment().render(template, templateData, function (err, res) {
92+
if (err) {
93+
Log.error(err)
94+
}
95+
96+
// The inner content of the div will be set after the template is received.
97+
// This isn't the most optimal way, but since it's near instant
98+
// it probably won't be an issue.
99+
// If it gives problems, we can always add a way to pre fetch the templates.
100+
// Let's not over optimise this ... KISS! :)
101+
div.innerHTML = res;
102+
});
103+
} else {
104+
// the template is a template string.
105+
div.innerHTML = this.nunjucksEnvironment().renderString(template, templateData);
106+
}
90107

91108
return div;
92109
},
@@ -102,6 +119,28 @@ var Module = Class.extend({
102119
return this.data.header;
103120
},
104121

122+
/* getTemplate()
123+
* This method returns the template for the module which is used by the default getDom implementation.
124+
* This method needs to be subclassed if the module wants to use a tempate.
125+
* It can either return a template sting, or a template filename.
126+
* If the string ends with '.html' it's considered a file from within the module's folder.
127+
*
128+
* return string - The template string of filename.
129+
*/
130+
getTemplate: function () {
131+
return "<div class=\"normal\">" + this.name + "</div><div class=\"small dimmed\">" + this.identifier + "</div>";
132+
},
133+
134+
/* getTemplateData()
135+
* This method returns the data to be used in the template.
136+
* This method needs to be subclassed if the module wants to use a custom data.
137+
*
138+
* return Object
139+
*/
140+
getTemplateData: function () {
141+
return {}
142+
},
143+
105144
/* notificationReceived(notification, payload, sender)
106145
* This method is called when a notification arrives.
107146
* This method is called by the Magic Mirror core.
@@ -118,6 +157,30 @@ var Module = Class.extend({
118157
}
119158
},
120159

160+
/** nunjucksEnvironment()
161+
* Returns the nunjucks environment for the current module.
162+
* The environment is checked in the _nunjucksEnvironment instance variable.
163+
164+
* @returns Nunjucks Environment
165+
*/
166+
nunjucksEnvironment: function() {
167+
if (this._nunjucksEnvironment != null) {
168+
return this._nunjucksEnvironment;
169+
}
170+
171+
var self = this;
172+
173+
this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), {async: true}), {
174+
trimBlocks: true,
175+
lstripBlocks: true
176+
});
177+
this._nunjucksEnvironment.addFilter("translate", function(str) {
178+
return self.translate(str)
179+
});
180+
181+
return this._nunjucksEnvironment;
182+
},
183+
121184
/* socketNotificationReceived(notification, payload)
122185
* This method is called when a socket notification arrives.
123186
*
@@ -276,8 +339,8 @@ var Module = Class.extend({
276339
* Request the translation for a given key with optional variables and default value.
277340
*
278341
* argument key string - The key of the string to translate
279-
* argument defaultValueOrVariables string/object - The default value or variables for translating. (Optional)
280-
* argument defaultValue string - The default value with variables. (Optional)
342+
* argument defaultValueOrVariables string/object - The default value or variables for translating. (Optional)
343+
* argument defaultValue string - The default value with variables. (Optional)
281344
*/
282345
translate: function (key, defaultValueOrVariables, defaultValue) {
283346
if(typeof defaultValueOrVariables === "object") {

modules/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,17 @@ start: function() {
555555
}
556556
````
557557

558+
#### `stop()`
559+
This method is called when the MagicMirror server receives a `SIGINT` command and is shutting down. This method should include any commands needed to close any open connections, stop any sub-processes and gracefully exit the module.
560+
561+
**Example:**
562+
````javascript
563+
stop: function() {
564+
console.log("Shutting down MyModule");
565+
this.connection.close();
566+
}
567+
````
568+
558569
#### `socketNotificationReceived: function(notification, payload)`
559570
With this method, your node helper can receive notifications from your modules. When this method is called, it has 2 arguments:
560571

0 commit comments

Comments
 (0)