-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (91 loc) · 3.03 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
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
88
89
90
91
92
93
94
95
96
97
const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
const { convertHandler } = require('./converthandler.js');
const dropAreas = document.querySelectorAll('#drop-area');
const closeButton = document.getElementById('CloseButton');
const updateLoad = document.getElementById('UpdateLoad');
const updateButton = document.getElementById('UpdateButton');
const restartAndUpdateButton = document.getElementById('RestartAndUpdateButton');
const minimizeButton = document.getElementById('MinimizeButton');
const convertScreen = document.getElementById('FileListContainer');
convertScreen.ConvertGroups = ConvertGroups;
// titlebar buttons onclick
closeButton.addEventListener('click', function() {
ipcRenderer.send('app/close');
});
minimizeButton.addEventListener('click', function() {
ipcRenderer.send('app/minimize');
});
const SettingsIcon = document.getElementById('SettingsIcon');
document
.getElementById('SettingsButton')
.addEventListener('mouseover', function() {
SettingsIcon.classList.add('SettingsIconHover');
});
document
.getElementById('SettingsButton')
.addEventListener('mouseout', function() {
SettingsIcon.classList.remove('SettingsIconHover');
});
ipcRenderer.on('updateMessage', () => {
updateButton.classList.remove('hidden');
});
ipcRenderer.on('updateDownloaded', () => {
updateLoad.classList.add('hidden');
restartAndUpdateButton.classList.remove('hidden');
});
function UpdateApp() {
ipcRenderer.send('app/update');
updateButton.classList.add('hidden');
updateLoad.classList.remove('hidden');
}
function RestartAndUpdate() {
ipcRenderer.send('restartAndUpdate');
}
for (const droparea of dropAreas) {
droparea.addEventListener('dragover', (e) => {
droparea.classList.add('hover');
e.preventDefault();
});
droparea.addEventListener('dragleave', () => {
droparea.classList.remove('hover');
});
droparea.addEventListener('drop', (e) => {
e.preventDefault();
UploadFiles(e.dataTransfer.items);
droparea.classList.remove('hover');
});
}
function UploadFiles(files) {
for (let i = 0; i < files.length; i++) {
if (files[i].name) {
PushFileInfo(files[i]);
continue;
}
TraverseFileTree(files[i].webkitGetAsEntry());
}
}
function TraverseFileTree(item, path) {
path = path || '';
if (item.isFile) {
item.file(function(file) {
PushFileInfo(file);
});
} else if (item.isDirectory) {
var dirReader = item.createReader();
dirReader.readEntries(function(entries) {
for (var i = 0; i < entries.length; i++) {
TraverseFileTree(entries[i], path + item.name + '/');
}
});
}
}
function PushFileInfo(file) {
convertScreen.addFile({
filetype: file.name
.substring(file.name.lastIndexOf('.') + 1)
.toLowerCase(),
filename: file.name.substring(file.name.lastIndexOf('\\') + 1),
filepath: file.path,
});
}