-
Notifications
You must be signed in to change notification settings - Fork 0
/
huxley.js
54 lines (46 loc) · 1.25 KB
/
huxley.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
"use strict";
const {readFile, writeFile} = require("fs");
const CodeMirror = require("codemirror");
require("codemirror/mode/markdown/markdown");
require("codemirror/addon/selection/active-line");
const storage = require("./storage");
document.addEventListener("DOMContentLoaded", () => {
const editor = new CodeMirror(document.querySelector(".editor"), {
autofocus: true,
lineWrapping: true,
mode: "markdown",
styleActiveLine: true,
theme: "huxley-light",
value: storage.get()
});
if (process.platform === "darwin") {
const Titlebar = require("./Titlebar");
const titlebar = new Titlebar("Huxley");
if (process.env.NODE_ENV === "development") {
titlebar.setTitle("Huxley - Experimental Build");
}
document.body.classList.add("platform-macos");
document.body.appendChild(titlebar.getElement());
}
window.huxley = {
readFile: (path) => {
readFile(path, "utf8", (err, content) => {
if (err) {
editor.setValue(err.message);
} else {
editor.setValue(content);
}
});
},
writeFile: (path) => {
writeFile(path, editor.getValue(), "utf8", (err) => {
if (err) {
editor.setValue(err.message);
}
});
}
};
window.addEventListener("beforeunload", () => {
storage.set(editor.getValue());
});
});