Skip to content

Commit 6fff491

Browse files
committed
Proper autostart capabilities via libportal
1 parent f5c7fd8 commit 6fff491

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

data/com.github.elfenware.badger.gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,10 @@
8787
<summary>The saved height of the window.</summary>
8888
<description>The saved height of the window.</description>
8989
</key>
90+
<key name="first-run" type="b">
91+
<default>true</default>
92+
<summary>Whether this is the first time that Badger has opened</summary>
93+
<description>Used to determine whether or not to perform initial install steps</description>
94+
</key>
9095
</schema>
9196
</schemalist>

meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ executable(
4040
dependency ('glib-2.0'),
4141
dependency('granite-7'),
4242
dependency('gobject-2.0'),
43-
dependency('gtk4')
43+
dependency('gtk4'),
44+
dependency('libportal')
4445
],
4546
install : true
4647
)

src/Application.vala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class Badger.Application : Gtk.Application {
4040
protected override void activate () {
4141
stdout.printf ("\n✔️ Activated");
4242

43+
var settings = new GLib.Settings ("com.github.elfenware.badger.state");
4344
var gtk_settings = Gtk.Settings.get_default ();
4445
var granite_settings = Granite.Settings.get_default ();
4546
stdout.printf ("\n⚙️ State settings loaded");
@@ -54,6 +55,24 @@ public class Badger.Application : Gtk.Application {
5455
);
5556
});
5657

58+
// On first run, request autostart
59+
if (settings.get_boolean ("first-run")) {
60+
stdout.printf ("\n🎉️ First run");
61+
62+
var portal = new Xdp.Portal();
63+
GenericArray<weak string> cmd = new GenericArray<weak string> ();
64+
cmd.add ("com.github.elfenware.badger --headless");
65+
66+
portal.request_background(
67+
null,
68+
"Autostart Badger in headless mode to send reminders",
69+
cmd,
70+
Xdp.BackgroundFlags.AUTOSTART,
71+
null);
72+
73+
settings.set_boolean ("first-run", false);
74+
}
75+
5776
if (window == null) {
5877
var reminders = set_up_reminders ();
5978
var main = new MainGrid (reminders);

0 commit comments

Comments
 (0)