-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (41 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const {
ipcRenderer
} = require('electron');
const photosUtil = require('./photos');
const faceUtil = require('./face-rec');
const path = require('path');
const dir = ipcRenderer.sendSync('get-photo-directory');
console.log(dir);
const photos = photosUtil.getPhotos(dir);
console.log(photos);
const photoReel = document.getElementById('photo-reel');
photoReel.innerHTML = '';
for (const photo of photos) {
const img = document.createElement('img');
img.src = path.format(photo);
img.id = 'photo-preview';
img.title = decodeURI(photo.name); // remove %20 for spaces
img.addEventListener('click', () => updateMainPhoto(path.format(photo)));
photoReel.appendChild(img);
if (photo !== photos[photos.length]) {
const hr = document.createElement('hr');
hr.className = 'divider';
photoReel.appendChild(hr);
}
}
function updateMainPhoto(imgPath) {
const photo = path.parse(imgPath);
const img = document.createElement('img');
img.src = imgPath;
img.id = 'photo';
img.title = decodeURI(photo.name); // remove %20 for spaces
const photoView = document.getElementById('photo-view');
photoView.innerHTML = '';
photoView.appendChild(img);
document.title = `${ipcRenderer.sendSync('get-window-title')} - ${img.title}`;
img.onload = () => {
faceUtil.detectFaces(img).then(() => {
console.log(`Done updating main photo and detecting face(s)!`);
});
};
}