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:
@@ -11,8 +11,68 @@ Singleton {
|
||||
property int currentProfile: -1
|
||||
property int previousProfile: -1
|
||||
|
||||
readonly property bool available: typeof PowerProfiles !== "undefined"
|
||||
|
||||
readonly property var availableProfiles: {
|
||||
if (!available)
|
||||
return [PowerProfile.PowerSaver, PowerProfile.Balanced, PowerProfile.Performance];
|
||||
|
||||
return [PowerProfile.PowerSaver, PowerProfile.Balanced].concat(PowerProfiles.hasPerformanceProfile ? [PowerProfile.Performance] : []);
|
||||
}
|
||||
|
||||
signal profileChanged(int profile)
|
||||
|
||||
function profileSlug(profile: int): string {
|
||||
switch (profile) {
|
||||
case PowerProfile.PowerSaver:
|
||||
return "power-saver";
|
||||
case PowerProfile.Balanced:
|
||||
return "balanced";
|
||||
case PowerProfile.Performance:
|
||||
return "performance";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
function parseProfileSlug(slug: string): int {
|
||||
if (!slug)
|
||||
return -1;
|
||||
|
||||
const lower = slug.toLowerCase().trim();
|
||||
if (lower === "power-saver" || lower === "powersaver" || lower === "saver" || lower === "0")
|
||||
return PowerProfile.PowerSaver;
|
||||
if (lower === "balanced" || lower === "1")
|
||||
return PowerProfile.Balanced;
|
||||
if (lower === "performance" || lower === "2")
|
||||
return PowerProfile.Performance;
|
||||
return -1;
|
||||
}
|
||||
|
||||
function applyProfile(profile: int): bool {
|
||||
if (!available)
|
||||
return false;
|
||||
|
||||
if (profile === PowerProfile.Performance && !PowerProfiles.hasPerformanceProfile)
|
||||
return false;
|
||||
|
||||
if (availableProfiles.indexOf(profile) === -1)
|
||||
return false;
|
||||
|
||||
PowerProfiles.profile = profile;
|
||||
return PowerProfiles.profile === profile;
|
||||
}
|
||||
|
||||
function cycleProfile(): bool {
|
||||
if (!available)
|
||||
return false;
|
||||
|
||||
const profiles = availableProfiles;
|
||||
const index = profiles.indexOf(PowerProfiles.profile);
|
||||
const nextProfile = index === -1 ? PowerProfile.Balanced : profiles[(index + 1) % profiles.length];
|
||||
return applyProfile(nextProfile);
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: typeof PowerProfiles !== "undefined" ? PowerProfiles : null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user