diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-02-22 19:58:07 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-02-22 19:58:07 +1100 |
| commit | cf55e2613314e27243c60395e58665b9309280c8 (patch) | |
| tree | 572b6226dad2c84621deb33d765d5a67454fc842 /src/utils/system.ts | |
| parent | scss: make notifpopup shadow default (diff) | |
| download | caelestia-shell-cf55e2613314e27243c60395e58665b9309280c8.tar.gz caelestia-shell-cf55e2613314e27243c60395e58665b9309280c8.tar.bz2 caelestia-shell-cf55e2613314e27243c60395e58665b9309280c8.zip | |
config: use config file
Config file at ~/.config/caelestia/shell.json
Diffstat (limited to 'src/utils/system.ts')
| -rw-r--r-- | src/utils/system.ts | 16 |
1 files changed, 13 insertions, 3 deletions
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> | 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); +}; |