Skip to content

Commit 4c21d1b

Browse files
authored
Merge pull request #88 from K97i/v2-powerprofiles
Add Power Profiles modal
2 parents 32d10ad + fc8b7af commit 4c21d1b

File tree

2 files changed

+75
-29
lines changed

2 files changed

+75
-29
lines changed

new/apps/web/src/lib/components/Widgets.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</div>
4141

4242
<div class="widgets">
43+
<PowerProfiles powerProfiles={report.System.PowerProfiles} batteries={report.Hardware.Batteries}/>
4344
<Temps />
4445
<AudioDevices audioDevices={report.Hardware.AudioDevices}/>
4546
</div>
Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
1-
<!-- NOT YET IMPLEMENTED IN NEW WIDGET SYSTEM -->
21
<script lang="ts">
32
import Widget from '../../common/ModalWidget.svelte';
3+
4+
interface PowerProfileInfo {
5+
Caption: string;
6+
Description: string;
7+
ElementName: string;
8+
InstanceID: string;
9+
IsActive: boolean;
10+
}
11+
12+
interface BatteryInfo {
13+
Name: string;
14+
Manufacturer: string;
15+
Chemistry: string;
16+
Design_Capacity: string;
17+
Full_Charge_Capacity: string;
18+
Remaining_Life_Percentage: string;
19+
}
20+
21+
interface Props {
22+
powerProfiles: Array<PowerProfileInfo>;
23+
batteries: Array<BatteryInfo>;
24+
}
25+
26+
let {
27+
powerProfiles,
28+
batteries
29+
}: Props = $props();
30+
31+
let activeProfile: PowerProfileInfo;
32+
33+
powerProfiles.forEach((profile: PowerProfileInfo)=>{
34+
if (profile.IsActive){
35+
activeProfile = profile
36+
return
37+
}
38+
})
439
</script>
540

641
<!-- Power Profiles -->
7-
<Widget title="Power Profiles" modalId="power-modal">
8-
<div slot="values">
42+
<Widget title="Power Profiles">
43+
{#snippet widgetContents()}
944
<div class="widget-value">
10-
<!-- <?php
11-
if ($json_data['System']['PowerProfiles']) {
12-
$profile_count = safe_count($json_data['System']['PowerProfiles']);
13-
$profile_color = '';
14-
$current_profile = '';
15-
if ($profile_count != 0) {
16-
for ($profile = 0; $profile < $profile_count; $profile++) {
17-
if ($json_data['System']['PowerProfiles'][$profile]['IsActive']) {
18-
$current_profile = $json_data['System']['PowerProfiles'][$profile]['ElementName'];
19-
}
20-
}
21-
if (str_contains(strtolower($current_profile), 'balanced')) {
22-
$profile_color = '--yellow';
23-
} elseif (str_contains(strtolower($current_profile), 'high')) {
24-
$profile_color = '--red';
25-
} elseif (str_contains(strtolower($current_profile), 'saver')) {
26-
$profile_color = '--green';
27-
}
28-
29-
echo '<span style="color: var(' . $profile_color . ');">' . $current_profile . '</span>';
30-
}
31-
}
32-
?> -->
45+
<span>{activeProfile.ElementName}</span>
3346
<div style="font-size: 10pt;">Current Profile</div>
3447
</div>
35-
</div>
48+
{/snippet}
3649

37-
<div class="modal-body">
50+
{#snippet modalContents()}
3851
<h4>Power Profiles</h4>
3952
<table id="power-table" class="table">
4053
<thead>
@@ -45,6 +58,16 @@
4558
<th>Status</th>
4659
</tr>
4760
</thead>
61+
<tbody>
62+
{#each powerProfiles as profile}
63+
<tr>
64+
<td>{profile.Description}</td>
65+
<td>{profile.ElementName}</td>
66+
<td>{profile.InstanceID}</td>
67+
<td>{profile.IsActive}</td>
68+
</tr>
69+
{/each}
70+
</tbody>
4871
</table>
4972
<br />
5073
<h4>Battery</h4>
@@ -58,6 +81,28 @@
5881
<th>Current Full Charge Capacity</th>
5982
</tr>
6083
</thead>
84+
<tbody>
85+
{#each batteries as battery}
86+
<tr>
87+
<td>{battery.Name}</td>
88+
<td>{battery.Manufacturer}</td>
89+
<td>{battery.Chemistry}</td>
90+
<td>{battery.Design_Capacity}</td>
91+
<td>{battery.Full_Charge_Capacity}</td>
92+
</tr>
93+
{/each}
94+
</tbody>
6195
</table>
62-
</div>
96+
{/snippet}
6397
</Widget>
98+
99+
<style>
100+
span {
101+
color: var(--color-secondary-50);
102+
}
103+
104+
div {
105+
color: var(--color-surface-300);
106+
font-size: 13pt;
107+
}
108+
</style>

0 commit comments

Comments
 (0)