Skip to content

Commit 9bc48ae

Browse files
committed
Fixed several errors (mostly startup errors due to unset variables or missing files that get created on first update cycle), Fixed more styling issues, Improved settings display and function, where there are no notes, one is created and set as default. Additional editors should no longer be created due to them not being destroyed
1 parent e6ceec2 commit 9bc48ae

File tree

9 files changed

+100
-153
lines changed

9 files changed

+100
-153
lines changed

config.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

package-lock.json

Lines changed: 10 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stickynoteapp",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"codemirror": "^5.43.0",
14+
"fs-extra": "^7.0.1",
1415
"hypermd": "^0.3.11",
1516
"vue": "^2.5.21",
1617
"vue-class-component": "^6.0.0",

public/style.css

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,14 @@ body {
9090
border-radius: 5px;
9191
color: white;
9292
padding: 5px;
93-
margin-top:20px;
9493
text-align: center;
9594
text-decoration: none;
9695
}
96+
9797
#settings{
9898
overflow: hidden;
9999
}
100100

101101
#settings form{
102102
padding:10px;
103-
}
104-
105-
#settings form p{
106-
overflow: hidden;
107-
text-overflow: ellipsis;
108-
max-width: 100vw;
109-
color:red;
110103
}

src/background.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,6 @@ function createWindow() {
4747

4848
}
4949

50-
import * as fs from 'fs';
51-
import * as path from 'path';
52-
function ensureExists(callback) {
53-
Configuration.getConfig().then(c => {
54-
fs.exists(c.notePath, folderExists => {
55-
if (!folderExists) {
56-
createDirectory(c, _ => {
57-
createDefault(c, _ => callback());
58-
})
59-
} else {
60-
fs.exists(path.join(c.notePath, c.defaultNote), fileExists => {
61-
if (!fileExists) createDefault(c, _ => callback())
62-
else callback();
63-
})
64-
};
65-
})
66-
});
67-
}
68-
69-
function createDirectory(config: Configuration, callback) {
70-
fs.mkdir(config.notePath, e => {
71-
if (e){
72-
console.log(e);
73-
alert(e);
74-
process.exit();
75-
}else{
76-
callback(e);
77-
}
78-
});
79-
}
80-
81-
function createDefault(config: Configuration, callback) {
82-
fs.writeFile(path.join(config.notePath, config.defaultNote), "# Welcome to your new note!\nLet's write something awesome.", e => {
83-
callback(e)
84-
})
85-
}
8650

8751
// Quit when all windows are closed.
8852
app.on('window-all-closed', () => {
@@ -109,10 +73,7 @@ app.on('ready', async () => {
10973
// Install Vue Devtools
11074
await installVueDevtools()
11175
}
112-
113-
ensureExists(function(){
114-
createWindow()
115-
})
76+
createWindow();
11677
})
11778

11879
var locked = app.requestSingleInstanceLock();

src/components/Editor.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import VueEmitter from "@/utility/VueEmitter"
1919
export default class Editor extends VueEmitter {
2020
private internalEditor: any;
2121
private saveWatcher: any;
22-
private config:Configuration = new Configuration();
22+
private config;
2323
private file;
24-
2524
private filePath() {
2625
return path.join(this.config.notePath, this.file);
2726
}
@@ -34,6 +33,11 @@ export default class Editor extends VueEmitter {
3433
this.registerEvents();
3534
}).catch(console.log);
3635
}
36+
destroyed() {
37+
document.removeChild(document.getElementsByClassName("CodeMirror")[0])
38+
this.internalEditor = null;
39+
clearInterval(this.saveWatcher);
40+
}
3741
3842
loadFile(file) {
3943
this.file = file;
@@ -67,10 +71,7 @@ export default class Editor extends VueEmitter {
6771
this.$root.$on(eventName, callback);
6872
}
6973
70-
destroyed() {
71-
this.internalEditor = null;
72-
clearInterval(this.saveWatcher);
73-
}
74+
7475
7576
private Save(handler: ((err: Error) => void)) {
7677
writeFile(this.filePath(), this.internalEditor.getValue(), handler);
@@ -84,7 +85,7 @@ export default class Editor extends VueEmitter {
8485
}, 5000);
8586
}
8687
87-
private configureEditor(defaultValue) {
88+
private configureEditor(defaultValue = "") {
8889
if(!this.internalEditor) this.internalEditor = HyperMD.fromTextArea(document.getElementById("input-area"),this.config.editorConfig);
8990
this.internalEditor.setValue(defaultValue.toString());
9091
this.internalEditor.markClean();

src/utility/Configuration.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { access, writeFile, constants as fsConstants, readFile } from 'fs';
1+
import {pathExists, writeFile, ensureDir, readFile} from "fs-extra"
22
import {join} from "path";
33
import { remote } from 'electron';
44
const configPath = join(remote.app.getPath('userData'), "config.json")
@@ -19,14 +19,18 @@ export default class Configuration {
1919
static getConfig(){
2020
var stashed = new Configuration()
2121
return new Promise<Configuration>((r,e) =>{
22-
access(configPath, fsConstants.F_OK, (err) => {
23-
if(err) writeFile(configPath,JSON.stringify(stashed,null,"\t"),ex =>{
24-
if(ex) e(ex)
25-
this.readFile(stashed,r);
22+
pathExists(configPath, (err, exists) =>{
23+
if(err) e(err);
24+
if(!err && !exists) writeFile(configPath,JSON.stringify(stashed,null,"\t"),err =>{
25+
if(err) e(err)
26+
this.readFile(stashed,c =>{
27+
ensureDir(c.notePath).then(e=>r(c))
28+
});
2629
})
27-
this.readFile(stashed,r);
28-
});
29-
30+
else this.readFile(stashed,c =>{
31+
ensureDir(c.notePath).then(e=>r(c))
32+
});
33+
})
3034
})
3135
}
3236

@@ -38,14 +42,10 @@ export default class Configuration {
3842
}
3943

4044
saveConfig(callback?){
41-
//TODO: This is a hack, but vue adds some junk data when binding
42-
delete (<any>this).data
43-
delete (<any>this).type
44-
console.log(JSON.stringify(this,null,"\t"))
4545
writeFile(configPath,JSON.stringify(this, null, "\t"),(e) => {
46-
if(callback) callback(e);
47-
else console.log(e);
48-
})
46+
if(callback) callback
47+
else console.log(e)
48+
});
4949
}
5050
}
5151

0 commit comments

Comments
 (0)