Skip to content

Commit 1bf2b3a

Browse files
committed
Code cleanup and minor performance enhancements, added an icon.
1 parent 23676fc commit 1bf2b3a

File tree

11 files changed

+110
-94
lines changed

11 files changed

+110
-94
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stickynoteapp",
3-
"version": "0.2.0",
3+
"version": "0.2.5",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",

public/Icon.png

5.41 KB
Loading

public/icon.ico

290 KB
Binary file not shown.

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7-
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
7+
<link rel="icon" href="<%= BASE_URL %>icon.ico">
88
<link rel="stylesheet" type="text/css" href="./style.css">
99
<link rel="stylesheet" type="text/css" href="./all.min.css">
1010
<title>stickynoteapp</title>

src/assets/Icon.png

5.41 KB
Loading

src/assets/icon.ico

290 KB
Binary file not shown.

src/background.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
installVueDevtools
77
} from 'vue-cli-plugin-electron-builder/lib'
88
const isDevelopment = process.env.NODE_ENV !== 'production'
9-
9+
const nativeImage = require('electron').nativeImage;
10+
var image = nativeImage.createFromPath(__dirname + '/assets/icon.png');
11+
image.setTemplateImage(true);
12+
console.log(__dirname + '/assets/icon.png')
1013
// Keep a global reference of the window object, if you don't, the window will
1114
// be closed automatically when the JavaScript object is garbage collected.
1215
let win;
@@ -23,7 +26,8 @@ function createWindow () {
2326
autoHideMenuBar: true,
2427
transparent: true,
2528
frame: false,
26-
resizable:true
29+
resizable:true,
30+
icon: image
2731
})
2832

