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()
class SmoothProgress extends Widget.Box {
@property(Number)

View file

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

View file

@ -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<boolean> {
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);
});
});
}}
/>

View file

@ -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 (
<NotifGestureWrapper
id={id}
popup_timer={popup_timer}
slide_in_from={slide_in_from}
setup_notif={(self) => {
/* 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();
}
}}
}}*/
>
<box vertical className={`notification ${notifObj.urgency} widget`}>
{/* Content */}
@ -183,7 +183,7 @@ export const Notification = ({
</box>
</box>
{progress}
{/* progress */}
{/* Actions */}
<box className="actions">

View file

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