feat(agsV2): add clock
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-09-27 16:52:33 -04:00
parent af10d27e1b
commit 2dcc17cbb2
2 changed files with 55 additions and 24 deletions

View file

@ -0,0 +1,31 @@
import { bind, Variable } from 'astal';
import GLib from 'gi://GLib?version=2.0';
export default () => {
const timeVar = Variable<string>('').poll(1000, (prev) => {
const time = GLib.DateTime.new_now_local();
const dayName = time.format('%a. ');
const dayNum = time.get_day_of_month();
const date = time.format(' %b. ');
const hour = (new Date().toLocaleString([], {
hour: 'numeric',
minute: 'numeric',
hour12: true,
}) ?? '')
.replace('a.m.', 'AM')
.replace('p.m.', 'PM');
return (dayNum && dayName && date) ?
(dayName + dayNum + date + hour) :
prev;
});
return (
<box className="bar-item">
<label label={bind(timeVar)} />
</box>
);
};

View file

@ -1,14 +1,14 @@
import { Astal, Gtk } from 'astal'; import { Astal, Gtk } from 'astal';
import Battery from './items/battery'; import Battery from './items/battery';
import Clock from './items/clock';
import CurrentClient from './items/current-client'; import CurrentClient from './items/current-client';
import BarRevealer from './fullscreen'; import BarRevealer from './fullscreen';
import Separator from '../misc/separator'; import Separator from '../misc/separator';
export default () => { export default () => (
return (
<BarRevealer <BarRevealer
exclusivity={Astal.Exclusivity.EXCLUSIVE} exclusivity={Astal.Exclusivity.EXCLUSIVE}
anchor={ anchor={
@ -24,6 +24,7 @@ export default () => {
</box> </box>
<box> <box>
<Clock />
</box> </box>
<box hexpand halign={Gtk.Align.END}> <box hexpand halign={Gtk.Align.END}>
@ -35,4 +36,3 @@ export default () => {
</BarRevealer> </BarRevealer>
); );
};