-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
37 lines (30 loc) · 1.29 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
const { ipcRenderer } = require("electron");
const path = require("path");
window.addEventListener("DOMContentLoaded", () => {
createDocumentBtn = document.getElementById("createDocumentBtn");
openDocumentBtn = document.getElementById("openDocumentBtn");
documentName = document.getElementById("documentName");
fileTextarea = document.getElementById("fileTextarea");
saveBtn = document.getElementById("saveBtn");
const handleDocumentChange = (filePath, content) => {
documentName.innerText = path.basename(filePath);
fileTextarea.removeAttribute("disabled");
fileTextarea.value = content;
fileTextarea.focus();
};
createDocumentBtn.addEventListener("click", () => {
ipcRenderer.send("create-document-triggered");
});
ipcRenderer.on("document-created", (_, filePath) => {
handleDocumentChange(filePath, "");
});
openDocumentBtn.addEventListener("click", () => {
ipcRenderer.send("open-document-triggered");
});
ipcRenderer.on("document-opened", (_, { filePath, content }) => {
handleDocumentChange(filePath, content);
});
saveBtn.addEventListener("click", () => {
ipcRenderer.send("save-document", fileTextarea.value);
});
});