@@ -135,70 +135,77 @@ Module.register("MMM-GooglePhotos", {
135
135
this . needMorePicsFlag = true ;
136
136
}
137
137
if ( this . needMorePicsFlag ) {
138
- this . sendSocketNotification ( "NEED_MORE_PICS" , [ ] ) ;
138
+ setTimeout ( ( ) => {
139
+ this . sendSocketNotification ( "NEED_MORE_PICS" , [ ] ) ;
140
+ } , 2000 ) ;
139
141
}
140
142
} ,
141
143
142
144
ready : function ( url , target ) {
143
145
let hidden = document . createElement ( "img" ) ;
146
+ const _this = this ;
144
147
hidden . onerror = ( event , source , lineno , colno , error ) => {
145
148
const errObj = { url, event, source, lineno, colno, error } ;
146
149
this . sendSocketNotification ( "IMAGE_LOAD_FAIL" , errObj ) ;
147
150
} ;
148
151
hidden . onload = ( ) => {
149
- let back = document . getElementById ( "GPHOTO_BACK" ) ;
150
- let current = document . getElementById ( "GPHOTO_CURRENT" ) ;
151
- current . textContent = "" ;
152
- //current.classList.remove("animated")
153
- // let dom = document.getElementById("GPHOTO");
154
- back . style . backgroundImage = `url(${ url } )` ;
155
- current . style . backgroundImage = `url(${ url } )` ;
156
- current . classList . add ( "animated" ) ;
157
- const info = document . getElementById ( "GPHOTO_INFO" ) ;
158
- const album = Array . isArray ( this . albums ) ? this . albums . find ( ( a ) => a . id === target . _albumId ) : { id : - 1 , title : '' } ;
159
- if ( this . config . autoInfoPosition ) {
160
- let op = ( album , target ) => {
161
- let now = new Date ( ) ;
162
- let q = Math . floor ( now . getMinutes ( ) / 15 ) ;
163
- let r = [
164
- [ 0 , "none" , "none" , 0 ] ,
165
- [ "none" , "none" , 0 , 0 ] ,
166
- [ "none" , 0 , 0 , "none" ] ,
167
- [ 0 , 0 , "none" , "none" ] ,
168
- ] ;
169
- return r [ q ] ;
170
- } ;
171
- if ( typeof this . config . autoInfoPosition === "function" ) {
172
- op = this . config . autoInfoPosition ;
173
- }
174
- const [ top , left , bottom , right ] = op ( album , target ) ;
175
- info . style . setProperty ( "--top" , top ) ;
176
- info . style . setProperty ( "--left" , left ) ;
177
- info . style . setProperty ( "--bottom" , bottom ) ;
178
- info . style . setProperty ( "--right" , right ) ;
179
- }
180
- info . innerHTML = "" ;
181
- let albumCover = document . createElement ( "div" ) ;
182
- albumCover . classList . add ( "albumCover" ) ;
183
- albumCover . style . backgroundImage = `url(modules/MMM-GooglePhotos/cache/${ album . id } )` ;
184
- let albumTitle = document . createElement ( "div" ) ;
185
- albumTitle . classList . add ( "albumTitle" ) ;
186
- albumTitle . innerHTML = album . title ;
187
- let photoTime = document . createElement ( "div" ) ;
188
- photoTime . classList . add ( "photoTime" ) ;
189
- photoTime . innerHTML = this . config . timeFormat === "relative" ? moment ( target . mediaMetadata . creationTime ) . fromNow ( ) : moment ( target . mediaMetadata . creationTime ) . format ( this . config . timeFormat ) ;
190
- let infoText = document . createElement ( "div" ) ;
191
- infoText . classList . add ( "infoText" ) ;
192
-
193
- info . appendChild ( albumCover ) ;
194
- infoText . appendChild ( albumTitle ) ;
195
- infoText . appendChild ( photoTime ) ;
196
- info . appendChild ( infoText ) ;
197
- this . sendSocketNotification ( "IMAGE_LOADED" , { id : target . id , index : this . index } ) ;
152
+ _this . render ( url , target ) ;
198
153
} ;
199
154
hidden . src = url ;
200
155
} ,
201
156
157
+ render : function ( url , target ) {
158
+ let back = document . getElementById ( "GPHOTO_BACK" ) ;
159
+ let current = document . getElementById ( "GPHOTO_CURRENT" ) ;
160
+ current . textContent = "" ;
161
+ //current.classList.remove("animated")
162
+ // let dom = document.getElementById("GPHOTO");
163
+ back . style . backgroundImage = `url(${ url } )` ;
164
+ current . style . backgroundImage = `url(${ url } )` ;
165
+ current . classList . add ( "animated" ) ;
166
+ const info = document . getElementById ( "GPHOTO_INFO" ) ;
167
+ const album = Array . isArray ( this . albums ) ? this . albums . find ( ( a ) => a . id === target . _albumId ) : { id : - 1 , title : '' } ;
168
+ if ( this . config . autoInfoPosition ) {
169
+ let op = ( album , target ) => {
170
+ let now = new Date ( ) ;
171
+ let q = Math . floor ( now . getMinutes ( ) / 15 ) ;
172
+ let r = [
173
+ [ 0 , "none" , "none" , 0 ] ,
174
+ [ "none" , "none" , 0 , 0 ] ,
175
+ [ "none" , 0 , 0 , "none" ] ,
176
+ [ 0 , 0 , "none" , "none" ] ,
177
+ ] ;
178
+ return r [ q ] ;
179
+ } ;
180
+ if ( typeof this . config . autoInfoPosition === "function" ) {
181
+ op = this . config . autoInfoPosition ;
182
+ }
183
+ const [ top , left , bottom , right ] = op ( album , target ) ;
184
+ info . style . setProperty ( "--top" , top ) ;
185
+ info . style . setProperty ( "--left" , left ) ;
186
+ info . style . setProperty ( "--bottom" , bottom ) ;
187
+ info . style . setProperty ( "--right" , right ) ;
188
+ }
189
+ info . innerHTML = "" ;
190
+ let albumCover = document . createElement ( "div" ) ;
191
+ albumCover . classList . add ( "albumCover" ) ;
192
+ albumCover . style . backgroundImage = `url(modules/MMM-GooglePhotos/cache/${ album . id } )` ;
193
+ let albumTitle = document . createElement ( "div" ) ;
194
+ albumTitle . classList . add ( "albumTitle" ) ;
195
+ albumTitle . innerHTML = album . title ;
196
+ let photoTime = document . createElement ( "div" ) ;
197
+ photoTime . classList . add ( "photoTime" ) ;
198
+ photoTime . innerHTML = this . config . timeFormat === "relative" ? moment ( target . mediaMetadata . creationTime ) . fromNow ( ) : moment ( target . mediaMetadata . creationTime ) . format ( this . config . timeFormat ) ;
199
+ let infoText = document . createElement ( "div" ) ;
200
+ infoText . classList . add ( "infoText" ) ;
201
+
202
+ info . appendChild ( albumCover ) ;
203
+ infoText . appendChild ( albumTitle ) ;
204
+ infoText . appendChild ( photoTime ) ;
205
+ info . appendChild ( infoText ) ;
206
+ this . sendSocketNotification ( "IMAGE_LOADED" , { id : target . id , index : this . index } ) ;
207
+ } ,
208
+
202
209
getDom : function ( ) {
203
210
let wrapper = document . createElement ( "div" ) ;
204
211
wrapper . id = "GPHOTO" ;
0 commit comments