@@ -30,7 +30,8 @@ import GLib from "gi://GLib";
30
30
import Gtk from "gi://Gtk?version=4.0" ;
31
31
32
32
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" ;
34
35
import { Window } from "./window.js" ;
35
36
36
37
export class Application extends Adw . Application {
@@ -41,11 +42,8 @@ export class Application extends Adw.Application {
41
42
GObject . registerClass ( this ) ;
42
43
}
43
44
44
- // notes: Note[] = [];
45
45
notes_list = Gio . ListStore . new ( Note . $gtype ) as Gio . ListStore < Note > ;
46
46
47
- show_all_notes = false ;
48
-
49
47
sort_notes ( ) {
50
48
this . notes_list . sort ( ( note1 : Note , note2 : Note ) => {
51
49
return note1 . modified . compare ( note2 . modified ) ;
@@ -62,13 +60,12 @@ export class Application extends Adw.Application {
62
60
63
61
this . init_actions ( ) ;
64
62
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 ) ) ;
68
66
69
- data . notes . forEach ( ( note ) => this . notes_list . append ( note ) ) ;
70
-
71
- this . sort_notes ( ) ;
67
+ this . sort_notes ( ) ;
68
+ } ) . catch ( logError ) ;
72
69
}
73
70
74
71
save ( ) {
@@ -78,9 +75,7 @@ export class Application extends Adw.Application {
78
75
array . push ( note ) ;
79
76
} ) ;
80
77
81
- save_notes ( array , {
82
- all_notes : this . show_all_notes ,
83
- } ) ;
78
+ return save_notes ( array ) ;
84
79
}
85
80
86
81
public vfunc_shutdown ( ) {
@@ -94,7 +89,7 @@ export class Application extends Adw.Application {
94
89
// we show the all_notes
95
90
let has_one_open = false ;
96
91
97
- if ( this . show_all_notes ) this . all_notes ( ) ;
92
+ if ( settings . get_boolean ( "show-all-notes" ) ) this . all_notes ( ) ;
98
93
99
94
this . foreach_note ( ( note ) => {
100
95
if ( note . open ) {
@@ -104,7 +99,7 @@ export class Application extends Adw.Application {
104
99
} ) ;
105
100
106
101
if ( ! has_one_open ) {
107
- this . show_all_notes = true ;
102
+ settings . set_boolean ( "show-all-notes" , true ) ;
108
103
this . all_notes ( ) ;
109
104
}
110
105
}
@@ -330,6 +325,8 @@ export class Application extends Adw.Application {
330
325
331
326
if ( found_id !== undefined ) this . notes_list . splice ( found_id , 1 , [ ] ) ;
332
327
if ( found_window ) found_window . close ( ) ;
328
+
329
+ delete_note ( uuid ) ;
333
330
}
334
331
335
332
all_notes ( ) {
@@ -348,12 +345,14 @@ export class Application extends Adw.Application {
348
345
349
346
this . window . connect ( "close-request" , ( ) => {
350
347
this . window = null ;
351
- this . show_all_notes = false ;
348
+ settings . set_boolean ( "show-all-notes" , false ) ;
352
349
} ) ;
353
350
354
351
this . window . add_controller ( this . new_controller ( ) ) ;
355
352
}
356
353
354
+ settings . set_boolean ( "show-all-notes" , true ) ;
355
+
357
356
this . window . present ( ) ;
358
357
}
359
358
0 commit comments