2933
if (process.env.WEBPACK_DEV_SERVER_URL) {

src/components/Editor.vue

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
<script lang="ts">
88
const HyperMD = require("hypermd");
99
import { readFile, writeFile, rename } from "fs";
10-
import * as path from "path";
10+
import { clearInterval } from "timers";
1111
import { Component, Prop, Vue } from "vue-property-decorator";
12+
import * as path from "path";
1213
import "hypermd/theme/hypermd-light.css";
1314
import "@/theme/sticky.css";
14-
import Configuration from "../utility/Configuration";
15-
import { clearInterval } from "timers";
15+
import Configuration from "@/utility/Configuration";
16+
import VueEmitter from "@/utility/VueEmitter"
1617
1718
@Component
18-
export default class Editor extends Vue {
19+
export default class Editor extends VueEmitter {
1920
private internalEditor: any;
2021
private saveWatcher: any;
2122
private config;
@@ -26,35 +27,29 @@ export default class Editor extends Vue {
2627
}
2728
2829
mounted() {
29-
console.log("Mounted");
3030
Configuration.getConfig()
3131
.then(c => {
3232
this.config = c;
3333
this.loadFile(c.defaultNote);
3434
this.registerEvents();
35-
})
36-
.catch(console.log);
35+
}).catch(console.log);
3736
}
3837
3938
loadFile(file) {
40-
console.log("fileName: " + file);
4139
this.file = file;
42-
console.log("this.file: " + this.file);
43-
console.log("this.filePath: " + this.filePath);
4440
readFile(this.filePath(), { encoding: "utf8" }, (e: any, d: any) => {
45-
console.log(e);
4641
this.emitFileLoaded();
4742
this.configureEditor(d);
4843
});
44+
4945
}
5046
5147
emitFileLoaded() {
52-
console.log(this.filePath());
53-
this.$root.$emit("fileLoaded", path.parse(this.filePath()).name);
48+
this.rootEmit("fileLoaded", path.parse(this.filePath()).name);
5449
}
5550
5651
registerEvents() {
57-
this.registerRootEvent("fileNameUpdated", (f: string) => {
52+
this.registerRootEvent("fileNameUpdated", f => {
5853
rename(
5954
this.filePath(),
6055
path.join(path.parse(this.filePath()).dir, f + ".md"),
@@ -64,15 +59,8 @@ export default class Editor extends Vue {
6459
}
6560
);
6661
});
67-
this.registerRootEvent("fileChange", (f: string) => {
68-
this.loadFile(f);
69-
});
70-
71-
this.registerRootEvent("closing", (_: any) =>
72-
this.Save(e => {
73-
this.$emit("finished");
74-
})
75-
);
62+
this.registerRootEvent("fileChange", this.loadFile);
63+
this.registerRootEvent("closing", _ => this.Save(_ => this.$emit("finished")));
7664
}
7765
7866
registerRootEvent(eventName, callback) {
@@ -97,22 +85,11 @@ export default class Editor extends Vue {
9785
}
9886
9987
private configureEditor(defaultValue) {
100-
console.log(this.config.editorConfig)
101-
console.log(defaultValue)
102-
if (!this.internalEditor) {
103-
this.internalEditor = HyperMD.fromTextArea(
104-
document.getElementById("input-area"),
105-
this.config.editorConfig
106-
);
107-
}
88+
if(!this.internalEditor) this.internalEditor = HyperMD.fromTextArea(document.getElementById("input-area"),this.config.editorConfig);
10889
this.internalEditor.setValue(defaultValue.toString());
10990
this.internalEditor.markClean();
11091
this.StartSaveWatch();
11192
}
112-
113-
private isClean() {
114-
return this.internalEditor.isClean();
115-
}
11693
}
11794
</script>
11895

src/components/NavBar.vue

Lines changed: 83 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,130 @@
11
<template>
22
<div id="NavBar">
33
<div id="controls">
4-
<a v-on:click="close()"><i class="fas fa-window-close"></i></a>
4+
<a v-on:click="close()">
5+
<i class="fas fa-window-close"></i>
6+
</a>
57
<!-- <a v-on:click="restore()"><i class="fas fa-window-restore"></i></a> -->
6-
<a v-on:click="minimize()"><i class="fas fa-minus-square"></i></a>
7-
<a v-on:click="pin()"><i class="fas fa-thumbtack"></i></a>
8+
<a v-on:click="minimize()">
9+
<i class="fas fa-minus-square"></i>
10+
</a>
11+
<a v-on:click="pin()">
12+
<i class="fas fa-thumbtack"></i>
13+
</a>
814
</div>
915
<input v-on:change="updateFileName" v-model="fileName" type="text" name="fileName">
1016
<select
11-
v-on:change="changeFile"
17+
v-on:change="changeFile()"
1218
v-model="SelectedFile"
1319
id="filePicker"
1420
style="margin-left:20px;"
1521
name="selectedFile"
1622
>
17-
<option v-for="file in Files()" :value="file.value" :key="file.id" :id=file.id >{{ file.value }}</option>
23+
<option
24+
v-for="file in Files()"
25+
:value="file.value"
26+
:key="file.id"
27+
:id="file.id"
28+
>{{ file.value }}</option>
1829
</select>
19-
<a v-on:click="newNote()"><i class="fas fa-file-medical"></i></a>
20-
<a v-on:click="deleteNote()"><i class="fas fa-trash"></i></a>
30+
<a v-on:click="newNote()">
31+
<i class="fas fa-file-medical"></i>
32+
</a>
33+
<a v-on:click="deleteNote()">
34+
<i class="fas fa-trash"></i>
35+
</a>
2136
</div>
2237
</template>
2338

2439
<script lang="ts">
2540
import { Component, Prop, Vue } from "vue-property-decorator";
26-
import * as fs from "fs";
41+
import {unlink, writeFile, readdirSync} from "fs";
2742
import * as path from "path";
28-
import Configuration from '@/utility/Configuration';
29-
const remote = require('electron').remote;
43+
import Configuration from "@/utility/Configuration";
44+
import VueEmitter from "@/utility/VueEmitter";
45+
const remote = require("electron").remote;
46+
const defaultNoteText =
47+
"# Welcome to your new note!\nLet's write something awesome.";
3048
3149
@Component
32-
export default class NavBar extends Vue {
50+
export default class NavBar extends VueEmitter {
3351
private fileName: string = "";
3452
private SelectedFile = "";
3553
private isMaximized = false;
36-
updateFileName() {
37-
this.$root.$emit("fileNameUpdated", this.fileName);
54+
private configuration;
55+
56+
private Files() {
57+
return readdirSync("notes").map((v, i) => {
58+
return { id: i, value: v };
59+
});
60+
}
61+
62+
public mounted() {
63+
Configuration.getConfig().then(c => {
64+
this.configuration = c;
65+
this.registerEvents();
66+
});
3867
}
39-
changeFile() {
40-
this.$root.$emit("fileChange", this.SelectedFile);
68+
69+
private updateFileName() {
70+
this.rootEmit("fileNameUpdated", this.fileName);
4171
}
42-
mounted() {
43-
this.registerEvents();
72+
private changeFile() {
73+
this.rootEmit("fileChange", this.SelectedFile);
4474
}
45-
75+
4676
private registerEvents() {
47-
this.$root.$on("fileLoaded", (f: string) => {
77+
this.$root.$on("fileLoaded", f => {
78+
console.log("Test");
4879
this.fileName = f;
4980
this.SelectedFile = this.fileName + ".md";
5081
});
5182
}
5283
53-
Files(){
54-
return fs.readdirSync("notes").map((v, i) =>{ return { id: i, value: v }});
84+
private restore() {
85+
this.isMaximized
86+
? remote.getCurrentWindow().unmaximize()
87+
: remote.getCurrentWindow().maximize();
88+
this.isMaximized = !this.isMaximized;
5589
}
56-
// private readNotes(callback?){
57-
// fs.readdir("notes", (e, f) => {
58-
// this.Files = f.map((v, i) => {
59-
// return { id: i, value: v };
60-
// });
61-
// callback()
62-
// });
63-
// }
6490
65-
close() {
66-
this.$root.$emit("closing");
91+
private pin() {
92+
remote
93+
.getCurrentWindow()
94+
.setAlwaysOnTop(!remote.getCurrentWindow().isAlwaysOnTop());
6795
}
6896
69-
pin(){
70-
const remote = require('electron').remote;
71-
let w = remote.getCurrentWindow();
72-
w.setAlwaysOnTop(!w.isAlwaysOnTop())
73-
}
74-
restore(){
75-
this.isMaximized ? remote.getCurrentWindow().unmaximize() : remote.getCurrentWindow().maximize();
76-
this.isMaximized = !this.isMaximized;
97+
private minimize() {
98+
remote.getCurrentWindow().minimize();
7799
}
78100
79-
minimize(){
80-
remote.getCurrentWindow().minimize();
101+
private close() {
102+
this.rootEmit("closing");
81103
}
82-
83104
84-
newNote(){
85-
let FileName = `${Date.now()}.md`
86-
fs.writeFile(path.join(new Configuration().notePath,FileName),"# Welcome to your new note!\nLet's write something awesome.","",_=>{
87-
this.SelectedFile = FileName;
88-
this.fileName = FileName;
89-
this.$root.$emit("fileChange", this.SelectedFile);
90-
});
105+
private newNote() {
106+
let FileName = `${Date.now()}.md`;
107+
writeFile(
108+
path.join(new Configuration().notePath, FileName),
109+
defaultNoteText,
110+
"",
111+
_ => {
112+
this.setFileName(FileName);
113+
}
114+
);
91115
}
92116
93-
deleteNote(){
117+
private deleteNote() {
94118
confirm(`This will permantly delete "${this.SelectedFile}". Continue?`);
95-
fs.unlink(path.join(new Configuration().notePath,this.SelectedFile), _ =>{
96-
this.SelectedFile = this.Files()[0].value;
97-
this.fileName = this.Files()[0].value;
98-
this.changeFile();
99-
});
119+
unlink(path.join(this.configuration.notePath, this.SelectedFile), _ =>
120+
this.setFileName(this.Files()[0].value)
121+
);
122+
}
123+
124+
private setFileName(fileName) {
125+
this.SelectedFile = fileName;
126+
this.fileName = fileName.replace(/.md$/, "");
127+
this.changeFile();
100128
}
101129
}
102130
</script>

src/utility/FileManager.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)