Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

node_helper.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const GitHelper = require(__dirname + "/git_helper.js");
  2. const defaultModules = require(__dirname + "/../defaultmodules.js");
  3. const NodeHelper = require("node_helper");
  4. module.exports = NodeHelper.create({
  5. config: {},
  6. updateTimer: null,
  7. updateProcessStarted: false,
  8. gitHelper: new GitHelper.gitHelper(),
  9. start: function () {},
  10. configureModules: async function (modules) {
  11. // Push MagicMirror itself , biggest chance it'll show up last in UI and isn't overwritten
  12. // others will be added in front
  13. // this method returns promises so we can't wait for every one to resolve before continuing
  14. this.gitHelper.add("default");
  15. for (let moduleName in modules) {
  16. if (!this.ignoreUpdateChecking(moduleName)) {
  17. this.gitHelper.add(moduleName);
  18. }
  19. }
  20. },
  21. socketNotificationReceived: function (notification, payload) {
  22. if (notification === "CONFIG") {
  23. this.config = payload;
  24. } else if (notification === "MODULES") {
  25. // if this is the 1st time thru the update check process
  26. if (!this.updateProcessStarted) {
  27. this.updateProcessStarted = true;
  28. this.configureModules(payload).then(() => this.performFetch());
  29. }
  30. }
  31. },
  32. performFetch: async function () {
  33. for (let gitInfo of await this.gitHelper.getRepos()) {
  34. this.sendSocketNotification("STATUS", gitInfo);
  35. }
  36. this.scheduleNextFetch(this.config.updateInterval);
  37. },
  38. scheduleNextFetch: function (delay) {
  39. if (delay < 60 * 1000) {
  40. delay = 60 * 1000;
  41. }
  42. let self = this;
  43. clearTimeout(this.updateTimer);
  44. this.updateTimer = setTimeout(function () {
  45. self.performFetch();
  46. }, delay);
  47. },
  48. ignoreUpdateChecking: function (moduleName) {
  49. // Should not check for updates for default modules
  50. if (defaultModules.indexOf(moduleName) >= 0) {
  51. return true;
  52. }
  53. // Should not check for updates for ignored modules
  54. if (this.config.ignoreModules.indexOf(moduleName) >= 0) {
  55. return true;
  56. }
  57. // The rest of the modules that passes should check for updates
  58. return false;
  59. }
  60. });