Skip to content

Commit 08ba0bc

Browse files
Frontend: update cpu widget to show per-core usage, clock, and temperature
1 parent 59d2cd4 commit 08ba0bc

File tree

1 file changed

+134
-7
lines changed

1 file changed

+134
-7
lines changed

core/frontend/src/widgets/Cpu.vue

Lines changed: 134 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
<template>
2-
<v-card class="d-flex align-center justify-center" height="40">
3-
<v-card-title>
4-
CPU: {{ cpu_usage }} %
5-
</v-card-title>
2+
<v-card class="d-flex align-center justify-center cpu-card" height="40">
3+
<div class="cpu-bars-container">
4+
<div
5+
v-for="(usage, index) in cpus_usage"
6+
:key="`cpu-${index}`"
7+
class="cpu-bar-container"
8+
:title="`CPU ${index}: ${usage.toFixed(1)}%`"
9+
>
10+
<div
11+
class="cpu-bar"
12+
:style="{
13+
height: `${Math.max(usage * 0.32, 1)}px`,
14+
backgroundColor: getBarColor(usage),
15+
}"
16+
/>
17+
</div>
18+
</div>
19+
20+
<div class="cpu-info-container">
21+
<div class="cpu-info-row clock-row">
22+
<v-icon small class="cpu-icon">
23+
mdi-speedometer
24+
</v-icon>
25+
<div v-if="clockDisplay.single">
26+
{{ clockDisplay.single }}GHz
27+
</div>
28+
<div v-else>
29+
{{ clockDisplay.max }}-{{ clockDisplay.min }}GHz
30+
</div>
31+
</div>
32+
33+
<div class="cpu-info-row temp-row">
34+
<v-icon small class="cpu-icon">
35+
mdi-thermometer
36+
</v-icon>
37+
<div>{{ cpu_temperature }}°C</div>
38+
</div>
39+
</div>
640
</v-card>
741
</template>
842

@@ -19,12 +53,45 @@ export default Vue.extend({
1953
}
2054
},
2155
computed: {
22-
cpu_usage(): string {
56+
cpus_usage(): number[] {
57+
const cpus = system_information.system?.cpu
58+
if (!cpus) {
59+
return []
60+
}
61+
return cpus.map((cpu) => cpu.usage)
62+
},
63+
cpu_clock(): number[] {
2364
const cpus = system_information.system?.cpu
2465
if (!cpus) {
25-
return '-'
66+
return []
67+
}
68+
return cpus.map((cpu) => cpu.frequency)
69+
},
70+
cpu_temperature(): string {
71+
const temperature_sensors = system_information.system?.temperature
72+
const main_sensor = temperature_sensors?.find(
73+
(sensor) => sensor.name.toLowerCase().includes('cpu') || sensor.name.toLowerCase().includes('soc'),
74+
)
75+
return main_sensor ? main_sensor.temperature.toFixed(1) : 'Loading..'
76+
},
77+
clockDisplay(): { single: string | null; max?: string | null; min?: string | null } {
78+
if (this.cpu_clock.length === 0) {
79+
return { single: null, max: null, min: null }
80+
}
81+
82+
const clocksInGhz = this.cpu_clock.map((clock: number) => clock / 1000)
83+
const allEqual = clocksInGhz.every((clock: number) => clock === clocksInGhz[0])
84+
85+
if (allEqual) {
86+
return { single: clocksInGhz[0].toFixed(1) }
87+
}
88+
const max = Math.max(...clocksInGhz)
89+
const min = Math.min(...clocksInGhz)
90+
return {
91+
max: max.toFixed(1),
92+
min: min.toFixed(1),
93+
single: null,
2694
}
27-
return (cpus.map((cpu) => cpu.usage).reduce((a, b) => a + b) / cpus.length).toFixed()
2895
},
2996
},
3097
mounted() {
@@ -33,5 +100,65 @@ export default Vue.extend({
33100
beforeDestroy() {
34101
clearInterval(this.timer)
35102
},
103+
methods: {
104+
getBarColor(usage: number): string {
105+
if (usage < 40) return '#4caf50' // Green
106+
if (usage < 75) return '#ff9800' // Orange
107+
return '#f44336' // Red
108+
},
109+
},
36110
})
37111
</script>
112+
113+
<style scoped>
114+
.cpu-card {
115+
border-radius: 4px;
116+
padding-left: 4px;
117+
padding-right: 4px;
118+
}
119+
120+
.cpu-bars-container {
121+
display: flex;
122+
align-items: flex-end;
123+
gap: 2px;
124+
margin-right: 12px;
125+
}
126+
127+
.cpu-bar-container {
128+
width: 8px;
129+
height: 32px;
130+
border: 1px solid var(--v-outline-darken3);
131+
border-radius: 3px;
132+
display: flex;
133+
align-items: flex-end;
134+
background-color: var(--v-sheet_bg-darken1);
135+
}
136+
137+
.cpu-bar {
138+
width: 100%;
139+
border-radius: 1px;
140+
transition: height 0.3s ease, background-color 0.3s ease;
141+
}
142+
143+
.cpu-info-container {
144+
display: flex;
145+
flex-direction: column;
146+
font-size: 0.8rem;
147+
line-height: 1.1;
148+
min-width: 70px;
149+
}
150+
151+
.cpu-icon {
152+
margin-right: 2px;
153+
font-size: 0.9rem !important;
154+
}
155+
156+
.cpu-info-row {
157+
display: flex;
158+
align-items: center;
159+
}
160+
161+
.clock-row .cpu-icon {
162+
margin-bottom: 2px;
163+
}
164+
</style>

0 commit comments

Comments
 (0)