From 818c3b8707e674e139ba5969d1bcfddb24906ada Mon Sep 17 00:00:00 2001 From: hajdenos <138399356+Hajdenko@users.noreply.github.com> Date: Thu, 20 Mar 2025 19:00:19 +0100 Subject: [PATCH] feat(alert): added lib.getOpenAlertDialog Added a function that gets the state of the AlertDialog. Usage: local isOpen, data = lib.getOpenAlertDialog() Signed-off-by: hajdenos <138399356+Hajdenko@users.noreply.github.com> --- resource/interface/client/alert.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/resource/interface/client/alert.lua b/resource/interface/client/alert.lua index 3726732fb..11166ac13 100644 --- a/resource/interface/client/alert.lua +++ b/resource/interface/client/alert.lua @@ -7,7 +7,7 @@ ]] ---@type promise? -local alert = nil +local alert, alertData = nil, nil local alertId = 0 ---@class AlertDialogProps @@ -28,11 +28,12 @@ function lib.alertDialog(data, timeout) local id = alertId + 1 alertId = id alert = promise.new() + alertData = data lib.setNuiFocus(false) SendNUIMessage({ action = 'sendAlert', - data = data + data = alertData }) if timeout then @@ -41,7 +42,11 @@ function lib.alertDialog(data, timeout) end) end - return Citizen.Await(alert) + return alert:await() +end + +function lib.getOpenAlertDialog() + return alert ~= nil, alertData end ---@param reason? string An optional reason for the window to be closed. @@ -54,7 +59,7 @@ function lib.closeAlertDialog(reason) }) local p = alert - alert = nil + alert, alertData = nil, nil if reason then p:reject(reason) else p:resolve() end end @@ -64,7 +69,7 @@ RegisterNUICallback('closeAlert', function(data, cb) lib.resetNuiFocus() local promise = alert --[[@as promise]] - alert = nil + alert, alertData = nil, nil promise:resolve(data) end)