Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Feb 22, 2024
2 parents f320c69 + 578f409 commit 1185433
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
6 changes: 2 additions & 4 deletions src/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,16 @@ public class Power.MainView : Switchboard.SettingsPage {
});
}

public static Polkit.Permission? get_permission () {
public static async Polkit.Permission? get_permission () {
if (permission != null) {
return permission;
}

try {
permission = new Polkit.Permission.sync (
return yield new Polkit.Permission (
"io.elementary.settings.power.administration",
new Polkit.UnixProcess (Posix.getpid ())
);

return permission;
} catch (Error e) {
critical (e.message);
return null;
Expand Down
38 changes: 19 additions & 19 deletions src/Widgets/LidCloseActionComboBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ class Power.LidCloseActionComboBox : Gtk.Widget {
dropdown.notify["selected"].connect (on_changed);
}

private bool set_active_with_permission (uint index_) {
// Returns true on success

var permission = MainView.get_permission ();
// Returns true on success
private async bool set_active_with_permission (uint index_) {
var permission = yield MainView.get_permission ();
if (permission == null) {
return false;
}
Expand All @@ -78,26 +77,13 @@ class Power.LidCloseActionComboBox : Gtk.Widget {

previous_active = dropdown.selected;
dropdown.selected = index_;
return true;
}

private void on_changed () {
var helper = LogindHelper.get_logind_helper ();
if (helper == null) {
return;
}

if (dropdown.selected != previous_active) {
var success = set_active_with_permission (dropdown.selected);
if (!success) {
dropdown.selected = previous_active;
return;
}
} else {
return;
return false;
}

LogindHelper.Action action = get_action ();
var action = get_action ();
try {
if (dock) {
helper.set_key (HANDLE_LID_SWITCH_DOCKED_KEY, action.to_string ());
Expand All @@ -107,6 +93,20 @@ class Power.LidCloseActionComboBox : Gtk.Widget {
} catch (Error e) {
warning (e.message);
}

return true;
}

private void on_changed () {
if (dropdown.selected == previous_active) {
return;
}

set_active_with_permission.begin (dropdown.selected, (obj, res) => {
if (!set_active_with_permission.end (res)) {
dropdown.selected = previous_active;
}
});
}

private void update_current_action () {
Expand Down

0 comments on commit 1185433

Please sign in to comment.