@@ -51,6 +51,8 @@ export class Application extends Adw.Application {
5151
5252 notes_list = Gio . ListStore . new ( Note . $gtype ) as Gio . ListStore < Note > ;
5353
54+ open_new_note = false ;
55+
5456 sort_notes ( ) {
5557 this . notes_list . sort ( ( note1 : Note , note2 : Note ) => {
5658 return note1 . modified . compare ( note2 . modified ) ;
@@ -89,6 +91,37 @@ export class Application extends Adw.Application {
8991 } catch ( error ) {
9092 console . error ( error as any ) ;
9193 }
94+
95+ this . add_main_option (
96+ "version" ,
97+ "v" . charCodeAt ( 0 ) ,
98+ GLib . OptionFlags . NONE ,
99+ GLib . OptionArg . NONE ,
100+ "Print version information and exit" ,
101+ null ,
102+ ) ;
103+
104+ this . add_main_option (
105+ "new-note" ,
106+ "n" . charCodeAt ( 0 ) ,
107+ GLib . OptionFlags . NONE ,
108+ GLib . OptionArg . NONE ,
109+ "Open a new note" ,
110+ null ,
111+ ) ;
112+
113+ this . connect ( "handle-local-options" , ( _app , options : GLib . VariantDict ) => {
114+ if ( options . contains ( "version" ) ) {
115+ print ( pkg . version ) ;
116+ /* quit the invoked process after printing the version number
117+ * leaving the running instance unaffected
118+ */
119+ return 0 ;
120+ } else if ( options . contains ( "new-note" ) ) {
121+ this . open_new_note = true ;
122+ }
123+ return - 1 ;
124+ } ) ;
92125 }
93126
94127 save ( ) {
@@ -112,24 +145,28 @@ export class Application extends Adw.Application {
112145 // we show the all_notes
113146 let has_one_open = false ;
114147
115- if ( settings . get_boolean ( "show-all-notes" ) ) this . all_notes ( ) ;
148+ if ( this . open_new_note ) {
149+ this . new_note ( ) ;
150+ } else {
151+ if ( settings . get_boolean ( "show-all-notes" ) ) this . all_notes ( ) ;
116152
117- this . foreach_note ( ( note ) => {
118- if ( note . open ) {
119- if ( has_one_open == false ) has_one_open = true ;
120- this . show_note ( note . uuid ) ;
121- }
122- } ) ;
153+ this . foreach_note ( ( note ) => {
154+ if ( note . open ) {
155+ if ( has_one_open == false ) has_one_open = true ;
156+ this . show_note ( note . uuid ) ;
157+ }
158+ } ) ;
123159
124- if ( ! has_one_open ) {
125- const last_open_note = this . notes_array ( )
126- . sort ( ( a , b ) => b . modified . compare ( a . modified ) ) [ 0 ] ;
160+ if ( ! has_one_open ) {
161+ const last_open_note = this . notes_array ( )
162+ . sort ( ( a , b ) => b . modified . compare ( a . modified ) ) [ 0 ] ;
127163
128- if ( has_one_open ) {
129- this . show_note ( last_open_note . uuid ) ;
130- } else {
131- settings . set_boolean ( "show-all-notes" , true ) ;
132- this . all_notes ( ) ;
164+ if ( has_one_open ) {
165+ this . show_note ( last_open_note . uuid ) ;
166+ } else {
167+ settings . set_boolean ( "show-all-notes" , true ) ;
168+ this . all_notes ( ) ;
169+ }
133170 }
134171 }
135172 }
0 commit comments