Implemented battery, power profile and brightness all in one menu
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
const battery = await Service.import("battery");
|
||||
import { closeAllMenus } from "../bar.js";
|
||||
|
||||
const BatteryLabel = () => {
|
||||
const isVis = Variable(battery.available);
|
||||
|
||||
const value = battery.bind("percent").as((p) => (p > 0 ? p / 100 : 0));
|
||||
const icon = battery
|
||||
.bind("percent")
|
||||
.as((p) => `battery-level-${Math.floor(p / 10) * 10}-symbolic`);
|
||||
@@ -12,23 +12,58 @@ const BatteryLabel = () => {
|
||||
isVis.value = available;
|
||||
});
|
||||
|
||||
const formatTime = (seconds) => {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
return { hours, minutes };
|
||||
};
|
||||
|
||||
const generateTooltip = (timeSeconds, isCharging, isCharged) => {
|
||||
if (isCharged) {
|
||||
return "Fully Charged!!!";
|
||||
}
|
||||
|
||||
const { hours, minutes } = formatTime(timeSeconds);
|
||||
if (isCharging) {
|
||||
return `${hours} hours ${minutes} minutes until full`;
|
||||
} else {
|
||||
return `${hours} hours ${minutes} minutes left`;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
component: Widget.Box({
|
||||
class_name: "battery",
|
||||
visible: battery.bind("available"),
|
||||
tooltip_text: battery.bind("time_remaining").as((t) => t.toString()),
|
||||
children: [
|
||||
Widget.Icon({ icon }),
|
||||
Widget.Label({
|
||||
label: battery.bind("percent").as((p) => (`${p}%`)),
|
||||
})
|
||||
// Widget.LevelBar({
|
||||
// widthRequest: 20,
|
||||
// vpack: "center",
|
||||
// value,
|
||||
// }),
|
||||
label: battery.bind("percent").as((p) => ` ${p}%`),
|
||||
}),
|
||||
],
|
||||
setup: (self) => {
|
||||
self.hook(battery, () => {
|
||||
self.tooltip_text = generateTooltip(
|
||||
battery.time_remaining,
|
||||
battery.charging,
|
||||
battery.charged,
|
||||
);
|
||||
});
|
||||
},
|
||||
}),
|
||||
isVis,
|
||||
props: {
|
||||
on_primary_click: (_, event) => {
|
||||
const clickPos = event.get_root_coords();
|
||||
const coords = [clickPos[1], clickPos[2]];
|
||||
|
||||
globalMousePos.value = coords;
|
||||
|
||||
closeAllMenus();
|
||||
App.toggleWindow("energymenu");
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ const Media = () => {
|
||||
|
||||
const songIcon = Variable("");
|
||||
|
||||
const label = Utils.watch(" No media playing ", mpris, "changed", () => {
|
||||
const label = Utils.watch(" Media ", mpris, "changed", () => {
|
||||
if (activePlayer.value) {
|
||||
const { track_title, identity } = activePlayer.value;
|
||||
songIcon.value = getIconForPlayer(identity);
|
||||
@@ -59,7 +59,7 @@ const Media = () => {
|
||||
: ` ${track_title}`;
|
||||
} else {
|
||||
songIcon.value = "";
|
||||
return " No media playing ";
|
||||
return " Media ";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ const Network = () => {
|
||||
Widget.Label({
|
||||
label: network.wifi
|
||||
.bind("ssid")
|
||||
.as((ssid) => (ssid ? ` ${ssid}` : " Unknown")),
|
||||
.as((ssid) => (ssid ? ` ${ssid}` : " --").substring(0, 7)),
|
||||
}),
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user