From cf55e2613314e27243c60395e58665b9309280c8 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 22 Feb 2025 19:58:07 +1100 Subject: config: use config file Config file at ~/.config/caelestia/shell.json --- src/utils/system.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/utils') diff --git a/src/utils/system.ts b/src/utils/system.ts index 8180e48..7ae23dd 100644 --- a/src/utils/system.ts +++ b/src/utils/system.ts @@ -1,4 +1,4 @@ -import { bind, execAsync, GLib, Variable, type Gio } from "astal"; +import { bind, execAsync, GLib, Variable, type Binding, type Gio } from "astal"; import type AstalApps from "gi://AstalApps"; import { osIcons } from "./icons"; @@ -63,5 +63,15 @@ export const osIcon = (() => { })(); export const currentTime = Variable(GLib.DateTime.new_now_local()).poll(1000, () => GLib.DateTime.new_now_local()); -export const bindCurrentTime = (format: string, fallback?: (time: GLib.DateTime) => string) => - bind(currentTime).as(c => c.format(format) ?? fallback?.(c) ?? new Date().toLocaleString()); +export const bindCurrentTime = ( + format: Binding | string, + fallback?: (time: GLib.DateTime) => string, + self?: JSX.Element +) => { + const fmt = (c: GLib.DateTime, format: string) => c.format(format) ?? fallback?.(c) ?? new Date().toLocaleString(); + if (typeof format === "string") return bind(currentTime).as(c => fmt(c, format)); + if (!self) throw new Error("bindCurrentTime: self is required when format is a Binding"); + const time = Variable.derive([currentTime, format], (c, f) => fmt(c, f)); + self?.connect("destroy", () => time.drop()); + return bind(time); +}; -- cgit v1.2.3-freya