-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
87 lines (76 loc) · 3.19 KB
/
renderer.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { ipcRenderer } = require('electron');
let selectedDirectory = '';
document.getElementById('selectDir').addEventListener('click', async () => {
const paths = await ipcRenderer.invoke('select-directory');
if (paths && paths.length > 0) {
selectedDirectory = paths[0];
document.getElementById('fileList').innerHTML = `Selected directory: ${selectedDirectory}`;
}
});
document.getElementById('processFiles').addEventListener('click', async () => {
if (!selectedDirectory) {
alert('Please select a directory first');
return;
}
try {
const results = await ipcRenderer.invoke('process-files', selectedDirectory);
displayResults(results);
} catch (err) {
alert('Error processing files: ' + err.message);
}
});
function displayResults(results) {
const fileList = document.getElementById('fileList');
fileList.innerHTML = '<h3>Processing Results:</h3>';
console.log(results)
if (results.length===0){
console.log('here')
const div = document.createElement('div');
div.className = 'file-item-fail';
const status = document.createElement('p');
status.innerHTML = `<strong>Status:</strong> `;
const statusSpan = document.createElement('span');
statusSpan.className = 'status-failed';
statusSpan.textContent = `Failed - Directory is Empty!`;
status.append(statusSpan)
div.appendChild(status)
fileList.append(div)
return
}
results.forEach(result => {
const div = document.createElement('div');
try {
div.className = result.noTextFound ? 'file-item-fail': 'file-item';
} catch (err) {
console.log(`Error occured in accesssing 'noTextFound' attribute`);
div.className = 'file-item-fail'
}
const originalName = document.createElement('p');
originalName.innerHTML = `<strong>Original:</strong> ${result.originalName}`;
div.appendChild(originalName);
if (result.success) {
const newName = document.createElement('p');
newName.innerHTML = `<strong>New name:</strong> ${result.newName}`;
div.appendChild(newName);
const status = document.createElement('p');
status.innerHTML = `<strong>Status:</strong> `;
const statusSpan = document.createElement('span');
statusSpan.className = result.noTextFound ? 'status-warning' : 'status-success';
statusSpan.textContent = result.noTextFound
? 'No readable text found - Original filename kept'
: 'Success';
status.appendChild(statusSpan);
div.appendChild(status);
} else {
div.className = 'file-item-fail'
const status = document.createElement('p');
status.innerHTML = `<strong>Status:</strong> `;
const statusSpan = document.createElement('span');
statusSpan.className = 'status-failed';
statusSpan.textContent = `Failed - ${result.error}`;
status.appendChild(statusSpan);
div.appendChild(status);
}
fileList.appendChild(div);
});
}