mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 17:28:53 +00:00
fix(ESX.UI): Close Opened Menus on Resource Stop
I have encountered several frustrating instances when accidentally restarting a script that still had an open ESX UI. This situation prevents the UI from closing properly and leads to a cascade of errors, ultimately forcing a game restart. To address this issue, I propose the following code changes. The code introduces an event handler for the onResourceStop event, enabling us to loop through all open ESX UIs and identify any opened menus within the same namespace as the resource name. Following the best practice, the namespace should ideally align with the resource name. I believe implementing these changes will provide a smoother user experience. I look forward to your feedback and merging these improvements into the main branch.
This commit is contained in:
@@ -1343,6 +1343,17 @@ AddEventHandler('esx:showHelpNotification', function(msg, thisFrame, beep, durat
|
||||
ESX.ShowHelpNotification(msg, thisFrame, beep, duration)
|
||||
end)
|
||||
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
for i = 1, #ESX.UI.Menu.Opened, 1 do
|
||||
if ESX.UI.Menu.Opened[i] then
|
||||
if ESX.UI.Menu.Opened[i].namespace == resourceName then
|
||||
ESX.UI.Menu.Opened[i].close()
|
||||
ESX.UI.Menu.Opened[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
---@param model number|string
|
||||
---@return string
|
||||
function ESX.GetVehicleType(model)
|
||||
|
||||
Reference in New Issue
Block a user