-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.js
More file actions
41 lines (34 loc) · 1.43 KB
/
renderer.js
File metadata and controls
41 lines (34 loc) · 1.43 KB
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
let currentFileName = 'No File Selected'
let currentFilePath = ''
const btnNew = document.getElementById('btn-new')
const btnOpen = document.getElementById('btn-open')
const btnSave = document.getElementById('btn-save')
const btnSaveAs = document.getElementById('btn-save-as')
const btnMode = document.getElementById('btn-mode')
const h1CurrentFile = document.getElementById('current-file')
const textArea = document.getElementById('text-area')
btnMode.value = window.darkMode ? '🌙' : '🔆'
h1CurrentFile.innerHTML = currentFileName
document.getElementById('btn-mode').addEventListener('click', async () => {
const isDarkMode = await window.darkMode.toggle()
document.getElementById('btn-mode').value = isDarkMode ? '🔆' : '🌙'
})
btnNew.addEventListener('click', (e) => {
currentFileName = 'No File Selected'
currentFilePath = ''
h1CurrentFile.innerHTML = currentFileName
textArea.value = ''
})
btnOpen.addEventListener('click', async () => {
const { fileName, filePath, fileData } = file = await window.electronAPI.openFile()
currentFileName = fileName
currentFilePath = filePath
h1CurrentFile.innerHTML = currentFileName
textArea.value = fileData
})
btnSave.addEventListener('click', (e) => {
window.electronAPI.saveFile({from: 'save', data: textArea.value, path: currentFilePath})
})
btnSaveAs.addEventListener('click', (e) => {
window.electronAPI.saveFile({from: 'saveas', data: textArea.value, path: currentFilePath})
})