From 019a02b10d7fd4467385fea60c695938b50194f0 Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Fri, 18 Apr 2025 21:46:10 -0300 Subject: [PATCH] :boom: ags(ask-popup): fix wrong behaviors, make `AskPopupProps.onAccept` prop optional --- ags/widget/AskPopup.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ags/widget/AskPopup.ts b/ags/widget/AskPopup.ts index 80e0859..706abf9 100644 --- a/ags/widget/AskPopup.ts +++ b/ags/widget/AskPopup.ts @@ -11,7 +11,7 @@ export type AskPopupProps = { text: string | Binding; cancelText?: string; acceptText?: string; - onAccept: () => void; + onAccept?: () => void; onCancel?: () => void; }; @@ -23,19 +23,22 @@ export type AskPopupProps = { * system. */ export function AskPopup(props: AskPopupProps): Widget.Window { + let accepted: boolean = false; + const buttons = [ new Widget.Button({ className: "cancel", hexpand: true, - label: props.cancelText || tr("ask_popup.options.cancel") || "Cancel", + label: props.cancelText ?? tr("cancel"), onClick: () => window.close(), } as Widget.ButtonProps), new Widget.Button({ className: "accept", hexpand: true, - label: props.acceptText || tr("ask_popup.options.accept") || "Ok", + label: props.acceptText ?? tr("accept"), onClick: () => { window.close(); + accepted = true; props.onAccept?.(); } } as Widget.ButtonProps) @@ -50,7 +53,7 @@ export function AskPopup(props: AskPopupProps): Widget.Window { layer: Astal.Layer.OVERLAY, widthRequest: 400, heightRequest: 220, - onDestroy: () => props.onCancel?.(), + onDestroy: () => !accepted && props.onCancel?.(), child: new Widget.Box({ className: "ask-popup-box", orientation: Gtk.Orientation.VERTICAL,