-
Notifications
You must be signed in to change notification settings - Fork 3
/
MMM-Config.js
106 lines (90 loc) · 3.23 KB
/
MMM-Config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
sample module structure
*/
Module.register("MMM-Config", {
// holder for config info from module_name.js
config: null,
// anything here in defaults will be added to the config data
// and replaced if the same thing is provided in config
defaults: {
showQR: false,
force_update: true,
restart: "",
debug: false
},
getTranslations: function () {
return {
en: "translations/en.json",
es: "translations/es.json",
da: "translations/da.json",
de: "translations/de.json"
};
},
init: function () {
Log.log(this.name + " is in init!");
},
start: function () {
Log.log(this.name + " is starting!");
this.config.lang = this.config.lang || config.language; //automatically overrides and sets language :)
},
getStyles: function () {
return ["MMM-Config.css"];
},
// return list of other functional scripts to use, if any (like require in node_helper)
/* getScripts: function () {
return [this.file("node_modules/qrcode/build/qrcode.min.js")];
}, */
// messages received from other modules and the system (NOT from your node helper)
// payload is a notification dependent data structure
notificationReceived: function (notification, payload, sender) {
// once everybody is loaded up
if (notification === "ALL_MODULES_STARTED") {
// send our config to our node_helper
this.config.address = config.address;
this.config.port = config.port;
this.config.whiteList = config.ipWhitelist;
this.config.id=this.identifier
this.sendSocketNotification("CONFIG", this.config);
}
},
// messages received from from your node helper (NOT other modules or the system)
// payload is a notification dependent data structure, up to you to design between module and node_helper
socketNotificationReceived: function (notification, payload) {
Log.log(
this.name +
" received a socket notification: " +
notification +
" - Payload: " +
payload
);
if (notification === "qr_url") {
this.config.url = payload;
// tell mirror runtime that our data has changed,
// we will be called back at GetDom() to provide the updated content
this.updateDom(1000);
}
},
// system notification your module is being hidden
// typically you would stop doing UI updates (getDom/updateDom) if the module is hidden
suspend: function () {},
// system notification your module is being unhidden/shown
// typically you would resume doing UI updates (getDom/updateDom) if the module is shown
resume: function () {},
// this is the major worker of the module, it provides the displayable content for this module
getDom: function () {
var wrapper = document.createElement("div");
// if user supplied message text in its module config, use it
if (this.config.hasOwnProperty("url")) {
if (config.address.toLowerCase() !== "localhost") {
let image = document.createElement("img");
image.src = this.config.url;
image.className = "qr";
wrapper.appendChild(image);
} else {
wrapper.classList.add("text");
wrapper.innerHTML = this.translate("QR_ERROR_MESSAGE").replace('8080',config.port);
}
}
return wrapper;
}
});