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,38 +1,38 @@
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={ Astal.WindowAnchor.TOP |
Astal.WindowAnchor.TOP | Astal.WindowAnchor.LEFT |
Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT
Astal.WindowAnchor.RIGHT }
} >
>
<centerbox className="bar widget"> <centerbox className="bar widget">
<box hexpand halign={Gtk.Align.START}> <box hexpand halign={Gtk.Align.START}>
<CurrentClient /> <CurrentClient />
</box> </box>
<box> <box>
</box> <Clock />
</box>
<box hexpand halign={Gtk.Align.END}> <box hexpand halign={Gtk.Align.END}>
<Battery /> <Battery />
<Separator size={2} /> <Separator size={2} />
</box> </box>
</centerbox> </centerbox>
</BarRevealer> </BarRevealer>
); );
};