diff --git a/MMM-RandomPhoto.js b/MMM-RandomPhoto.js index ccb3978..f1ebb2c 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,19 @@ Module.register("MMM-RandomPhoto",{ }, fetchImageList: function() { + 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.scanInterval != -1) { + clearTimeout(this.scanTimer); + this.scanTimer = setTimeout(function() { + Log.log("Requesting new images"); + 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 +119,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, @@ -399,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/README.md b/README.md index 5d9e80c..1dbe2fb 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, 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` 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 +});