Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requesting to run at startup #159

Open
danirabbit opened this issue Dec 17, 2021 · 0 comments
Open

Requesting to run at startup #159

danirabbit opened this issue Dec 17, 2021 · 0 comments

Comments

@danirabbit
Copy link
Member

danirabbit commented Dec 17, 2021

Problem

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

Proposal

We should document using the background portal 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<string, Variant> (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<Background> (DBUS_DESKTOP_NAME, DBUS_DESKTOP_PATH);
             }

             return background;
         }

         public abstract ObjectPath request_background (string window_handle, HashTable<string, Variant> options) throws IOError, DBusError;
     }
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

1 participant