-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
68 lines (63 loc) · 2.41 KB
/
preload.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const { ipcRenderer, contextBridge, ipcMain } = require("electron");
const API = {
requestImages: () => ipcRenderer.send("request-images"),
getImageInfo: (name, date) => ipcRenderer.send("image-info", name, date),
openInExplorer: (path) => ipcRenderer.send("open-explorer", path),
settings: () => ipcRenderer.send("settings"),
copyClipboard: (text) => ipcRenderer.send("copy-clipboard", text)
}
function removeAllChildNodes(parent) {
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
}
ipcRenderer.on('image', async (event, message) => {
if(message.success === true) {
document.getElementById('imageName').innerText = message.name;
document.getElementById('imageIMG').src = message.path;
} else {
const a = document.createElement('a');
a.href = "index.html";
a.click();
}
});
ipcRenderer.on('images', async (event, message) => {
if(message.success === true) {
const theDivToInsertInto = document.getElementById('ourDiv');
removeAllChildNodes(theDivToInsertInto);
const dates = message.everything
for(var date in dates) {
for(var image in dates[date].images) {
console.log(dates);
const ourImage = dates[date].images[image];
const imageName = ourImage.name;
const imagePath = ourImage.path;
// stuff
const div1 = document.createElement('div');
div1.classList = "col";
div1.style.marginTop = "3em";
div1.style.height = "8em";
const div2 = document.createElement('div');
div2.classList = "card shadow-sm";
const div3 = document.createElement('div');
div3.classList = "card-body text-center";
const h4 = document.createElement('h4');
h4.classList = "card-text text-center";
h4.style.color = "black";
const h4a = document.createElement('a');
h4a.href = "image.html?name=" + imageName + "&date=" + dates[date].date;
h4a.innerText = imageName;
const theImage = document.createElement('img');
theImage.src = imagePath;
theImage.style.width = "85%";
theDivToInsertInto.appendChild(div1);
div1.appendChild(div2);
div2.appendChild(div3);
div3.appendChild(h4);
h4.appendChild(h4a);
div3.appendChild(theImage);
}
}
}
});
contextBridge.exposeInMainWorld('eshare', API);