-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrenderer.js
38 lines (31 loc) · 1.18 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
const { ipcRenderer } = require("electron");
const path = require("path");
window.addEventListener("DOMContentLoaded", () => {
const el = {
documentName: document.getElementById("documentName"),
createDocumentBtn: document.getElementById("createDocumentBtn"),
openDocumentBtn: document.getElementById("openDocumentBtn"),
fileTextarea: document.getElementById("fileTextarea"),
};
const handleDocumentChange = (filePath, content = "") => {
el.documentName.innerHTML = path.parse(filePath).base;
el.fileTextarea.removeAttribute("disabled");
el.fileTextarea.value = content;
el.fileTextarea.focus();
};
el.createDocumentBtn.addEventListener("click", () => {
ipcRenderer.send("create-document-triggered");
});
el.openDocumentBtn.addEventListener("click", () => {
ipcRenderer.send("open-document-triggered");
});
el.fileTextarea.addEventListener("input", (e) => {
ipcRenderer.send("file-content-updated", e.target.value);
});
ipcRenderer.on("document-opened", (_, { filePath, content }) => {
handleDocumentChange(filePath, content);
});
ipcRenderer.on("document-created", (_, filePath) => {
handleDocumentChange(filePath);
});
});