-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFile.js
82 lines (69 loc) · 2.19 KB
/
createFile.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
var commandName = document.getElementById("commandName");
var filePath = document.getElementById("filePath");
var additionalParameters = document.getElementById("additionalParameters");
var componentList = document.getElementById("additionalContent");
var Store = require('electron-store');
var remote = require('electron').remote;
var fs = remote.require('fs');
var win = remote.getCurrentWindow();
var dialog = remote.dialog;
var store = new Store();
var onChooseFile = new Event('onChooseFile', {bubbles: true});
var onChooseFolder = new Event('onChooseFolder', {bubbles: true});
var onChangeCommand = new Event('onChangeCommand', {bubbles: true});
win.setMinimumSize(500, 500);
win.setSize(500, 500);
var data = store.get('Commands');
var filePicker = document.getElementById("filePicker");
filePath.addEventListener("change", filePathChanged());
//Button choose file
function chooseFile(){
filePath.value = dialog.showOpenDialogSync({properties:['openFile']});
filePath.dispatchEvent(onChooseFile);
}
//Button choose folder
function chooseFolder(){
filePath.value = dialog.showOpenDialogSync({properties:['openDirectory']});
filePath.dispatchEvent(onChooseFolder);
}
//Custom user Input
function filePathChanged(){
try{
var path = fs.lstatSync(filePath.value);
if(path.isDirectory()){
filePath.dispatchEvent(onChooseFolder);
}
else if(path.isFile()){
filePath.dispatchEvent(onChooseFile);
}
}catch(e){
console.log("File does not exist");
}
filePath.dispatchEvent(onChangeCommand)
}
function saveEntry(){
//Forgot Name
if(commandName.value.length === 0){
commandName.style.border = "solid 2px red";
return
}
//Forgot filePath
if(filePath.value.length === 0){
filePath.style.border = "solid 2px red";
return
}
//Store command
data = store.get('Commands');
data.push({
"Name": commandName.value,
"Command": filePath.value,
"Parameter": additionalParameters.value,
"Used": 0
});
store.set("Commands", data);
goToIndex();
}
//Return to main page
function goToIndex(){
window.location.href = "index.html";
}