2024-09-27 16:52:33 -04:00
|
|
|
import { bind, Variable } from 'astal';
|
2024-10-21 16:35:20 -04:00
|
|
|
import { App } from 'astal/gtk3';
|
2024-09-27 16:52:33 -04:00
|
|
|
|
|
|
|
import GLib from 'gi://GLib?version=2.0';
|
2024-10-21 16:35:20 -04:00
|
|
|
import { PopupWindow } from '../../misc/popup-window';
|
2024-09-27 16:52:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
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 (
|
2024-10-21 16:35:20 -04:00
|
|
|
<button
|
|
|
|
className="bar-item"
|
|
|
|
cursor="pointer"
|
|
|
|
|
|
|
|
onButtonReleaseEvent={(self) => {
|
|
|
|
const win = App.get_window('win-calendar') as PopupWindow;
|
|
|
|
|
|
|
|
win.set_x_pos(
|
|
|
|
self.get_allocation(),
|
|
|
|
'right',
|
|
|
|
);
|
|
|
|
|
|
|
|
win.visible = !win.visible;
|
|
|
|
}}
|
|
|
|
|
|
|
|
setup={(self) => {
|
|
|
|
App.connect('window-toggled', (_, win) => {
|
|
|
|
if (win.name === 'win-notif-center') {
|
|
|
|
self.toggleClassName('toggle-on', win.visible);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
2024-09-27 16:52:33 -04:00
|
|
|
<label label={bind(timeVar)} />
|
2024-10-21 16:35:20 -04:00
|
|
|
</button>
|
2024-09-27 16:52:33 -04:00
|
|
|
);
|
|
|
|
};
|