Skip to content
Merged
5 changes: 5 additions & 0 deletions data/com.github.elfenware.badger.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@
<summary>The saved height of the window.</summary>
<description>The saved height of the window.</description>
</key>
<key name="first-run" type="b">
<default>true</default>
<summary>Whether this is the first time that Badger has opened</summary>
<description>Used to determine whether or not to perform initial install steps</description>
</key>
</schema>
</schemalist>
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ executable(
dependency ('glib-2.0'),
dependency('granite-7'),
dependency('gobject-2.0'),
dependency('gtk4')
dependency('gtk4'),
dependency('libportal')
],
install : true
)
Expand Down
47 changes: 38 additions & 9 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

public class Badger.Application : Gtk.Application {
public bool headless = false;
public bool ask_autostart = false;

private Badger.MainWindow window;

Expand All @@ -40,6 +41,7 @@ public class Badger.Application : Gtk.Application {
protected override void activate () {
stdout.printf ("\n✔️ Activated");

var settings = new GLib.Settings ("com.github.elfenware.badger.state");
var gtk_settings = Gtk.Settings.get_default ();
var granite_settings = Granite.Settings.get_default ();
stdout.printf ("\n⚙️ State settings loaded");
Expand All @@ -54,6 +56,20 @@ public class Badger.Application : Gtk.Application {
);
});

// On first run, request autostart
if (settings.get_boolean ("first-run") || ask_autostart) {

// Show first run message only if really first run
if (settings.get_boolean ("first-run")) {
stdout.printf ("\n🎉️ First run");
settings.set_boolean ("first-run", false);
} else {
ask_autostart = false;
}
request_autostart ();

}

if (window == null) {
var reminders = set_up_reminders ();
var main = new MainGrid (reminders);
Expand All @@ -77,16 +93,20 @@ public class Badger.Application : Gtk.Application {
window.show ();
window.present ();
}
headless = false;
}

public override int command_line (ApplicationCommandLine command_line) {
stdout.printf ("\n💲️ Command line mode started");

bool headless_mode = false;
OptionEntry[] options = new OptionEntry[1];
OptionEntry[] options = new OptionEntry[2];
options[0] = {
"headless", 0, 0, OptionArg.NONE,
ref headless_mode, "Run without window", null
ref headless, "Run without window", null
};
options[1] = {
"request-autostart", 0, 0, OptionArg.NONE,
ref ask_autostart, "Request autostart permission", null
};

// We have to make an extra copy of the array, since .parse assumes
Expand All @@ -108,21 +128,30 @@ public class Badger.Application : Gtk.Application {
return 0;
}

headless = headless_mode;

hold ();
activate ();
return 0;
}

public static int main (string[] args) {
var app = new Badger.Application ();
return app.run (args);
}

if (args.length > 1 && args[1] == "--headless") {
app.headless = true;
}
private static void request_autostart () {
Xdp.Portal portal = new Xdp.Portal ();
GenericArray<weak string> cmd = new GenericArray<weak string> ();
cmd.add ("com.github.elfenware.badger --headless");

return app.run (args);
// TODO: Implicit .begin is deprecated but i have no idea how to fix that
portal.request_background (
null,
"Autostart Badger in headless mode to send reminders",
cmd,
Xdp.BackgroundFlags.AUTOSTART,
null);

stdout.printf ("\n🚀 Requested autostart for Badger");
}

private Reminder[] set_up_reminders () {
Expand Down