From ba0ff17a616a56af40451ea134bb373e158fa352 Mon Sep 17 00:00:00 2001 From: MystaraTheGreat Date: Mon, 15 Mar 2021 08:23:17 +0000 Subject: [PATCH 1/8] Added rescan interval --- MMM-RandomPhoto.js | 12 +++++++++++- package-lock.json | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 package-lock.json diff --git a/MMM-RandomPhoto.js b/MMM-RandomPhoto.js index ccb3978..8ec9063 100644 --- a/MMM-RandomPhoto.js +++ b/MMM-RandomPhoto.js @@ -13,6 +13,7 @@ Module.register("MMM-RandomPhoto",{ opacity: 0.3, animationSpeed: 500, updateInterval: 60, + scanInterval: -1, // How often to look for new photos. -1 = never imageRepository: "picsum", // Select the image repository source. One of "picsum" (default / fallback), "localdirectory" or "nextcloud" (currently broken because of CORS bug in nextcloud) repositoryConfig: { // if imageRepository = "picsum" -> "path", "username" and "password" are ignored and can be left empty @@ -41,6 +42,7 @@ Module.register("MMM-RandomPhoto",{ start: function() { this.updateTimer = null; + this.scanTimer = null; this.imageList = null; // Used for nextcloud and localdirectory image list this.currentImageIndex = -1; // Used for nextcloud and localdirectory image list this.running = false; @@ -70,8 +72,16 @@ Module.register("MMM-RandomPhoto",{ }, fetchImageList: function() { + Log.log(this.name + " fetching image list"); if (typeof this.config.repositoryConfig.path !== "undefined" && this.config.repositoryConfig.path !== null) { this.sendSocketNotification('FETCH_IMAGE_LIST'); + + if (this.config.updateInterval != -1) { + clearTimeout(this.scanTimer); + this.scanTimer = setTimeout(function() { + self.fetchImageList(); + }, (this.config.scanInterval * 1000)); + } } else { Log.error("[" + this.name + "] Trying to use 'nextcloud' or 'localdirectory' but did not specify any 'config.repositoryConfig.path'."); } @@ -106,7 +116,7 @@ Module.register("MMM-RandomPhoto",{ if (self.localdirectory || self.nextcloud) { if (self.imageList && self.imageList.length > 0) { url = "/" + this.name + "/images/" + this.returnImageFromList(mode); - + jQuery.ajax({ method: "GET", url: url, diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..082cd96 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "magic-mirror-module-random-photo", + "version": "1.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "jquery": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", + "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==" + } + } +} From 8c5222b0618faf66259f74bad8ec1a94000fa34e Mon Sep 17 00:00:00 2001 From: MystaraTheGreat Date: Mon, 15 Mar 2021 13:27:52 +0000 Subject: [PATCH 2/8] Fixed error in which function became out of scope --- MMM-RandomPhoto.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/MMM-RandomPhoto.js b/MMM-RandomPhoto.js index 8ec9063..b985946 100644 --- a/MMM-RandomPhoto.js +++ b/MMM-RandomPhoto.js @@ -72,15 +72,17 @@ Module.register("MMM-RandomPhoto",{ }, fetchImageList: function() { - Log.log(this.name + " fetching image list"); + var self = this; + + Log.info(this.name + " fetching image list"); if (typeof this.config.repositoryConfig.path !== "undefined" && this.config.repositoryConfig.path !== null) { this.sendSocketNotification('FETCH_IMAGE_LIST'); - if (this.config.updateInterval != -1) { + if (this.config.scanInterval != -1) { clearTimeout(this.scanTimer); this.scanTimer = setTimeout(function() { - self.fetchImageList(); - }, (this.config.scanInterval * 1000)); + self.fetchImageList(); + }, (this.config.scanInterval * 1000)); } } else { Log.error("[" + this.name + "] Trying to use 'nextcloud' or 'localdirectory' but did not specify any 'config.repositoryConfig.path'."); From a376de8658062c3c55baf7f26e049b76eec1c008 Mon Sep 17 00:00:00 2001 From: MystaraTheGreat Date: Wed, 17 Mar 2021 08:45:21 +0000 Subject: [PATCH 3/8] Added documentation --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5d9e80c..98964d9 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ The entry in `config.js` can include the following options: | `opacity` | *Optional* - The opacity of the image.

**Type:** `double`
**Default:** `0.3` | `animationSpeed` | *Optional* - How long the fade out and fade in of photos should take.

**Type:** `int`
**Default:** `500` | `updateInterval` | *Optional* - How long before getting a new image.

**Type:** `int`
**Default:** `60` seconds +| `scanInterval` | *Optional* - How long before rescanning the image repository. A value of -1 means 'never'.

**Type:** `int`
**Default:** `-1` (never) | `startHidden` | *Optional* - Should the module start hidden? Useful if you use it as a "screensaver"

**Type:** `boolean`
**Default:** `false` | `startPaused` | *Optional* - Should the module start in "paused" (automatic image loading will be paused) mode?

**Type:** `boolean`
**Default:** `false` | `showStatusIcon` | *Optional* - Do you want to see the current status of automatic image loading ("play" / "paused" mode)?

**Type:** `boolean`
**Default:** `true` From 66428450027fd810e490e27d4d760f59e6ca65b7 Mon Sep 17 00:00:00 2001 From: MystaraTheGreat Date: Sun, 21 Mar 2021 12:06:34 +0000 Subject: [PATCH 4/8] Changed tab to spaces --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98964d9..7e094b9 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The entry in `config.js` can include the following options: | `opacity` | *Optional* - The opacity of the image.

**Type:** `double`
**Default:** `0.3` | `animationSpeed` | *Optional* - How long the fade out and fade in of photos should take.

**Type:** `int`
**Default:** `500` | `updateInterval` | *Optional* - How long before getting a new image.

**Type:** `int`
**Default:** `60` seconds -| `scanInterval` | *Optional* - How long before rescanning the image repository. A value of -1 means 'never'.

**Type:** `int`
**Default:** `-1` (never) +| `scanInterval` | *Optional* - How long before rescanning the image repository. A value of -1 means 'never'.

**Type:** `int`
**Default:** `-1` (never) | `startHidden` | *Optional* - Should the module start hidden? Useful if you use it as a "screensaver"

**Type:** `boolean`
**Default:** `false` | `startPaused` | *Optional* - Should the module start in "paused" (automatic image loading will be paused) mode?

**Type:** `boolean`
**Default:** `false` | `showStatusIcon` | *Optional* - Do you want to see the current status of automatic image loading ("play" / "paused" mode)?

**Type:** `boolean`
**Default:** `true` From dbc00cd58c73143c84b9c78e3b9fc05fdb57b597 Mon Sep 17 00:00:00 2001 From: MystaraTheGreat Date: Sun, 21 Mar 2021 12:07:58 +0000 Subject: [PATCH 5/8] Changed documentation to mention that scanInterval is in seconds --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e094b9..1dbe2fb 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The entry in `config.js` can include the following options: | `opacity` | *Optional* - The opacity of the image.

**Type:** `double`
**Default:** `0.3` | `animationSpeed` | *Optional* - How long the fade out and fade in of photos should take.

**Type:** `int`
**Default:** `500` | `updateInterval` | *Optional* - How long before getting a new image.

**Type:** `int`
**Default:** `60` seconds -| `scanInterval` | *Optional* - How long before rescanning the image repository. A value of -1 means 'never'.

**Type:** `int`
**Default:** `-1` (never) +| `scanInterval` | *Optional* - How long, in seconds, before rescanning the image repository. A value of -1 means 'never'.

**Type:** `int`
**Default:** `-1` (never) | `startHidden` | *Optional* - Should the module start hidden? Useful if you use it as a "screensaver"

**Type:** `boolean`
**Default:** `false` | `startPaused` | *Optional* - Should the module start in "paused" (automatic image loading will be paused) mode?

**Type:** `boolean`
**Default:** `false` | `showStatusIcon` | *Optional* - Do you want to see the current status of automatic image loading ("play" / "paused" mode)?

**Type:** `boolean`
**Default:** `true` From 2f309a4403b806f99386ab6aadd05e58a7d619fb Mon Sep 17 00:00:00 2001 From: MystaraTheGreat Date: Sun, 21 Mar 2021 12:11:33 +0000 Subject: [PATCH 6/8] Removed package-lock.json --- package-lock.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 082cd96..0000000 --- a/package-lock.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "magic-mirror-module-random-photo", - "version": "1.0.1", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "jquery": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", - "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==" - } - } -} From a4d1e57130056dd718b7b278331aa129c3ad4ac2 Mon Sep 17 00:00:00 2001 From: MystaraTheGreat Date: Sun, 21 Mar 2021 12:57:41 +0000 Subject: [PATCH 7/8] Changed tabs to spaces --- MMM-RandomPhoto.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MMM-RandomPhoto.js b/MMM-RandomPhoto.js index b985946..52e16ab 100644 --- a/MMM-RandomPhoto.js +++ b/MMM-RandomPhoto.js @@ -13,7 +13,7 @@ Module.register("MMM-RandomPhoto",{ opacity: 0.3, animationSpeed: 500, updateInterval: 60, - scanInterval: -1, // How often to look for new photos. -1 = never + scanInterval: -1, // How often to look for new photos. -1 = never imageRepository: "picsum", // Select the image repository source. One of "picsum" (default / fallback), "localdirectory" or "nextcloud" (currently broken because of CORS bug in nextcloud) repositoryConfig: { // if imageRepository = "picsum" -> "path", "username" and "password" are ignored and can be left empty @@ -42,7 +42,7 @@ Module.register("MMM-RandomPhoto",{ start: function() { this.updateTimer = null; - this.scanTimer = null; + this.scanTimer = null; this.imageList = null; // Used for nextcloud and localdirectory image list this.currentImageIndex = -1; // Used for nextcloud and localdirectory image list this.running = false; @@ -72,18 +72,18 @@ Module.register("MMM-RandomPhoto",{ }, fetchImageList: function() { - var self = this; + var self = this; - Log.info(this.name + " fetching image list"); + Log.info(this.name + " fetching image list"); if (typeof this.config.repositoryConfig.path !== "undefined" && this.config.repositoryConfig.path !== null) { this.sendSocketNotification('FETCH_IMAGE_LIST'); - if (this.config.scanInterval != -1) { - clearTimeout(this.scanTimer); - this.scanTimer = setTimeout(function() { - self.fetchImageList(); - }, (this.config.scanInterval * 1000)); - } + if (this.config.scanInterval != -1) { + clearTimeout(this.scanTimer); + this.scanTimer = setTimeout(function() { + self.fetchImageList(); + }, (this.config.scanInterval * 1000)); + } } else { Log.error("[" + this.name + "] Trying to use 'nextcloud' or 'localdirectory' but did not specify any 'config.repositoryConfig.path'."); } From fa3e05a6248a8bc070ed53b1bd8c67d4a100b247 Mon Sep 17 00:00:00 2001 From: MystaraTheGreat Date: Sat, 3 Apr 2021 18:54:40 +0100 Subject: [PATCH 8/8] Rescan interval --- MMM-RandomPhoto.js | 4 ++++ node_helper.js | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/MMM-RandomPhoto.js b/MMM-RandomPhoto.js index 52e16ab..f1ebb2c 100644 --- a/MMM-RandomPhoto.js +++ b/MMM-RandomPhoto.js @@ -81,6 +81,7 @@ Module.register("MMM-RandomPhoto",{ if (this.config.scanInterval != -1) { clearTimeout(this.scanTimer); this.scanTimer = setTimeout(function() { + Log.log("Requesting new images"); self.fetchImageList(); }, (this.config.scanInterval * 1000)); } @@ -411,6 +412,9 @@ Module.register("MMM-RandomPhoto",{ if(!this.config.startHidden) { this.resumeImageLoading(true); } + } else if (notification === "UPDATE_IMAGE_LIST") { + Log.log("Updating image list"); + this.imageList = payload; } }, diff --git a/node_helper.js b/node_helper.js index 9c300ce..ee669e8 100644 --- a/node_helper.js +++ b/node_helper.js @@ -4,6 +4,8 @@ const fs = require("fs"); // for localdirectory const NodeHelper = require("node_helper"); +var initialLoadCompleted = false; + module.exports = NodeHelper.create({ start: function() { @@ -60,7 +62,13 @@ module.exports = NodeHelper.create({ } } this.imageList = imageList; - self.sendSocketNotification("IMAGE_LIST", imageList); + if (initialLoadCompleted == false) { + self.sendSocketNotification("IMAGE_LIST", imageList); + initialLoadCompleted = true; + } else { + self.sendSocketNotification("UPDATE_IMAGE_LIST", imageList); + } + return; } return false; @@ -93,7 +101,13 @@ module.exports = NodeHelper.create({ imageList[index] = item.replace("href>" + urlParts.pathname, ""); //console.log("[" + self.name + "] Found entry: " + imageList[index]); }); - self.sendSocketNotification("IMAGE_LIST", imageList); + if (initialLoadCompleted == false) { + self.sendSocketNotification("IMAGE_LIST", imageList); + initialLoadCompleted = true; + } else { + console.log("Updating image list") + self.sendSocketNotification("UPDATE_IMAGE_LIST", imageList); + } return; } else { console.log("[" + this.name + "] WARNING: did not get any images from nextcloud url"); @@ -158,4 +172,4 @@ module.exports = NodeHelper.create({ }, -}); \ No newline at end of file +});