BatteryService: create placeholder policy to chagne charging treshold without password

This commit is contained in:
Damian D'Souza
2025-10-09 21:18:19 +02:00
parent 2f515ca3c5
commit c2ff74aa20
2 changed files with 31 additions and 0 deletions
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<action id="com.local.battery-manager.ACTUAL_USER_PLACEHOLDER">
<description>Manage battery settings for ACTUAL_USER_PLACEHOLDER</description>
<message>Authentication is required to manage battery settings</message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/battery-manager-ACTUAL_USER_PLACEHOLDER</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>
+14
View File
@@ -0,0 +1,14 @@
polkit.addRule(function(action, subject) {
if (action.id == "com.local.battery-manager.ACTUAL_USER_PLACEHOLDER" &&
subject.user == "ACTUAL_USER_PLACEHOLDER") {
// Check if the parent process is quickshell or set-battery-threshold
var pid = subject.pid;
var ppid = polkit.spawn(["ps", "-o", "ppid=", "-p", pid.toString()]).trim();
var parentCmd = polkit.spawn(["ps", "-o", "comm=", "-p", ppid]).trim();
if (parentCmd.indexOf("quickshell") !== -1 || parentCmd.indexOf("set-battery-treshold") !== -1) {
return polkit.Result.YES;
}
}
});