From df3b51399cbe82b083ef04230f3b340e12621afb Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 27 Jan 2025 21:55:02 +1100 Subject: sideright: make popdown window Weather requires a weather api key from https://weatherapi.com --- src/modules/popdowns/index.tsx | 2 + src/modules/popdowns/sideright.tsx | 127 +++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 src/modules/popdowns/sideright.tsx (limited to 'src/modules/popdowns') diff --git a/src/modules/popdowns/index.tsx b/src/modules/popdowns/index.tsx index 9ee9f77..c4f4664 100644 --- a/src/modules/popdowns/index.tsx +++ b/src/modules/popdowns/index.tsx @@ -2,6 +2,7 @@ import BluetoothDevices from "./bluetoothdevices"; import Media from "./media"; import Networks from "./networks"; import Notifications from "./notifications"; +import SideRight from "./sideright"; import Updates from "./updates"; export default () => { @@ -10,6 +11,7 @@ export default () => { ; ; ; + ; return null; }; diff --git a/src/modules/popdowns/sideright.tsx b/src/modules/popdowns/sideright.tsx new file mode 100644 index 0000000..86c0547 --- /dev/null +++ b/src/modules/popdowns/sideright.tsx @@ -0,0 +1,127 @@ +import { bind } from "astal"; +import { Astal, Gtk, type Gdk } from "astal/gtk3"; +import SWeather, { type WeatherData } from "../../services/weather"; +import { ellipsize } from "../../utils/strings"; +import { bindCurrentTime } from "../../utils/system"; +import { Calendar as WCal } from "../../utils/widgets"; +import PopupWindow from "../../widgets/popupwindow"; + +const getHoursFromUpdate = (data: WeatherData, hours: number) => { + const updateTime = data.location.localtime_epoch; + const updateHourStart = updateTime - (updateTime % 3600); + + let nextHour = new Date((updateHourStart + hours * 3600) * 1000).getHours(); + if (nextHour >= 24) nextHour -= 24; + + return nextHour; +}; + +const Time = () => ( + + + + +); + +const Calendar = () => ( + + { + self.connect("button-press-event", (_, event: Gdk.Event) => { + if (event.get_button()[1] === Astal.MouseButton.MIDDLE) { + const now = new Date(); + const child = self.get_child() as WCal | null; + if (!child) return; + child.select_month(now.getMonth(), now.getFullYear()); + } + }); + }} + > + { + const update = () => { + const now = new Date(); + if (self.month === now.getMonth() && self.year === now.getFullYear()) self.day = now.getDate(); + else self.day = 0; + }; + self.connect("month-changed", update); + self.connect("next-month", update); + self.connect("prev-month", update); + self.connect("next-year", update); + self.connect("prev-year", update); + update(); + }} + /> + + +); + +const Weather = () => { + const weather = SWeather.get_default(); + + return ( + + + + + + {Array.from({ length: 4 }).map((_, i) => ( + + + ))} + + + ); +}; + +export default () => ( + + + + +); -- cgit v1.2.3-freya