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

LidCloseActionComboBox: acquire permission async #261

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public class Power.MainView : Switchboard.SettingsPage {
LOGOUT
}

private static Polkit.Permission? permission = null;

public MainView () {
Object (
title: _("Power"),
Expand Down Expand Up @@ -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/");

Expand Down
15 changes: 12 additions & 3 deletions src/Widgets/LidCloseActionComboBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Loading