mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
- Added autoTimezone property to the clock
This commit is contained in:
parent
1a97107b2d
commit
c608636b7a
@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Disabled the screensaver on raspbian with installation script
|
- Disabled the screensaver on raspbian with installation script
|
||||||
- Added option to truncate the number of vertical lines a calendar item can span if `wrapEvents` is enabled.
|
- Added option to truncate the number of vertical lines a calendar item can span if `wrapEvents` is enabled.
|
||||||
- Added autoLocation options for weather forcast and current weather modules.
|
- Added autoLocation options for weather forcast and current weather modules.
|
||||||
|
- Added autoTimezone option for the default clock module.
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
- Bumped the Electron dependency to v3.0.13 to support the most recent Raspbian. [#1500](https://github.com/MichMich/MagicMirror/issues/1500)
|
- Bumped the Electron dependency to v3.0.13 to support the most recent Raspbian. [#1500](https://github.com/MichMich/MagicMirror/issues/1500)
|
||||||
|
@ -26,6 +26,7 @@ Module.register("clock",{
|
|||||||
analogShowDate: "top", // options: false, 'top', or 'bottom'
|
analogShowDate: "top", // options: false, 'top', or 'bottom'
|
||||||
secondsColor: "#888888",
|
secondsColor: "#888888",
|
||||||
timezone: null,
|
timezone: null,
|
||||||
|
autoTimezone: false
|
||||||
},
|
},
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
@ -39,16 +40,31 @@ Module.register("clock",{
|
|||||||
start: function() {
|
start: function() {
|
||||||
Log.info("Starting module: " + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
|
|
||||||
// Schedule update interval.
|
if (this.config.autoTimezone) {
|
||||||
var self = this;
|
this.sendSocketNotification("AUTO_TIMEZONE");
|
||||||
setInterval(function() {
|
} else {
|
||||||
self.updateDom();
|
// Schedule update interval.
|
||||||
}, 1000);
|
var self = this;
|
||||||
|
setInterval(function() {
|
||||||
|
self.updateDom();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
moment.locale(config.language);
|
moment.locale(config.language);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
socketNotificationReceived: function (notification, payload) {
|
||||||
|
if (notification === "UPDATE_TIMEZONE") {
|
||||||
|
var self = this;
|
||||||
|
self.config.timezone = payload.timezone;
|
||||||
|
setInterval(function() {
|
||||||
|
self.updateDom();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Override dom generator.
|
// Override dom generator.
|
||||||
getDom: function() {
|
getDom: function() {
|
||||||
|
|
||||||
|
29
modules/default/clock/node_helper.js
Normal file
29
modules/default/clock/node_helper.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
var http = require("http");
|
||||||
|
var NodeHelper = require("node_helper");
|
||||||
|
|
||||||
|
module.exports = NodeHelper.create({
|
||||||
|
start: function () {
|
||||||
|
},
|
||||||
|
|
||||||
|
socketNotificationReceived: function (notification, payload) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (notification === "AUTO_TIMEZONE") {
|
||||||
|
console.log("Loading timezone...");
|
||||||
|
http.get("http://ip-api.com/json", function (req) {
|
||||||
|
var data = "";
|
||||||
|
req.on("data", function (d) {
|
||||||
|
data += d;
|
||||||
|
});
|
||||||
|
req.on("end", function () {
|
||||||
|
var body = JSON.parse(data);
|
||||||
|
payload.timezone = body.timezone;
|
||||||
|
self.sendSocketNotification("UPDATE_TIMEZONE", payload);
|
||||||
|
});
|
||||||
|
}).on("error", function () {
|
||||||
|
payload.error = "Could not figure out the timezone.";
|
||||||
|
self.sendSocketNotification("UPDATE_TIMEZONE", payload);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user