Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 94c6a4c
Showing
8 changed files
with
2,768 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!doctype html> | ||
|
||
<style> | ||
html, body { | ||
margin: 0; | ||
overflow: hidden; | ||
} | ||
|
||
form { | ||
display: flex; | ||
} | ||
|
||
input { | ||
flex: 1; | ||
font-size: 72px; | ||
padding: 5px; | ||
color: #333; | ||
font-family: avenir next; | ||
outline: none; | ||
} | ||
</style> | ||
|
||
<body hidden> | ||
<form id="form"> | ||
<input id="input" autofocus> | ||
<submit hidden></submit> | ||
</form> | ||
|
||
<script> | ||
let electron = require("electron") | ||
|
||
document.getElementById("form").addEventListener("submit", event => { | ||
electron.ipcRenderer.send( | ||
"add-note", | ||
document.getElementById("input").value | ||
) | ||
|
||
event.preventDefault() | ||
}) | ||
|
||
document.body.removeAttribute("hidden") | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
let { | ||
app, | ||
globalShortcut, | ||
BrowserWindow, | ||
ipcMain | ||
} = require("electron") | ||
|
||
let fs = require("fs") | ||
let os = require("os") | ||
|
||
/** | ||
* @type {BrowserWindow} | ||
*/ | ||
let window | ||
|
||
let notesFile = os.homedir() + "/notes" | ||
|
||
function show ({width, height, name}) { | ||
window.hide() | ||
window.setSize(width, height) | ||
window.center() | ||
window.loadFile(`${name}.html`) | ||
setTimeout(() => { | ||
window.show() | ||
}, 200) | ||
} | ||
|
||
function showAddNote () { | ||
show({ | ||
width: 800, | ||
height: 100, | ||
name: "add-note" | ||
}) | ||
} | ||
|
||
function showNotes () { | ||
show({ | ||
width: 800, | ||
height: 800, | ||
name: "notes" | ||
}) | ||
} | ||
|
||
app.on("ready", () => { | ||
window = new BrowserWindow({ | ||
width: 800, | ||
height: 100, | ||
frame: false, | ||
resizable: false, | ||
show: false | ||
}) | ||
|
||
window.webContents.on("before-input-event", (event, input) => { | ||
if (input.key == "Enter" || input.key == "Escape") { | ||
window.hide() | ||
} | ||
}) | ||
|
||
ipcMain.on("add-note", (event, note) => { | ||
fs.appendFileSync(notesFile, note + "\n") | ||
window.hide() | ||
}) | ||
|
||
window.on("close", event => { | ||
event.preventDefault() | ||
window.hide() | ||
}) | ||
|
||
globalShortcut.register( | ||
"Command+Alt+Space", | ||
showAddNote | ||
) | ||
|
||
globalShortcut.register( | ||
"Command+Control+Alt+Space", | ||
showNotes | ||
) | ||
|
||
app.on("will-quit", () => { | ||
// Unregister all shortcuts. | ||
globalShortcut.unregisterAll() | ||
}) | ||
|
||
app.on("window-all-closed", Function.prototype) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<style> | ||
html, body { | ||
margin: 0; | ||
} | ||
body { | ||
font-family: avenir next; | ||
font-size: 36px; | ||
color: #222; | ||
padding: 1em; | ||
} | ||
ul { | ||
list-style-type: none; | ||
padding: 0; | ||
line-height: 1.5; | ||
} | ||
[type="checkbox"] { | ||
vertical-align: middle; | ||
margin-right: 10px; | ||
} | ||
:checked + label { | ||
text-decoration: line-through; | ||
color: #2222; | ||
} | ||
</style> | ||
<body hidden> | ||
<main id="main" role="main"> | ||
<ul id="ul"> | ||
|
||
</ul> | ||
</main> | ||
<script> | ||
let main = document.getElementById("main") | ||
|
||
let fs = require("fs") | ||
let os = require("os") | ||
let electron = require("electron") | ||
let notesFile = os.homedir() + "/notes" | ||
|
||
let notes = fs.readFileSync(notesFile, "utf-8") | ||
.split("\n") | ||
.filter(Boolean) | ||
|
||
function deleteNotes (checkies) { | ||
let filtered = notes.filter((note, index) => { | ||
return !checkies[index].checked | ||
}) | ||
|
||
fs.writeFileSync(notesFile, filtered.join("\n") + "\n") | ||
} | ||
|
||
function toggleNote (event) { | ||
let {index} = event.target | ||
let checky = event.target.querySelector("[type=\"checkbox\"]") | ||
checky.checked = !checky.checked | ||
} | ||
|
||
function render (notes) { | ||
let ul = document.createElement("ul") | ||
ul.id = "ul" | ||
if (notes.length) { | ||
notes.forEach((note, index) => { | ||
let li = document.createElement("li") | ||
let checky = document.createElement("input") | ||
checky.type = "checkbox" | ||
checky.id = `checky-${index}` | ||
let label = document.createElement("label") | ||
label.setAttribute("for", checky.id) | ||
label.textContent = note | ||
li.prepend(checky) | ||
li.append(label) | ||
li.index = index | ||
li.addEventListener("click", toggleNote) | ||
ul.appendChild(li) | ||
}) | ||
} | ||
let old = document.getElementById("ul") | ||
main.replaceChild(ul, old) | ||
} | ||
|
||
let askToBeClosed = () => | ||
electron.ipcRenderer("please-close-notes") | ||
|
||
window.addEventListener("beforeunload", event => { | ||
event.preventDefault() | ||
deleteNotes(document.querySelectorAll("[type=\"checkbox\"]")) | ||
askToBeClosed() | ||
return true | ||
}) | ||
|
||
render(notes) | ||
|
||
document.body.removeAttribute("hidden") | ||
</script> |
Oops, something went wrong.