-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
143 lines (123 loc) · 4.63 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const remote = require('electron').remote,
os = require('os'),
dialog = remote.dialog,
fs = require('fs-extra');
let currentWindow = remote.getCurrentWindow();
remote.getCurrentWindow().removeAllListeners('resize');
//Resize okna a zobrazení scrollbaru
currentWindow.on('resize', e => {
document.body.style.setProperty('--area-size', (currentWindow.getSize()[1] -40) + "px", '');
});
//Minimalizace okna
document.querySelector('.min-button').addEventListener('click', e => {
let window = remote.getCurrentWindow();
window.minimize();
});
//Maximalizace okna
document.querySelector('.max-button').addEventListener('click', e => {
let window = remote.getCurrentWindow();
if (!window.isMaximized()) {
window.maximize();
} else {
window.unmaximize();
}
});
//Zavření okna
document.querySelector('.close-button').addEventListener('click', e => {
let window = remote.getCurrentWindow();
window.close();
});
//Kliknutí v menu
document.body.addEventListener('click', e => {
if (e.target.dataset.section) {
loadSite(e);
} else if (e.target.dataset.result) {
iframe(e);
} else if (e.target.dataset.save) {
savefiles(e);
}/*else if (event.target.dataset.modal) {
handleModalTrigger(event)
} else if (event.target.classList.contains('modal-hide')) {
hideAllModals()
}*/
});
//Akce po spuštění aplikace
$(document).ready(() => {
$('.modal').modal();
$('.collapsible').collapsible();
//Zobrazení Welcome screen
document.getElementById("welcome-section").classList.add('is-shown');
updateBread("welcome-section");
});
//Načtení stránky
function loadSite(event) {
hideSites();
const sectionId = event.target.dataset.section + '-section';
document.getElementById(sectionId).classList.add('is-shown');
updateBread(sectionId);
}
//Zakrytí předchozí stránky
function hideSites() {
const sections = document.querySelectorAll('.is-shown');
Array.prototype.forEach.call(sections, section => {
section.classList.remove('is-shown');
});
/*const buttons = document.querySelectorAll('.nav-button.is-selected');
Array.prototype.forEach.call(buttons, function (button) {
button.classList.remove('is-selected')
});*/
}
//Aktualizace hlavičky
function updateBread(section) {
let breadcrumb = document.getElementById(section).getAttribute("breadcrumb");
let finalbreadcrumb = '<span id="windowName">';
if (breadcrumb.includes(">")) {
breadcrumb = document.getElementById(section).getAttribute("breadcrumb").split(">");
for (let i = 0; i < breadcrumb.length; i++) {
finalbreadcrumb = finalbreadcrumb + '<a class="breadcrumb">' + breadcrumb[i].trim() + '</a>';
}
} else finalbreadcrumb = finalbreadcrumb + '<a class="breadcrumb">' + breadcrumb + '</a>';
finalbreadcrumb = finalbreadcrumb + '</span>';
$("#windowName").replaceWith(finalbreadcrumb);
}
//Zpracování kódu do iframu
function iframe(event) {
const codename = event.target.dataset.result;
downloadCode(codename, result => {
$(`iframe.${codename}`).attr('src', result);
})
}
function downloadCode(codename, callback) {
const codeID = event.target.dataset.result,
blocks = $('[data-codename="' + codename + '"]'),
dir = os.homedir() + "/.learntoweb/";
fs.ensureDir(dir, err => {
if (err) throw err;
fs.emptyDir(dir, err => {
let result = true;
if (err) throw err;
for (let i = 0; i < blocks.length; i++) {
fs.writeFileSync(os.homedir() + "/.learntoweb/" + blocks[i].dataset.filename, window[codeID + "-" + blocks[i].dataset.filename].getValue());
if (blocks[i].dataset.filename.includes(".html") || blocks[i].dataset.filename.includes(".php")) result = os.homedir() + "/.learntoweb/" + blocks[i].dataset.filename;
}
callback(result);
})
});
}
function savefiles(event) {
const codename = event.target.dataset.save,
blocks = $('[data-codename="' + codename + '"]');
dialog.showOpenDialog({
title: "Vyberte složku",
properties: ["openDirectory"]
}, (folderPaths) => {
if (folderPaths === undefined){
console.log("Nebyla vybrána žádná složka kam by bylo možné uložit tento projekt");
} else {
console.log(folderPaths);
for (let i = 0; i < blocks.length; i++) {
fs.writeFileSync(folderPaths + "/" + blocks[i].dataset.filename, window[codename + "-" + blocks[i].dataset.filename].getValue());
}
}
});
}