Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.github.elfenware.badger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ finish-args:
- '--socket=wayland'
# Allow Badger to send reminders
- '--socket=session-bus'
# Allow Badger to autostart and keep timers in the background
- '--talk-name=org.freedesktop.portal.Background'

cleanup:
- '/include'
Expand Down
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 @@ -77,5 +77,10 @@
path="/com/github/elfenware/badger/state/"
id="com.github.elfenware.badger.state"
gettext-domain="com.github.elfenware.badger">
<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
50 changes: 40 additions & 10 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,23 +128,33 @@ 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 ();

if (args.length > 1 && args[1] == "--headless") {
app.headless = true;
}

return app.run (args);
}

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");
cmd.add ("--headless");

// 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 () {
Reminder[] reminders = new Reminder[8];
reminders[0] = new Reminder (
Expand Down