Added menubutton for choosing powerprofile
This commit is contained in:
1 parent
d956e86a74
commit
baf2021aa9
1 file changed
+82
@@ -2,6 +2,7 @@ import { Gtk } from "ags/gtk4"
|
||||
import AstalNetwork from "gi://AstalNetwork?version=0.1"
|
||||
import AstalBluetooth from "gi://AstalBluetooth?version=0.1"
|
||||
import AstalWp from "gi://AstalWp?version=0.1"
|
||||
import AstalPowerProfiles from "gi://AstalPowerProfiles?version=0.1"
|
||||
import { createBinding, createComputed, createState, For } from "ags"
|
||||
import { interval } from "ags/time"
|
||||
import { exec, execAsync } from "ags/process"
|
||||
@@ -41,6 +42,23 @@ interval(2000, () => setVpns(fetchVpns()))
|
||||
|
||||
const vpnActive = vpns((list) => list.some((c) => c.active))
|
||||
|
||||
const POWER_PROFILE_ICONS: Record<string, string> = {
|
||||
"power-saver": "power-profile-power-saver-symbolic",
|
||||
balanced: "power-profile-balanced-symbolic",
|
||||
performance: "power-profile-performance-symbolic",
|
||||
}
|
||||
|
||||
const POWER_PROFILE_LABELS: Record<string, string> = {
|
||||
"power-saver": "Power Saver",
|
||||
balanced: "Balanced",
|
||||
performance: "Performance",
|
||||
}
|
||||
|
||||
const powerprofiles = AstalPowerProfiles.get_default()
|
||||
const activeProfile = createBinding(powerprofiles, "active-profile")
|
||||
const powerProfiles = powerprofiles.get_profiles().map((p) => p.profile)
|
||||
const hasPowerProfiles = powerProfiles.length > 0
|
||||
|
||||
function NetworkItem() {
|
||||
const network = AstalNetwork.Network.get_default()
|
||||
const primary = createBinding(network, "primary")
|
||||
@@ -190,6 +208,58 @@ function VpnList() {
|
||||
)
|
||||
}
|
||||
|
||||
function PowerProfileItem() {
|
||||
return (
|
||||
<menubutton cssClasses={["qs-item"]} hexpand>
|
||||
<box spacing={12} valign={Gtk.Align.CENTER}>
|
||||
<image
|
||||
iconName={activeProfile(
|
||||
(p) => POWER_PROFILE_ICONS[p] ?? "power-profile-balanced-symbolic",
|
||||
)}
|
||||
cssClasses={["qs-icon"]}
|
||||
/>
|
||||
<label
|
||||
label={activeProfile((p) => POWER_PROFILE_LABELS[p] ?? p)}
|
||||
halign={Gtk.Align.START}
|
||||
hexpand
|
||||
/>
|
||||
<image iconName="pan-down-symbolic" />
|
||||
</box>
|
||||
<popover>
|
||||
<box orientation={Gtk.Orientation.VERTICAL} spacing={4}>
|
||||
{powerProfiles.map((name) => (
|
||||
<button
|
||||
cssClasses={["qs-item"]}
|
||||
onClicked={(btn) => {
|
||||
powerprofiles.set_active_profile(name)
|
||||
const popover = btn.get_ancestor(
|
||||
Gtk.Popover.$gtype,
|
||||
) as Gtk.Popover | null
|
||||
popover?.popdown()
|
||||
}}
|
||||
>
|
||||
<box spacing={12} valign={Gtk.Align.CENTER}>
|
||||
<image
|
||||
iconName={
|
||||
POWER_PROFILE_ICONS[name] ??
|
||||
"power-profile-balanced-symbolic"
|
||||
}
|
||||
cssClasses={["qs-icon"]}
|
||||
/>
|
||||
<label
|
||||
label={POWER_PROFILE_LABELS[name] ?? name}
|
||||
halign={Gtk.Align.START}
|
||||
hexpand
|
||||
/>
|
||||
</box>
|
||||
</button>
|
||||
))}
|
||||
</box>
|
||||
</popover>
|
||||
</menubutton>
|
||||
)
|
||||
}
|
||||
|
||||
export default function QuickSettings() {
|
||||
return (
|
||||
<menubutton
|
||||
@@ -213,6 +283,18 @@ export default function QuickSettings() {
|
||||
<BluetoothItem />
|
||||
</box>
|
||||
<VpnList />
|
||||
<box
|
||||
orientation={Gtk.Orientation.VERTICAL}
|
||||
spacing={8}
|
||||
visible={hasPowerProfiles}
|
||||
>
|
||||
<label
|
||||
label="Power Profile"
|
||||
cssClasses={["qs-title"]}
|
||||
halign={Gtk.Align.START}
|
||||
/>
|
||||
<PowerProfileItem />
|
||||
</box>
|
||||
<box orientation={Gtk.Orientation.VERTICAL} spacing={8}>
|
||||
<button
|
||||
cssClasses={["qs-title"]}
|
||||
|
||||
Reference in new issue
Block a user