@@ -206,7 +206,7 @@ export default {
206
206
this .menuSize .width = contextMenu? .offsetWidth ;
207
207
this .menuSize .height = contextMenu? .offsetHeight ;
208
208
// this.processForm = true;
209
- // this.preloadDirectory();
209
+ this .preloadDirectory ();
210
210
211
211
// window.addEventListener("keydown", this.handelKeypress);
212
212
},
@@ -216,15 +216,21 @@ export default {
216
216
console .log (checkPath);
217
217
if (checkPath) {
218
218
this .fileListScreen = true ;
219
- this .processForm = true ;
219
+ // this.processForm = true;
220
220
this .preloadDirectory ();
221
221
}
222
222
},
223
223
imgOnLoad (e , index ) {
224
- this .files [index].width = e .target .naturalWidth ;
225
- this .files [index].height = e .target .naturalHeight ;
226
- if (! Number .isInteger (this .files [index].rating )) {
227
- this .files [index].rating = this .files [index].exif ? .Rating ;
224
+ const f = this .files [index];
225
+
226
+ f .width = e .target .naturalWidth ;
227
+ f .height = e .target .naturalHeight ;
228
+
229
+ console .log (f .rating );
230
+
231
+ if (! Number .isInteger (f .rating )) {
232
+ console .log (f .exif ? .Rating );
233
+ f .rating = f .exif ? .Rating ?? 5 ;
228
234
}
229
235
},
230
236
getFilesByRating (rating ) {
@@ -290,25 +296,26 @@ export default {
290
296
}
291
297
},
292
298
async preloadDirectory () {
299
+ this .processForm = true ;
293
300
this .files = [];
294
301
295
302
const [files , dir ] = await window .electronAPI .preloadDirectory ();
296
303
297
304
this .savePath = dir;
298
305
299
- if (! files .length ) {
306
+ if (! files? .length ) {
300
307
this .fileListScreen = false ;
301
308
this .processForm = false ;
309
+ return ;
302
310
} else {
303
311
this .fileTotalCount = files .length ;
304
312
}
305
313
306
- const fileLoadPromise = [];
307
-
308
314
for (let i = 0 ; i < files .length ; i++ ) {
309
315
this .files .push (await this .createFile (files[i], i));
310
316
}
311
317
318
+ this .fileListScreen = true ;
312
319
this .processForm = false ;
313
320
},
314
321
changeRating (nextRating ) {
@@ -319,17 +326,25 @@ export default {
319
326
async createFile (file , index ) {
320
327
// console.log(file);
321
328
322
- return {
329
+ // console.log(file.name, await exifr.thumbnailUrl(file));
330
+
331
+ const item = {
323
332
index: index,
324
333
name: file .name ,
325
- url: await exifr .thumbnailUrl (file),
334
+ url:
335
+ (await exifr .thumbnailUrl (file)) ??
336
+ (await this .fileToBase64WithResize (file)),
326
337
exif: await exifr .parse (file, true ),
327
338
width: 1 ,
328
339
height: 1 ,
329
340
checked: false ,
330
- rating: undefined ,
341
+ rating: ( await exifr . parse (file, true ) ? . rating ) ?? 5 ,
331
342
raw: file,
332
343
};
344
+
345
+ console .log (item);
346
+
347
+ return item;
333
348
},
334
349
listingConfirm () {
335
350
const finalList = this .files
@@ -346,6 +361,8 @@ export default {
346
361
},
347
362
checkUpdate () {
348
363
window .electronAPI .checkUpdate ((evt , arg ) => {
364
+ if (! arg) return ;
365
+
349
366
this .updateInfo = arg;
350
367
this .updateForm = arg .currentVersion < arg .targetVersion ;
351
368
// console.log(this.updateForm);
@@ -383,6 +400,55 @@ export default {
383
400
handelKeypress (event ) {
384
401
console .log (event );
385
402
},
403
+ fileToBase64WithResize (file , maxSize = 640 ) {
404
+ return new Promise ((resolve , reject ) => {
405
+ const reader = new FileReader ();
406
+
407
+ reader .onload = () => {
408
+ const img = new Image ();
409
+ img .onload = () => {
410
+ const canvas = document .createElement (" canvas" );
411
+ let width = img .width ;
412
+ let height = img .height ;
413
+
414
+ if (width > maxSize || height > maxSize) {
415
+ const aspectRatio = width / height;
416
+ if (height >= width) {
417
+ width = maxSize;
418
+ height = width / aspectRatio;
419
+ }
420
+ if (width > height) {
421
+ height = maxSize;
422
+ width = height * aspectRatio;
423
+ }
424
+ }
425
+
426
+ canvas .width = width;
427
+ canvas .height = height;
428
+
429
+ const ctx = canvas .getContext (" 2d" );
430
+ ctx .drawImage (img, 0 , 0 , width, height);
431
+
432
+ ctx .canvas .toBlob ((blob ) => {
433
+ const url = URL .createObjectURL (blob);
434
+ resolve (url);
435
+ }, file .type );
436
+ };
437
+
438
+ img .onerror = (error ) => {
439
+ reject (undefined );
440
+ };
441
+
442
+ img .src = reader .result ;
443
+ };
444
+
445
+ reader .onerror = (error ) => {
446
+ reject (undefined );
447
+ };
448
+
449
+ reader .readAsDataURL (file);
450
+ });
451
+ },
386
452
},
387
453
watch: {
388
454
menuOpened (value ) {
0 commit comments