aboutsummaryrefslogtreecommitdiff
path: root/src/agent.vala
diff options
context:
space:
mode:
authorMuhammad <thevancedgamer@mentallysanemainliners.org>2026-03-10 01:37:25 +0500
committerMuhammad <thevancedgamer@mentallysanemainliners.org>2026-03-10 01:37:25 +0500
commit36d77944f2e7707eefd60ea208c6f4bc55a3f961 (patch)
treed6074f6903687b3b278d90abab2d62dcd057d5a8 /src/agent.vala
parent6c7c62d7c6d153293c8aea8dd1c71faabdef3b3e (diff)
downloadayatana-indicator-bluetooth-36d77944f2e7707eefd60ea208c6f4bc55a3f961.tar.gz
ayatana-indicator-bluetooth-36d77944f2e7707eefd60ea208c6f4bc55a3f961.tar.bz2
ayatana-indicator-bluetooth-36d77944f2e7707eefd60ea208c6f4bc55a3f961.zip
agent: add proper support for AuthorizeService
Signed-off-by: Muhammad <thevancedgamer@mentallysanemainliners.org>
Diffstat (limited to 'src/agent.vala')
-rw-r--r--src/agent.vala63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/agent.vala b/src/agent.vala
index 9e568a4..16ce6a2 100644
--- a/src/agent.vala
+++ b/src/agent.vala
@@ -1,9 +1,12 @@
[DBus (name = "org.bluez.Agent1")]
public class Agent: Object
{
+ // These actions and menus are exposed on their relevant paths by service.vala
public GLib.Menu menu;
public GLib.SimpleActionGroup actions;
private GLib.SimpleAction pin_action;
+
+ // These paths are set by service.vala
public string menu_path;
public string actions_path;
@@ -102,8 +105,66 @@ public class Agent: Object
return accepted;
}
- public void AuthorizeService (GLib.ObjectPath object, string uuid) throws GLib.DBusError, GLib.IOError
+ public void AuthorizeService (GLib.ObjectPath object, string uuid) throws RejectedError, GLib.DBusError, GLib.IOError
{
+ bool authorized = false;
+ bool trusted = false;
+
+ string header = "Allow %s to connect?".printf (bluetooth.get_device_name (object));
+ string body = "Allow the Bluetooth device to access a Bluetooth service?";
+
+ notification = new Notify.Notification (header, body, "bluetooth-active");
+ notification.closed.connect (() => {
+ authorized = false;
+ notification = null;
+
+ if (loop.is_running ()) {
+ loop.quit ();
+ }
+ });
+
+ if (AyatanaCommon.utils_is_lomiri ()) {
+ notification.set_hint ("x-lomiri-snap-decisions", true);
+ }
+
+ notification.add_action ("trust_and_authorize", "Trust and authorize", (notif, action) => {
+ loop.quit ();
+ notification = null;
+
+ trusted = true;
+ authorized = true;
+ });
+
+ notification.add_action ("authorize", "Authorize", (notif, action) => {
+ loop.quit ();
+ notification = null;
+
+ authorized = true;
+ });
+
+ notification.add_action ("reject", "Do not authorize", (notif, action) => {
+ loop.quit ();
+ notification = null;
+ });
+
+ try {
+ notification.show ();
+ }
+ catch (Error e) {
+ warning ("Panic: Failed showing notification: %s", e.message);
+ }
+
+ loop.run ();
+
+ // Once the loop quits, we can see if we want to set the 'Trusted' property in BlueZ
+ if (trusted) {
+ Device device = bluetooth.get_device (object);
+ bluetooth.set_device_trusted (device.id, trusted);
+ }
+
+ if (!authorized) {
+ throw new RejectedError.ERROR ("Rejected by user");
+ }
}
public void RequestConfirmation (GLib.ObjectPath object, uint32 passkey) throws RejectedError, GLib.DBusError, GLib.IOError