-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
66 lines (57 loc) · 2.77 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
const { ipcRenderer } = require('electron');
const selectFolderButton = document.getElementById('selectFolderButton');
const toggleServerButton = document.getElementById('toggleServerButton');
const designFileListContainer = document.getElementById('designFileList');
const currentPathDisplay = document.getElementById('currentPath');
// Event listener for selecting a folder
selectFolderButton.addEventListener('click', () => {
ipcRenderer.send('select-folder');
});
toggleServerButton.addEventListener('click', () => {
ipcRenderer.send('open-external-link', 'https://github.com/MotorBottle/Figma-Local-Font-Extractor');
});
// Update the design file list from the main process
ipcRenderer.on('update-design-file-list', (event, designFiles) => {
designFileListContainer.innerHTML = '';
designFiles.forEach((file, index) => {
const fileElement = document.createElement('div');
fileElement.className = 'design-file-record';
fileElement.innerHTML = `
<div class="design-file-details">
<div class="design-file-title">${file.fileName}</div>
<div class="design-file-updated">Updated: ${file.lastUpdatedTime}</div>
<div class="design-file-fonts">Fonts Used: ${file.fonts.join(', ')}</div>
</div>
<div class="design-file-actions">
<img src="extract.svg" id="extract-${index}" class="extract-btn" alt="Extract Fonts" title="Extract Fonts">
<img src="openDir.svg" id="open-${index}" class="open-btn" alt="Open Folder" title="Open Folder">
</div>
`;
designFileListContainer.appendChild(fileElement);
document.getElementById(`extract-${index}`).addEventListener('click', () => {
ipcRenderer.send('find-and-copy-fonts', { fontFamilies: file.fonts, destFolderName: file.folderName });
});
document.getElementById(`open-${index}`).addEventListener('click', () => {
ipcRenderer.send('open-folder', file.folderName);
});
});
});
// Handle the folder selection response
ipcRenderer.on('folder-selected', (event, path) => {
if (path) {
document.getElementById('currentPath').textContent = `Current Path: ${path}`;
} else {
document.getElementById('currentPath').textContent = 'Current Path: Not set';
}
});
ipcRenderer.on('fonts-copied', (event, { status, message, count, copiedFiles }) => {
console.log(status, message);
if (status === 'Success') {
alert(`Successfully copied ${count} font files.`);
} else if (status === 'NoneCopied') {
alert("No new fonts were copied, all fonts already exist in the destination.");
} else {
alert("An error occurred while copying fonts.");
}
// Additional logic as needed
});