-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
31 lines (27 loc) · 1.2 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
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
selectXmlFile: () => ipcRenderer.invoke('select-xml-file'),
selectOutputDirectory: () => ipcRenderer.invoke('select-output-directory'),
processXmlFile: (xmlFilePath, outputDir) => ipcRenderer.invoke('process-xml-file', xmlFilePath, outputDir),
openOutputFolder: () => ipcRenderer.invoke('open-output-folder'),
closeApp: () => ipcRenderer.invoke('close-app'),
resetOutputFolder: () => ipcRenderer.invoke('reset-output-folder')
});
ipcRenderer.on('asynchronous-message', (event, message) => {
const progressDiv = document.getElementById('progress');
const logElement = document.createElement('p');
if (message.type === 'progress') {
progressDiv.innerHTML += `<p class="success">${message.data}</p>`;
} else if (message.type === 'error') {
logElement.className = 'error';
logElement.textContent = message.data;
progressDiv.appendChild(logElement);
} else if (message.type === 'log') {
console.log(message.data);
return;
} else {
console.warn('Received message with unknown type:', message);
return;
}
progressDiv.scrollTop = progressDiv.scrollHeight;
});