From 1378072df9d6c7b5ce88662de496b7cda3dc74c6 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Tue, 29 Oct 2024 17:30:40 -0400 Subject: [PATCH] fix(agsV2): catch errors from notifs --- .../ags/v2/widgets/misc/smooth-progress.tsx | 1 + .../ags/v2/widgets/misc/sorted-list.tsx | 3 +- .../ags/v2/widgets/notifs/gesture.tsx | 75 ++++++++++++++----- .../ags/v2/widgets/notifs/notification.tsx | 10 +-- nixosModules/ags/v2/widgets/notifs/popups.tsx | 2 +- 5 files changed, 65 insertions(+), 26 deletions(-) diff --git a/nixosModules/ags/v2/widgets/misc/smooth-progress.tsx b/nixosModules/ags/v2/widgets/misc/smooth-progress.tsx index 13821043..a32685b6 100644 --- a/nixosModules/ags/v2/widgets/misc/smooth-progress.tsx +++ b/nixosModules/ags/v2/widgets/misc/smooth-progress.tsx @@ -7,6 +7,7 @@ type SmoothProgressProps = Widget.BoxProps & { }; +// PERF: this is kinda laggy @register() class SmoothProgress extends Widget.Box { @property(Number) diff --git a/nixosModules/ags/v2/widgets/misc/sorted-list.tsx b/nixosModules/ags/v2/widgets/misc/sorted-list.tsx index fd207ebe..39689e22 100644 --- a/nixosModules/ags/v2/widgets/misc/sorted-list.tsx +++ b/nixosModules/ags/v2/widgets/misc/sorted-list.tsx @@ -119,6 +119,7 @@ export class SortedList { on_open={() => { entry.text = ''; centerCursor(); + entry.grab_focus(); }} > { diff --git a/nixosModules/ags/v2/widgets/notifs/gesture.tsx b/nixosModules/ags/v2/widgets/notifs/gesture.tsx index 6a01bd9d..62b28793 100644 --- a/nixosModules/ags/v2/widgets/notifs/gesture.tsx +++ b/nixosModules/ags/v2/widgets/notifs/gesture.tsx @@ -1,6 +1,6 @@ import { Gdk, Gtk, Widget } from 'astal/gtk3'; import { property, register } from 'astal/gobject'; -import { idle, interval } from 'astal'; +import { idle, interval, timeout } from 'astal'; import AstalIO from 'gi://AstalIO'; @@ -63,6 +63,8 @@ export class NotifGestureWrapper extends Widget.EventBox { @property(Boolean) declare dragging: boolean; + private _sliding_away = false; + private async get_hovered(): Promise { const layers = JSON.parse(await hyprMessage('j/layers')) as LayerResult; const cursorPos = JSON.parse(await hyprMessage('j/cursorpos')) as CursorPos; @@ -101,7 +103,7 @@ export class NotifGestureWrapper extends Widget.EventBox { .slice(0, index) .reduce((prev, curr) => prev + curr, 0); - if (cursorPos.y >= thisY && cursorPos.y <= thisY + (popups[index][1] ?? 0)) { + if (cursorPos.y >= thisY && cursorPos.y <= thisY + (popups[index]?.at(1) ?? 0)) { if (cursorPos.x >= notifLayer.x && cursorPos.x <= notifLayer.x + notifLayer.w) { return true; @@ -121,21 +123,39 @@ export class NotifGestureWrapper extends Widget.EventBox { )); } - public slideAway(side: 'Left' | 'Right') { - if (!this.sensitive) { + public slideAway(side: 'Left' | 'Right'): void { + if (!this.sensitive || this._sliding_away) { return; } - ((this.get_child() as Widget.Revealer).get_child() as Widget.Box) - .css = side === 'Left' ? slideLeft : slideRight; - // Make it uninteractable this.sensitive = false; + this._sliding_away = true; - setTimeout(() => { - (this.get_child() as Widget.Revealer).revealChild = false; + let rev = this.get_child() as Widget.Revealer | null; - setTimeout(() => { + if (!rev) { + return; + } + + const revChild = rev.get_child() as Widget.Box | null; + + if (!revChild) { + return; + } + + revChild.css = side === 'Left' ? slideLeft : slideRight; + + timeout(ANIM_DURATION - 100, () => { + rev = this.get_child() as Widget.Revealer | null; + + if (!rev) { + return; + } + + rev.revealChild = false; + + timeout(ANIM_DURATION, () => { // Kill notif if specified if (!this.is_popup) { Notifications.get_notification(this.id)?.dismiss(); @@ -146,13 +166,12 @@ export class NotifGestureWrapper extends Widget.EventBox { else { // Make sure we cleanup any references to this instance NotifGestureWrapper.popups.delete(this.id); - this.timer_object?.cancel(); } // Get rid of disappeared widget this.destroy(); - }, ANIM_DURATION); - }, ANIM_DURATION - 100); + }); + }); } constructor({ @@ -181,6 +200,10 @@ export class NotifGestureWrapper extends Widget.EventBox { on_leave_notify_event: () => { this.setCursor('grab'); }, + + onDestroy: () => { + this.timer_object?.cancel(); + }, }); this.id = id; @@ -203,7 +226,7 @@ export class NotifGestureWrapper extends Widget.EventBox { } } } - catch (_) { + catch (_e) { this.timer_object?.cancel(); } }); @@ -284,20 +307,34 @@ export class NotifGestureWrapper extends Widget.EventBox { slideRight; idle(() => { - (self.get_parent() as Widget.Revealer).revealChild = true; + if (!Notifications.get_notification(id)) { + return; + } + + const rev = self?.get_parent() as Widget.Revealer | null; + + if (!rev) { + return; + } + + rev.revealChild = true; + + timeout(ANIM_DURATION, () => { + if (!Notifications.get_notification(id)) { + return; + } - setTimeout(() => { // Then we go to center self.css = defaultStyle; if (this.is_popup) { - setTimeout(() => { + timeout(ANIM_DURATION, () => { NotifGestureWrapper.on_sliding_in( --NotifGestureWrapper.sliding_in, ); - }, ANIM_DURATION); + }); } - }, ANIM_DURATION); + }); }); }} /> diff --git a/nixosModules/ags/v2/widgets/notifs/notification.tsx b/nixosModules/ags/v2/widgets/notifs/notification.tsx index cfc9eeee..b84fb0ca 100644 --- a/nixosModules/ags/v2/widgets/notifs/notification.tsx +++ b/nixosModules/ags/v2/widgets/notifs/notification.tsx @@ -10,7 +10,7 @@ import AstalNotifd from 'gi://AstalNotifd'; const Notifications = AstalNotifd.get_default(); import NotifGestureWrapper from './gesture'; -import SmoothProgress from '../misc/smooth-progress'; +// import SmoothProgress from '../misc/smooth-progress'; // Make a variable to connect to for Widgets @@ -106,14 +106,14 @@ export const Notification = ({ HasNotifs.set(Notifications.get_notifications().length > 0); - const progress = SmoothProgress({ className: 'smooth-progress' }); + // const progress = SmoothProgress({ className: 'smooth-progress' }); return ( { + /* setup_notif={(self) => { if (self.is_popup) { self.connect('notify::popup-timer', () => { progress.fraction = self.popup_timer / 5; @@ -122,7 +122,7 @@ export const Notification = ({ else { progress.destroy(); } - }} + }}*/ > {/* Content */} @@ -183,7 +183,7 @@ export const Notification = ({ - {progress} + {/* progress */} {/* Actions */} diff --git a/nixosModules/ags/v2/widgets/notifs/popups.tsx b/nixosModules/ags/v2/widgets/notifs/popups.tsx index b564a351..f8fa23be 100644 --- a/nixosModules/ags/v2/widgets/notifs/popups.tsx +++ b/nixosModules/ags/v2/widgets/notifs/popups.tsx @@ -16,7 +16,7 @@ export default () => ( const notifQueue: number[] = []; const addPopup = (id: number) => { - if (!id) { + if (!id || !Notifications.get_notification(id)) { return; }