fix(agsV2): catch errors from notifs
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-10-29 17:30:40 -04:00
parent 5abc944b81
commit 1378072df9
5 changed files with 65 additions and 26 deletions

View file

@ -7,6 +7,7 @@ type SmoothProgressProps = Widget.BoxProps & {
}; };
// PERF: this is kinda laggy
@register() @register()
class SmoothProgress extends Widget.Box { class SmoothProgress extends Widget.Box {
@property(Number) @property(Number)

View file

@ -119,6 +119,7 @@ export class SortedList<T> {
on_open={() => { on_open={() => {
entry.text = ''; entry.text = '';
centerCursor(); centerCursor();
entry.grab_focus();
}} }}
> >
<box <box
@ -145,7 +146,7 @@ export class SortedList<T> {
<scrollable <scrollable
className="widget list" className="widget list"
css="min-height: 600px; min-width: 600px;" css="min-height: 600px; min-width: 700px;"
hscroll={Gtk.PolicyType.NEVER} hscroll={Gtk.PolicyType.NEVER}
vscroll={Gtk.PolicyType.AUTOMATIC} vscroll={Gtk.PolicyType.AUTOMATIC}
> >

View file

@ -1,6 +1,6 @@
import { Gdk, Gtk, Widget } from 'astal/gtk3'; import { Gdk, Gtk, Widget } from 'astal/gtk3';
import { property, register } from 'astal/gobject'; import { property, register } from 'astal/gobject';
import { idle, interval } from 'astal'; import { idle, interval, timeout } from 'astal';
import AstalIO from 'gi://AstalIO'; import AstalIO from 'gi://AstalIO';
@ -63,6 +63,8 @@ export class NotifGestureWrapper extends Widget.EventBox {
@property(Boolean) @property(Boolean)
declare dragging: boolean; declare dragging: boolean;
private _sliding_away = false;
private async get_hovered(): Promise<boolean> { private async get_hovered(): Promise<boolean> {
const layers = JSON.parse(await hyprMessage('j/layers')) as LayerResult; const layers = JSON.parse(await hyprMessage('j/layers')) as LayerResult;
const cursorPos = JSON.parse(await hyprMessage('j/cursorpos')) as CursorPos; const cursorPos = JSON.parse(await hyprMessage('j/cursorpos')) as CursorPos;
@ -101,7 +103,7 @@ export class NotifGestureWrapper extends Widget.EventBox {
.slice(0, index) .slice(0, index)
.reduce((prev, curr) => prev + curr, 0); .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 && if (cursorPos.x >= notifLayer.x &&
cursorPos.x <= notifLayer.x + notifLayer.w) { cursorPos.x <= notifLayer.x + notifLayer.w) {
return true; return true;
@ -121,21 +123,39 @@ export class NotifGestureWrapper extends Widget.EventBox {
)); ));
} }
public slideAway(side: 'Left' | 'Right') { public slideAway(side: 'Left' | 'Right'): void {
if (!this.sensitive) { if (!this.sensitive || this._sliding_away) {
return; return;
} }
((this.get_child() as Widget.Revealer).get_child() as Widget.Box)
.css = side === 'Left' ? slideLeft : slideRight;
// Make it uninteractable // Make it uninteractable
this.sensitive = false; this.sensitive = false;
this._sliding_away = true;
setTimeout(() => { let rev = this.get_child() as Widget.Revealer | null;
(this.get_child() as Widget.Revealer).revealChild = false;
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 // Kill notif if specified
if (!this.is_popup) { if (!this.is_popup) {
Notifications.get_notification(this.id)?.dismiss(); Notifications.get_notification(this.id)?.dismiss();
@ -146,13 +166,12 @@ export class NotifGestureWrapper extends Widget.EventBox {
else { else {
// Make sure we cleanup any references to this instance // Make sure we cleanup any references to this instance
NotifGestureWrapper.popups.delete(this.id); NotifGestureWrapper.popups.delete(this.id);
this.timer_object?.cancel();
} }
// Get rid of disappeared widget // Get rid of disappeared widget
this.destroy(); this.destroy();
}, ANIM_DURATION); });
}, ANIM_DURATION - 100); });
} }
constructor({ constructor({
@ -181,6 +200,10 @@ export class NotifGestureWrapper extends Widget.EventBox {
on_leave_notify_event: () => { on_leave_notify_event: () => {
this.setCursor('grab'); this.setCursor('grab');
}, },
onDestroy: () => {
this.timer_object?.cancel();
},
}); });
this.id = id; this.id = id;
@ -203,7 +226,7 @@ export class NotifGestureWrapper extends Widget.EventBox {
} }
} }
} }
catch (_) { catch (_e) {
this.timer_object?.cancel(); this.timer_object?.cancel();
} }
}); });
@ -284,20 +307,34 @@ export class NotifGestureWrapper extends Widget.EventBox {
slideRight; slideRight;
idle(() => { 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 // Then we go to center
self.css = defaultStyle; self.css = defaultStyle;
if (this.is_popup) { if (this.is_popup) {
setTimeout(() => { timeout(ANIM_DURATION, () => {
NotifGestureWrapper.on_sliding_in( NotifGestureWrapper.on_sliding_in(
--NotifGestureWrapper.sliding_in, --NotifGestureWrapper.sliding_in,
); );
}, ANIM_DURATION); });
} }
}, ANIM_DURATION); });
}); });
}} }}
/> />

View file

@ -10,7 +10,7 @@ import AstalNotifd from 'gi://AstalNotifd';
const Notifications = AstalNotifd.get_default(); const Notifications = AstalNotifd.get_default();
import NotifGestureWrapper from './gesture'; import NotifGestureWrapper from './gesture';
import SmoothProgress from '../misc/smooth-progress'; // import SmoothProgress from '../misc/smooth-progress';
// Make a variable to connect to for Widgets // Make a variable to connect to for Widgets
@ -106,14 +106,14 @@ export const Notification = ({
HasNotifs.set(Notifications.get_notifications().length > 0); HasNotifs.set(Notifications.get_notifications().length > 0);
const progress = SmoothProgress({ className: 'smooth-progress' }); // const progress = SmoothProgress({ className: 'smooth-progress' });
return ( return (
<NotifGestureWrapper <NotifGestureWrapper
id={id} id={id}
popup_timer={popup_timer} popup_timer={popup_timer}
slide_in_from={slide_in_from} slide_in_from={slide_in_from}
setup_notif={(self) => { /* setup_notif={(self) => {
if (self.is_popup) { if (self.is_popup) {
self.connect('notify::popup-timer', () => { self.connect('notify::popup-timer', () => {
progress.fraction = self.popup_timer / 5; progress.fraction = self.popup_timer / 5;
@ -122,7 +122,7 @@ export const Notification = ({
else { else {
progress.destroy(); progress.destroy();
} }
}} }}*/
> >
<box vertical className={`notification ${notifObj.urgency} widget`}> <box vertical className={`notification ${notifObj.urgency} widget`}>
{/* Content */} {/* Content */}
@ -183,7 +183,7 @@ export const Notification = ({
</box> </box>
</box> </box>
{progress} {/* progress */}
{/* Actions */} {/* Actions */}
<box className="actions"> <box className="actions">

View file

@ -16,7 +16,7 @@ export default () => (
const notifQueue: number[] = []; const notifQueue: number[] = [];
const addPopup = (id: number) => { const addPopup = (id: number) => {
if (!id) { if (!id || !Notifications.get_notification(id)) {
return; return;
} }