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.

updatenotification.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Magic Mirror
  2. * Module: UpdateNotification
  3. *
  4. * By Michael Teeuw https://michaelteeuw.nl
  5. * MIT Licensed.
  6. */
  7. Module.register("updatenotification", {
  8. // Define module defaults
  9. defaults: {
  10. updateInterval: 10 * 60 * 1000, // every 10 minutes
  11. refreshInterval: 24 * 60 * 60 * 1000, // one day
  12. ignoreModules: [],
  13. timeout: 5000
  14. },
  15. suspended: false,
  16. moduleList: {},
  17. // Override start method.
  18. start: function () {
  19. Log.info("Starting module: " + this.name);
  20. setInterval(() => {
  21. this.moduleList = {};
  22. this.updateDom(2);
  23. }, this.config.refreshInterval);
  24. },
  25. notificationReceived: function (notification, payload, sender) {
  26. if (notification === "DOM_OBJECTS_CREATED") {
  27. this.sendSocketNotification("CONFIG", this.config);
  28. this.sendSocketNotification("MODULES", Module.definitions);
  29. //this.hide(0, { lockString: this.identifier });
  30. }
  31. },
  32. // Override socket notification handler.
  33. socketNotificationReceived: function (notification, payload) {
  34. if (notification === "STATUS") {
  35. this.updateUI(payload);
  36. }
  37. },
  38. updateUI: function (payload) {
  39. if (payload && payload.behind > 0) {
  40. // if we haven't seen info for this module
  41. if (this.moduleList[payload.module] === undefined) {
  42. // save it
  43. this.moduleList[payload.module] = payload;
  44. this.updateDom(2);
  45. }
  46. //self.show(1000, { lockString: self.identifier });
  47. } else if (payload && payload.behind === 0) {
  48. // if the module WAS in the list, but shouldn't be
  49. if (this.moduleList[payload.module] !== undefined) {
  50. // remove it
  51. delete this.moduleList[payload.module];
  52. this.updateDom(2);
  53. }
  54. }
  55. },
  56. diffLink: function (module, text) {
  57. const localRef = module.hash;
  58. const remoteRef = module.tracking.replace(/.*\//, "");
  59. return '<a href="https://github.com/MichMich/MagicMirror/compare/' + localRef + "..." + remoteRef + '" ' + 'class="xsmall dimmed" ' + 'style="text-decoration: none;" ' + 'target="_blank" >' + text + "</a>";
  60. },
  61. // Override dom generator.
  62. getDom: function () {
  63. const wrapper = document.createElement("div");
  64. if (this.suspended === false) {
  65. // process the hash of module info found
  66. for (const key of Object.keys(this.moduleList)) {
  67. let m = this.moduleList[key];
  68. const message = document.createElement("div");
  69. message.className = "small bright";
  70. const icon = document.createElement("i");
  71. icon.className = "fa fa-exclamation-circle";
  72. icon.innerHTML = "&nbsp;";
  73. message.appendChild(icon);
  74. const updateInfoKeyName = m.behind === 1 ? "UPDATE_INFO_SINGLE" : "UPDATE_INFO_MULTIPLE";
  75. let subtextHtml = this.translate(updateInfoKeyName, {
  76. COMMIT_COUNT: m.behind,
  77. BRANCH_NAME: m.current
  78. });
  79. const text = document.createElement("span");
  80. if (m.module === "default") {
  81. text.innerHTML = this.translate("UPDATE_NOTIFICATION");
  82. subtextHtml = this.diffLink(m, subtextHtml);
  83. } else {
  84. text.innerHTML = this.translate("UPDATE_NOTIFICATION_MODULE", {
  85. MODULE_NAME: m.module
  86. });
  87. }
  88. message.appendChild(text);
  89. wrapper.appendChild(message);
  90. const subtext = document.createElement("div");
  91. subtext.innerHTML = subtextHtml;
  92. subtext.className = "xsmall dimmed";
  93. wrapper.appendChild(subtext);
  94. }
  95. }
  96. return wrapper;
  97. },
  98. suspend: function () {
  99. this.suspended = true;
  100. },
  101. resume: function () {
  102. this.suspended = false;
  103. this.updateDom(2);
  104. }
  105. });