diff --git a/src/MainView.vala b/src/MainView.vala index 3dc1bbcb..eca975a9 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"), @@ -350,22 +348,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 a67d724a..dd8073ff 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; @@ -56,14 +58,21 @@ 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); + return false; + } } if (!permission.allowed) { try { - permission.acquire (); + yield permission.acquire_async (); } catch (Error e) { warning (e.message); return false;