elementary / elementary/docs

Requesting to run at startup

Open
#159 0 comments 0 reactions 0 assignees View on GitHub
Needs Design
Dominant language
No language data
Stars
88
Forks
30
Avg merge
3h 28m
Merged PRs (30d)
1

Description

### Problem

We don't currently document how apps should request to run at startup

### Proposal

We should document using the [background portal](https://docs.flatpak.org/en/latest/portal-api-reference.html#gdbus-org.freedesktop.portal.Background) to request running at startup either manually through dbus, using libportal, or possibly adding a granite method for this

### Prior Art (Optional)

This commit in Calendar: https://github.com/elementary/calendar/pull/681/files#diff-f4e5d48d751c670a8575715da1cb0a0976532427a8b6143c7fdede415a33ba6cR176

Particularly
```
private void ask_for_background () {
try {
var portal = Portal.Background.get ();
string[] cmd = { "io.elementary.calendar", "--background" };

window.export.begin ((obj, res) => {
var options = new HashTable (str_hash, str_equal);
options["handle_token"] = Portal.generate_token ();
options["reason"] = _("Calendar wants to initialize with the session");
options["commandline"] = cmd;
options["dbus-activatable"] = false;
options["autostart"] = true;

// TODO: handle response
try {
portal.request_background (window.export.end (res), options);
} catch (Error e) {
warning ("couldnt ask for background access: %s", e.message);
}
});
} catch (Error e) {
warning ("cloudnt connect to portal: %s", e.message);
}
}
```

and the portal class:

```
namespace Portal {
const string DBUS_DESKTOP_PATH = "/org/freedesktop/portal/desktop";
const string DBUS_DESKTOP_NAME = "org.freedesktop.portal.Desktop";
Background? background = null;

public static string generate_token () {
return "%s_%i".printf (
GLib.Application.get_default ().application_id.replace (".", "_"),
Random.int_range (0, int32.MAX)
);
}

[DBus (name = "org.freedesktop.portal.Background")]
interface Background : Object {
public abstract uint version { get; }

public static Background @get () throws IOError, DBusError {
if (background == null) {
var connection = GLib.Application.get_default ().get_dbus_connection ();
background = connection.get_proxy_sync (DBUS_DESKTOP_NAME, DBUS_DESKTOP_PATH);
}

return background;
}

public abstract ObjectPath request_background (string window_handle, HashTable options) throws IOError, DBusError;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.