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

AppSettingsView: add notification permission link #221

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
6 changes: 6 additions & 0 deletions data/applications.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/io/elementary/settings/icons">
<file alias="permissions-background.svg" compressed="true">background.svg</file>
</gresource>
</gresources>
176 changes: 176 additions & 0 deletions data/background.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
gresource = gnome.compile_resources(
'applications-resources',
'applications.gresource.xml',
source_dir: meson.current_source_dir()
)


i18n.merge_file(
input: 'applications.metainfo.xml.in',
output: 'io.elementary.settings.applications.metainfo.xml',
Expand Down
11 changes: 10 additions & 1 deletion src/Permissions/Backend/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Permissions.Backend.App : GLib.Object {
public Flatpak.InstalledRef installed_ref { get; construct; }
public string id { get; private set; }
public string name { get; private set; }
public Icon icon { get; private set; }
public GenericArray<Backend.PermissionSettings> settings;

private const string GROUP = "Context";
Expand All @@ -35,7 +36,15 @@ public class Permissions.Backend.App : GLib.Object {

construct {
id = installed_ref.get_name ();
name = installed_ref.get_appdata_name () ?? id;

var appinfo = new GLib.DesktopAppInfo (id + ".desktop");
if (appinfo != null) {
name = appinfo.get_name ();
icon = appinfo.get_icon () ?? new ThemedIcon ("application-default-icon");
} else {
icon = new ThemedIcon ("application-default-icon");
name = id;
}

settings = new GenericArray<Backend.PermissionSettings> ();

Expand Down
58 changes: 58 additions & 0 deletions src/Permissions/Backend/PermissionStore.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* SPDX-FileCopyrightText: 2023 elementary, Inc. (https://elementary.io)
*/

[DBus (name = "org.freedesktop.impl.portal.PermissionStore", timeout = 120000)]
public interface PermissionStoreDBus : GLib.Object {
public signal void changed (string table, string id, bool deleted, GLib.Variant data, [DBus (signature = "a{sas}")] GLib.Variant permissions);
public abstract async void set_permission (string table, bool create, string id, string app, string[] permissions) throws DBusError, IOError;
public abstract async string[] get_permission (string table, string id, string app) throws DBusError, IOError;
}

public class Permissions.PermissionStore : GLib.Object {
public signal void changed ();

private const string DBUS_NAME = "org.freedesktop.impl.portal.PermissionStore";
private const string DBUS_PATH = "/org/freedesktop/impl/portal/PermissionStore";
private const uint RECONNECT_TIMEOUT = 5000U;

private static PermissionStore? instance;
public static unowned PermissionStore get_default () {
if (instance == null) {
instance = new PermissionStore ();
}

return instance;
}

public PermissionStoreDBus dbus { get; private set; default = null; }

construct {
Bus.watch_name (
BusType.SESSION, DBUS_NAME, AUTO_START,
() => try_connect (), name_vanished_callback
);
}

private PermissionStore () { }

private void try_connect () {
Bus.get_proxy.begin<PermissionStoreDBus> (SESSION, DBUS_NAME, DBUS_PATH, 0, null, (obj, res) => {
try {
dbus = Bus.get_proxy.end (res);
dbus.changed.connect (() => changed ());
} catch (Error e) {
critical (e.message);
Timeout.add (RECONNECT_TIMEOUT, () => {
try_connect ();
return GLib.Source.REMOVE;
});
}
});
}

private void name_vanished_callback (DBusConnection connection, string name) {
dbus = null;
}
}
12 changes: 5 additions & 7 deletions src/Permissions/PermissionsPlug.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public class Permissions.Plug : Gtk.Box {
child = scrolled_window
};

var sidebar = new Gtk.Box (VERTICAL, 12);
var sidebar = new Gtk.Box (VERTICAL, 12) {
margin_bottom = 12,
margin_start = 12
};
sidebar.append (search_entry);
sidebar.append (frame);

Expand All @@ -94,12 +97,7 @@ public class Permissions.Plug : Gtk.Box {
show_row (row);
}

var grid = new Gtk.Grid () {
margin_end = 12,
margin_bottom = 12,
margin_start = 12,
column_spacing = 12
};
var grid = new Gtk.Grid ();
grid.attach (sidebar, 0, 0, 1, 1);
grid.attach (app_settings_view, 1, 0, 2, 1);

Expand Down