@@ -3,24 +3,31 @@ import AstalBattery from "gi://AstalBattery";
|
||||
|
||||
const battery = AstalBattery.get_default();
|
||||
|
||||
const formatTime = (seconds: number) => seconds > 0
|
||||
? `${String(Math.floor(seconds / 3600)).padStart(2, "0")}:${String(Math.floor((seconds % 3600) / 60)).padStart(2, "0")}`
|
||||
: "--:--";
|
||||
const formatTime = (seconds: number) =>
|
||||
seconds > 0
|
||||
? `${String(Math.floor(seconds / 3600)).padStart(2, "0")}:${String(Math.floor((seconds % 3600) / 60)).padStart(2, "0")}`
|
||||
: "--:--";
|
||||
|
||||
export default () => {
|
||||
const percentage = bind(battery, "percentage").as((p) => Math.round(p * 100) + "%");
|
||||
const percentage = bind(battery, "percentage").as(
|
||||
(p) => Math.round(p * 100) + "%",
|
||||
);
|
||||
const charging = bind(battery, "charging");
|
||||
const timeToFull = bind(battery, "timeToFull");
|
||||
const timeToEmpty = bind(battery, "timeToEmpty");
|
||||
|
||||
const time = Variable.derive([charging, timeToFull, timeToEmpty], (charging, full, empty) =>
|
||||
formatTime(charging ? full : empty)
|
||||
const time = Variable.derive(
|
||||
[charging, timeToFull, timeToEmpty],
|
||||
(charging, full, empty) => formatTime(charging ? full : empty),
|
||||
);
|
||||
|
||||
const label = Variable.derive([percentage, charging, time], (percentage, charging, time) => {
|
||||
const arrow = charging ? "▲" : "▼";
|
||||
return `${percentage} (${time}) ${arrow}`;
|
||||
});
|
||||
const label = Variable.derive(
|
||||
[percentage, charging, time],
|
||||
(percentage, charging, time) => {
|
||||
const arrow = charging ? "▲" : "▼";
|
||||
return `${percentage} (${time}) ${arrow}`;
|
||||
},
|
||||
);
|
||||
|
||||
return (
|
||||
<button className="battery">
|
||||
|
@@ -2,14 +2,20 @@ import { bind, Variable } from "astal";
|
||||
import { GLib } from "astal";
|
||||
|
||||
export default () => {
|
||||
const time = Variable(GLib.DateTime.new_now_local().format("%H:%M - %A, %d %B %Y")!).poll(
|
||||
const time = Variable(
|
||||
GLib.DateTime.new_now_local().format("%H:%M - %A, %d %B %Y")!,
|
||||
).poll(
|
||||
1000,
|
||||
() => GLib.DateTime.new_now_local().format("%H:%M - %A, %d %B %Y")!,
|
||||
);
|
||||
|
||||
return (
|
||||
<button className="date">
|
||||
<label className="label" onDestroy={() => time.drop()} label={bind(time)} />
|
||||
<label
|
||||
className="label"
|
||||
onDestroy={() => time.drop()}
|
||||
label={bind(time)}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@@ -21,9 +21,13 @@ export default function Hidden({
|
||||
onHover={() => show.set(true)}
|
||||
onHoverLost={() => show.set(false)}
|
||||
>
|
||||
<box orientation={orientation} >
|
||||
<revealer setup={self => timeout(2000, () => self.revealChild = false)} revealChild={bind(show)} transitionType={transitionType}>
|
||||
{Array.isArray(contents) ? (<>{contents}</>) : (contents)}
|
||||
<box orientation={orientation}>
|
||||
<revealer
|
||||
setup={(self) => timeout(2000, () => (self.revealChild = false))}
|
||||
revealChild={bind(show)}
|
||||
transitionType={transitionType}
|
||||
>
|
||||
{Array.isArray(contents) ? <>{contents}</> : contents}
|
||||
</revealer>
|
||||
<box clickThrough className="trigger-guard" />
|
||||
</box>
|
||||
|
Reference in New Issue
Block a user