1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-06-08 04:09:15 -04:00

feat(ipc): add powerprofile status & shared profile helpers

- Follow-up to PR #2515
This commit is contained in:
purian23
2026-05-30 14:57:01 -04:00
parent 461da22b08
commit b7daf3f64a
7 changed files with 171 additions and 64 deletions
+24 -37
View File
@@ -1894,7 +1894,7 @@ Item {
IpcHandler {
function open(): string {
if (typeof PowerProfiles === "undefined")
if (!PowerProfileWatcher.available)
return "ERROR: power-profiles-daemon not available";
PopoutService.openPowerProfileModal();
@@ -1907,7 +1907,7 @@ Item {
}
function toggle(): string {
if (typeof PowerProfiles === "undefined")
if (!PowerProfileWatcher.available)
return "ERROR: power-profiles-daemon not available";
PopoutService.togglePowerProfileModal();
@@ -1915,59 +1915,46 @@ Item {
}
function list(): string {
if (typeof PowerProfiles === "undefined")
if (!PowerProfileWatcher.available)
return "ERROR: power-profiles-daemon not available";
const profiles = ["power-saver", "balanced"];
if (PowerProfiles.hasPerformanceProfile)
profiles.push("performance");
return PowerProfileWatcher.availableProfiles.map(profile => PowerProfileWatcher.profileSlug(profile)).join("\n");
}
return profiles.join("\n");
function status(): string {
if (!PowerProfileWatcher.available)
return "ERROR: power-profiles-daemon not available";
return PowerProfileWatcher.profileSlug(PowerProfiles.profile);
}
function set(profile: string): string {
if (typeof PowerProfiles === "undefined")
if (!PowerProfileWatcher.available)
return "ERROR: power-profiles-daemon not available";
if (!profile)
return "ERROR: No profile specified";
const lower = profile.toLowerCase().trim();
if (lower === "power-saver" || lower === "powersaver" || lower === "saver" || lower === "0") {
PowerProfiles.profile = PowerProfile.PowerSaver;
return "POWERPROFILE_SET_SUCCESS";
} else if (lower === "balanced" || lower === "1") {
PowerProfiles.profile = PowerProfile.Balanced;
return "POWERPROFILE_SET_SUCCESS";
} else if (lower === "performance" || lower === "2") {
if (PowerProfiles.hasPerformanceProfile) {
PowerProfiles.profile = PowerProfile.Performance;
return "POWERPROFILE_SET_SUCCESS";
} else {
return "ERROR: Performance profile not supported by hardware";
}
} else {
const parsed = PowerProfileWatcher.parseProfileSlug(profile);
if (parsed === -1)
return "ERROR: Unknown power profile. Supported options: power-saver, balanced, performance";
}
if (parsed === PowerProfile.Performance && !PowerProfiles.hasPerformanceProfile)
return "ERROR: Performance profile not supported by hardware";
if (!PowerProfileWatcher.applyProfile(parsed))
return "ERROR: Failed to set power profile";
return "POWERPROFILE_SET_SUCCESS";
}
function cycle(): string {
if (typeof PowerProfiles === "undefined")
if (!PowerProfileWatcher.available)
return "ERROR: power-profiles-daemon not available";
const current = PowerProfiles.profile;
const profiles = [PowerProfile.PowerSaver, PowerProfile.Balanced];
if (PowerProfiles.hasPerformanceProfile)
profiles.push(PowerProfile.Performance);
if (!PowerProfileWatcher.cycleProfile())
return "ERROR: Failed to set power profile";
const index = profiles.indexOf(current);
if (index === -1) {
PowerProfiles.profile = PowerProfile.Balanced;
return "POWERPROFILE_CYCLE_SUCCESS";
}
const nextIndex = (index + 1) % profiles.length;
PowerProfiles.profile = profiles[nextIndex];
return "POWERPROFILE_CYCLE_SUCCESS";
}