From 54630355929b6236ae617437518d9413c2e165f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 23 Feb 2024 15:24:52 -0800 Subject: [PATCH 1/2] LidCloseActionComboBox: acquire permission async --- src/MainView.vala | 18 ------------------ src/Widgets/LidCloseActionComboBox.vala | 14 +++++++++++--- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/MainView.vala b/src/MainView.vala index b4ae237e..45f96a47 100644 --- a/src/MainView.vala +++ b/src/MainView.vala @@ -44,8 +44,6 @@ public class Power.MainView : Switchboard.SettingsPage { LOGOUT } - private static Polkit.Permission? permission = null; - public MainView () { Object ( title: _("Power"), @@ -329,22 +327,6 @@ public class Power.MainView : Switchboard.SettingsPage { }); } - public static async Polkit.Permission? get_permission () { - if (permission != null) { - return permission; - } - - try { - return yield new Polkit.Permission ( - "io.elementary.settings.power.administration", - new Polkit.UnixProcess (Posix.getpid ()) - ); - } catch (Error e) { - critical (e.message); - return null; - } - } - private static bool backlight_detect () { var interface_path = File.new_for_path ("/sys/class/backlight/"); diff --git a/src/Widgets/LidCloseActionComboBox.vala b/src/Widgets/LidCloseActionComboBox.vala index 2bc0ec7e..deca5d4f 100644 --- a/src/Widgets/LidCloseActionComboBox.vala +++ b/src/Widgets/LidCloseActionComboBox.vala @@ -23,6 +23,8 @@ class Power.LidCloseActionComboBox : Gtk.Widget { public bool dock { get; construct; } + private static Polkit.Permission? permission = null; + private Gtk.ComboBoxText combobox; private int previous_active; @@ -59,14 +61,20 @@ class Power.LidCloseActionComboBox : Gtk.Widget { // Returns true on success private async bool set_active_with_permission (int index_) { - var permission = yield MainView.get_permission (); if (permission == null) { - return false; + try { + permission = yield new Polkit.Permission ( + "io.elementary.settings.power.administration", + new Polkit.UnixProcess (Posix.getpid ()) + ); + } catch (Error e) { + critical (e.message); + } } if (!permission.allowed) { try { - permission.acquire (); + yield permission.acquire_async (); } catch (Error e) { warning (e.message); return false; From 9a74bf5501691af85f3e2c46d785fec5cd288415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 23 Feb 2024 15:27:14 -0800 Subject: [PATCH 2/2] Update LidCloseActionComboBox.vala --- src/Widgets/LidCloseActionComboBox.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Widgets/LidCloseActionComboBox.vala b/src/Widgets/LidCloseActionComboBox.vala index deca5d4f..71f5e73b 100644 --- a/src/Widgets/LidCloseActionComboBox.vala +++ b/src/Widgets/LidCloseActionComboBox.vala @@ -69,6 +69,7 @@ class Power.LidCloseActionComboBox : Gtk.Widget { ); } catch (Error e) { critical (e.message); + return false; } }