2020
2121public class Badger.Application : Gtk .Application {
2222 public bool headless = false ;
23+ public bool ask_autostart = false ;
2324
2425 private Badger . MainWindow window;
2526
@@ -40,6 +41,7 @@ public class Badger.Application : Gtk.Application {
4041 protected override void activate () {
4142 stdout. printf (" \n ✔️ Activated" );
4243
44+ var settings = new GLib .Settings (" com.github.elfenware.badger.state" );
4345 var gtk_settings = Gtk . Settings . get_default ();
4446 var granite_settings = Granite . Settings . get_default ();
4547 stdout. printf (" \n ⚙️ State settings loaded" );
@@ -54,6 +56,20 @@ public class Badger.Application : Gtk.Application {
5456 );
5557 });
5658
59+ // On first run, request autostart
60+ if (settings. get_boolean (" first-run" ) || ask_autostart) {
61+
62+ // Show first run message only if really first run
63+ if (settings. get_boolean (" first-run" )) {
64+ stdout. printf (" \n 🎉️ First run" );
65+ settings. set_boolean (" first-run" , false );
66+ } else {
67+ ask_autostart = false ;
68+ }
69+ request_autostart ();
70+
71+ }
72+
5773 if (window == null ) {
5874 var reminders = set_up_reminders ();
5975 var main = new MainGrid (reminders);
@@ -77,16 +93,20 @@ public class Badger.Application : Gtk.Application {
7793 window. show ();
7894 window. present ();
7995 }
96+ headless = false ;
8097 }
8198
8299 public override int command_line (ApplicationCommandLine command_line ) {
83100 stdout. printf (" \n 💲️ Command line mode started" );
84101
85- bool headless_mode = false ;
86- OptionEntry [] options = new OptionEntry [1 ];
102+ OptionEntry [] options = new OptionEntry [2 ];
87103 options[0 ] = {
88104 " headless" , 0 , 0 , OptionArg . NONE ,
89- ref headless_mode, " Run without window" , null
105+ ref headless, " Run without window" , null
106+ };
107+ options[1 ] = {
108+ " request-autostart" , 0 , 0 , OptionArg . NONE ,
109+ ref ask_autostart, " Request autostart permission" , null
90110 };
91111
92112 // We have to make an extra copy of the array, since .parse assumes
@@ -108,23 +128,33 @@ public class Badger.Application : Gtk.Application {
108128 return 0 ;
109129 }
110130
111- headless = headless_mode;
112-
113131 hold ();
114132 activate ();
115133 return 0 ;
116134 }
117135
118136 public static int main (string [] args ) {
119137 var app = new Badger .Application ();
120-
121- if (args. length > 1 && args[1 ] == " --headless" ) {
122- app. headless = true ;
123- }
124-
125138 return app. run (args);
126139 }
127140
141+ private static void request_autostart () {
142+ Xdp . Portal portal = new Xdp .Portal ();
143+ GenericArray<weak string> cmd = new GenericArray<weak string> ();
144+ cmd. add (" com.github.elfenware.badger" );
145+ cmd. add (" --headless" );
146+
147+ // TODO: Implicit .begin is deprecated but i have no idea how to fix that
148+ portal. request_background (
149+ null ,
150+ " Autostart Badger in headless mode to send reminders" ,
151+ cmd,
152+ Xdp . BackgroundFlags . AUTOSTART ,
153+ null );
154+
155+ stdout. printf (" \n 🚀 Requested autostart for Badger" );
156+ }
157+
128158 private Reminder [] set_up_reminders () {
129159 Reminder [] reminders = new Reminder [8 ];
130160 reminders[0 ] = new Reminder (
0 commit comments