Skip to content

Commit 231b877

Browse files
authored
Safer backend
2 parents 3aa00fc + c09a59c commit 231b877

9 files changed

+355
-111
lines changed

data/com.vixalien.sticky.gschema.xml.in

+5
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@
3838
The selected color scheme. 0 = follow system style, 1 = light, 2 = dark
3939
</description>
4040
</key>
41+
<key name="show-all-notes" type="b">
42+
<default>true</default>
43+
<summary>Show all notes</summary>
44+
<description>Whether to show the all notes window or note</description>
45+
</key>
4146
</schema>
4247
</schemalist>

src/application.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import GLib from "gi://GLib";
3030
import Gtk from "gi://Gtk?version=4.0";
3131

3232
import { StickyNotes } from "./notes.js";
33-
import { load_notes, Note, save_notes, settings } from "./util.js";
33+
import { Note, settings } from "./util.js";
34+
import { delete_note, load_notes, save_notes } from "./store.js";
3435
import { Window } from "./window.js";
3536

3637
export class Application extends Adw.Application {
@@ -41,11 +42,8 @@ export class Application extends Adw.Application {
4142
GObject.registerClass(this);
4243
}
4344

44-
// notes: Note[] = [];
4545
notes_list = Gio.ListStore.new(Note.$gtype) as Gio.ListStore<Note>;
4646

47-
show_all_notes = false;
48-
4947
sort_notes() {
5048
this.notes_list.sort((note1: Note, note2: Note) => {
5149
return note1.modified.compare(note2.modified);
@@ -62,13 +60,12 @@ export class Application extends Adw.Application {
6260

6361
this.init_actions();
6462

65-
const data = load_notes() || [];
66-
67-
this.show_all_notes = data.state.all_notes;
63+
load_notes()
64+
.then((notes) => {
65+
notes.forEach((note) => this.notes_list.append(note));
6866

69-
data.notes.forEach((note) => this.notes_list.append(note));
70-
71-
this.sort_notes();
67+
this.sort_notes();
68+
}).catch(logError);
7269
}
7370

7471
save() {
@@ -78,9 +75,7 @@ export class Application extends Adw.Application {
7875
array.push(note);
7976
});
8077

81-
save_notes(array, {
82-
all_notes: this.show_all_notes,
83-
});
78+
return save_notes(array);
8479
}
8580

8681
public vfunc_shutdown() {
@@ -94,7 +89,7 @@ export class Application extends Adw.Application {
9489
// we show the all_notes
9590
let has_one_open = false;
9691

97-
if (this.show_all_notes) this.all_notes();
92+
if (settings.get_boolean("show-all-notes")) this.all_notes();
9893

9994
this.foreach_note((note) => {
10095
if (note.open) {
@@ -104,7 +99,7 @@ export class Application extends Adw.Application {
10499
});
105100

106101
if (!has_one_open) {
107-
this.show_all_notes = true;
102+
settings.set_boolean("show-all-notes", true);
108103
this.all_notes();
109104
}
110105
}
@@ -330,6 +325,8 @@ export class Application extends Adw.Application {
330325

331326
if (found_id !== undefined) this.notes_list.splice(found_id, 1, []);
332327
if (found_window) found_window.close();
328+
329+
delete_note(uuid);
333330
}
334331

335332
all_notes() {
@@ -348,12 +345,14 @@ export class Application extends Adw.Application {
348345

349346
this.window.connect("close-request", () => {
350347
this.window = null;
351-
this.show_all_notes = false;
348+
settings.set_boolean("show-all-notes", false);
352349
});
353350

354351
this.window.add_controller(this.new_controller());
355352
}
356353

354+
settings.set_boolean("show-all-notes", true);
355+
357356
this.window.present();
358357
}
359358

src/com.vixalien.sticky.src.gresource.xml

+2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
<gresource prefix="/com/vixalien/sticky/js">
44
<file>application.js</file>
55
<file>card.js</file>
6+
<file>errors.js</file>
67
<file>main.js</file>
78
<file>notes.js</file>
89
<file>styleselector.js</file>
10+
<file>store.js</file>
911
<file>themeselector.js</file>
1012
<file>view.js</file>
1113
<file>window.js</file>

src/errors.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export enum StickyErrorType {
2+
FILE_NOT_FOUND,
3+
FILE_CORRUPTED,
4+
NO_PERMISSION,
5+
UNKNOWN,
6+
}
7+
8+
export class StickyError {
9+
message: string;
10+
type: StickyErrorType;
11+
12+
constructor(type: StickyErrorType, message: string) {
13+
this.message = message;
14+
this.type = type;
15+
}
16+
}

src/meson.build

+2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ gnome = import('gnome')
33
sources = [
44
'application.ts',
55
'card.ts',
6+
'errors.ts',
67
'main.ts',
78
'notes.ts',
89
'styleselector.ts',
10+
'store.ts',
911
'themeselector.ts',
1012
'view.ts',
1113
'window.ts',

0 commit comments

Comments
 (0)