fix(ags-v3): nice-to-have — portabilité, perf, réactivité
- Prompt.tsx: GLib.get_user_name() au lieu de hardcode "tetardtek" - ghost-shell.desktop: $HOME au lieu de chemin absolu - SystemStats.tsx: lecture /proc/stat + /proc/meminfo (zero fork, économie batterie) - Battery.tsx: createDerivedBinding percentage+charging — réactif sur branchement
This commit is contained in:
@@ -1,29 +1,38 @@
|
||||
import AstalBattery from "gi://AstalBattery"
|
||||
import { createBinding } from "ags"
|
||||
import { createBinding, createDerivedBinding } from "ags"
|
||||
|
||||
export default function Battery() {
|
||||
const bat = AstalBattery.get_default()
|
||||
|
||||
const text = createBinding(bat, "percentage")((p: number) => {
|
||||
const pct = Math.round(p * 100)
|
||||
let icon = ""
|
||||
if (bat.charging) icon = ""
|
||||
else if (pct > 90) icon = ""
|
||||
else if (pct > 70) icon = ""
|
||||
else if (pct > 50) icon = ""
|
||||
else if (pct > 30) icon = ""
|
||||
else if (pct > 10) icon = ""
|
||||
else icon = ""
|
||||
return `${icon} ${pct}%`
|
||||
})
|
||||
const percentage = createBinding(bat, "percentage")
|
||||
const charging = createBinding(bat, "charging")
|
||||
|
||||
const cls = createBinding(bat, "percentage")((p: number) => {
|
||||
const pct = Math.round(p * 100)
|
||||
if (bat.charging) return "battery charging"
|
||||
if (pct <= 10) return "battery low"
|
||||
if (pct <= 20) return "battery warning"
|
||||
return "battery"
|
||||
})
|
||||
const text = createDerivedBinding(
|
||||
[percentage, charging],
|
||||
(p: number, isCharging: boolean) => {
|
||||
const pct = Math.round(p * 100)
|
||||
let icon = ""
|
||||
if (isCharging) icon = ""
|
||||
else if (pct > 90) icon = ""
|
||||
else if (pct > 70) icon = ""
|
||||
else if (pct > 50) icon = ""
|
||||
else if (pct > 30) icon = ""
|
||||
else if (pct > 10) icon = ""
|
||||
else icon = ""
|
||||
return `${icon} ${pct}%`
|
||||
},
|
||||
)
|
||||
|
||||
const cls = createDerivedBinding(
|
||||
[percentage, charging],
|
||||
(p: number, isCharging: boolean) => {
|
||||
const pct = Math.round(p * 100)
|
||||
if (isCharging) return "battery charging"
|
||||
if (pct <= 10) return "battery low"
|
||||
if (pct <= 20) return "battery warning"
|
||||
return "battery"
|
||||
},
|
||||
)
|
||||
|
||||
return <label class={cls} label={text} />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user