@@ -203,70 +203,69 @@ module.exports = NodeHelper.create({
203203
204204 displayImage : async function ( showCurrent = false ) {
205205 Log . debug ( LOG_PREFIX + 'displayImage called' , showCurrent , this . lastImageLoaded ? 'has last image' : 'no last image' ) ;
206- if ( showCurrent && this . lastImageLoaded ) {
207- // Just send the current image
208- this . sendSocketNotification (
209- 'IMMICHSLIDESHOW_DISPLAY_IMAGE' ,
210- this . lastImageLoaded
211- ) ;
212- return ;
213- }
206+
207+ // If we are not showing the current image, then fetch the next one.
208+ if ( ! ( showCurrent && this . lastImageLoaded ) ) {
209+
210+ // if there are no images or all the images have been displayed or it is the next day, try loading the images again
211+ if ( ! this . imageList . length || this . index >= this . imageList . length || Date . now ( ) - this . pictureDate > 86400000 ) {
212+ Log . debug ( LOG_PREFIX + 'image list is empty or index out of range or list too old! fetching new image list...' ) ;
213+ // Force the index to 0 so that we start from the beginning
214+ // and calling this function again will not get stuck in a loop
215+ if ( this . index >= this . imageList . length ) {
216+ this . index = 0 ;
217+ }
218+ // Set the last Image to null so we cannot load it and have to progress
219+ this . lastImageLoaded = null ;
220+ this . gatherImageList ( this . config ) ;
221+ return ;
222+ }
214223
215- // if there are no images or all the images have been displayed or it is the next day, try loading the images again
216- if ( ! this . imageList . length || this . index >= this . imageList . length || Date . now ( ) - this . pictureDate > 86400000 ) {
217- Log . debug ( LOG_PREFIX + 'image list is empty or index out of range or list too old! fetching new image list...' ) ;
218- // Force the index to 0 so that we start from the beginning
219- // and calling this function again will not get stuck in a loop
220- if ( this . index >= this . imageList . length ) {
221- this . index = 0 ;
224+ // If still do not have images, just call this function in 5 min
225+ if ( ! this . imageList . length ) {
226+ Log . debug ( LOG_PREFIX + 'image list is empty! setting timeout for next image...' ) ;
227+ // still no images, search again after 5 mins
228+ setTimeout ( ( ) => {
229+ this . displayImage ( ) ;
230+ } , 300000 ) ;
231+ return ;
222232 }
223- // Set the last Image to null so we cannot load it and have to progress
224- this . lastImageLoaded = null ;
225- this . gatherImageList ( this . config ) ;
226- return ;
227- }
228- // Log.debug(LOG_PREFIX + 'image list', this.imageList.length, this.imageList);
229- if ( ! this . imageList . length ) {
230- Log . debug ( LOG_PREFIX + 'image list is empty! setting timeout for next image...' ) ;
231- // still no images, search again after 5 mins
232- setTimeout ( ( ) => {
233- this . displayImage ( ) ;
234- } , 300000 ) ;
235- return ;
236- }
237233
238- let image = this . imageList [ this . index ] ;
234+ let image = this . imageList [ this . index ] ;
235+
236+ Log . debug ( LOG_PREFIX + 'reading image "' + image . originalPath + '"' ) ;
237+
238+ this . lastImageLoaded = {
239+ identifier : this . config . identifier ,
240+ path : image . originalPath ,
241+ exifInfo : image . exifInfo || { } ,
242+ people : [ ] ,
243+ data : null ,
244+ imageId : image . id ,
245+ index : this . index + 1 , // Index is zero based
246+ total : this . imageList . length
247+ } ;
239248
240- Log . debug ( LOG_PREFIX + 'reading image "' + image . originalPath + '"' ) ;
241-
242- this . lastImageLoaded = {
243- identifier : this . config . identifier ,
244- path : image . originalPath ,
245- exifInfo : image . exifInfo || { } ,
246- people : [ ] ,
247- data : null ,
248- imageId : image . id ,
249- index : this . index + 1 , // Index is zero based
250- total : this . imageList . length
251- } ;
252-
253- // If there is no exif info available, or if we need people but no people are listed
254- // then fetch it with a separate call based on the API version
255- if ( ! image . exifInfo || image . exifInfo . length == 0 ||
256- this . config . imageInfo . includes ( 'people' ) && ( ! image . people || image . people . length == 0 ) ) {
257- const assetInfo = await immichApi . getAssetInfo ( image . id ) ;
258- if ( assetInfo ) {
259- this . lastImageLoaded . exifInfo = assetInfo . exifInfo ;
260- this . lastImageLoaded . people = assetInfo . people ;
249+ // If there is no exif info available, or if we need people but no people are listed
250+ // then fetch it with a separate call based on the API version
251+ if ( ! image . exifInfo || image . exifInfo . length == 0 ||
252+ this . config . imageInfo . includes ( 'people' ) && ( ! image . people || image . people . length == 0 ) ) {
253+ const assetInfo = await immichApi . getAssetInfo ( image . id ) ;
254+ if ( assetInfo ) {
255+ this . lastImageLoaded . exifInfo = assetInfo . exifInfo ;
256+ this . lastImageLoaded . people = assetInfo . people ;
257+ }
261258 }
259+ this . lastImageLoaded . data = await immichApi . getBase64EncodedAsset ( image . id ) ;
262260 }
263261
264- this . lastImageLoaded . data = await immichApi . getBase64EncodedAsset ( image . id ) ;
265-
266- this . sendSocketNotification (
267- 'IMMICHSLIDESHOW_DISPLAY_IMAGE' ,
268- this . lastImageLoaded
269- ) ;
262+ // Only send a notification if we have the new image loaded
263+ if ( this . lastImageLoaded . data ) {
264+ this . sendSocketNotification (
265+ 'IMMICHSLIDESHOW_DISPLAY_IMAGE' ,
266+ this . lastImageLoaded
267+ ) ;
268+ }
270269 } ,
271270
272271 getNextImage : function ( showCurrent = false , reloadOnLoop = false ) {
0 commit comments