ADD - introduce unique phone devices

This commit is contained in:
Eichenholz
2026-08-04 18:35:57 +02:00
parent 75be4c2a69
commit 46e6c6cc25
11 changed files with 1066 additions and 191 deletions
+59 -17
View File
@@ -1,7 +1,19 @@
local is_open = false
local notification_focus = false
local device_payload = nil
local mail_callbacks = {
local server_callbacks = {
"device:save",
"device:factory-reset",
"account:login",
"account:register",
"account:logout",
"account:devices",
"account:remove-device",
"notes:list",
"notes:create",
"notes:update",
"notes:delete",
"mail:register",
"mail:login",
"mail:logout",
@@ -24,17 +36,21 @@ local function get_locale()
end
local function send_open_message()
if not device_payload then
return
end
local payload = device_payload
payload.lang = Sky.Config.locale
payload.locales = get_locale().Nui
SendNUIMessage({
type = "app:open",
data = {
lang = Sky.Config.locale,
locales = get_locale().Nui,
},
data = payload,
})
end
local function open_phone()
if is_open then
if is_open or not device_payload then
return
end
@@ -52,16 +68,18 @@ local function close_phone()
is_open = false
SetNuiFocus(notification_focus, notification_focus)
SendNUIMessage({ type = "app:close" })
Sky.Cb.Trigger("sky_phone:device:close", {})
end
RegisterCommand(Config.Command, function()
if is_open then
close_phone()
return
end
open_phone()
end, false)
if Config.Phone.DevelopmentCommand then
RegisterCommand(Config.Command, function()
if is_open then
close_phone()
return
end
Sky.Cb.Trigger("sky_phone:device:development-open", {})
end, false)
end
RegisterNUICallback("ui:ready", function(_, cb)
if is_open then
@@ -82,7 +100,7 @@ RegisterNUICallback("notification:focus", function(data, cb)
cb({ success = true })
end)
for _, callback_name in ipairs(mail_callbacks) do
for _, callback_name in ipairs(server_callbacks) do
RegisterNUICallback(callback_name, function(data, cb)
local result = Sky.Cb.Trigger("sky_phone:" .. callback_name, data)
if result then
@@ -94,6 +112,26 @@ for _, callback_name in ipairs(mail_callbacks) do
end)
end
RegisterNetEvent("sky_phone:device:open", function(data)
device_payload = data
open_phone()
end)
RegisterNetEvent("sky_phone:device:updated", function(data)
device_payload = data
SendNUIMessage({ type = "device:updated", data = data })
end)
RegisterNetEvent("sky_phone:device:invalidated", function()
device_payload = nil
close_phone()
end)
RegisterNetEvent("sky_phone:device:error", function(error_code)
local message = get_locale().DeviceErrors[error_code] or get_locale().DeviceErrors.default
Sky.Show.Notification("iFruit", message, "error", 5000)
end)
RegisterNetEvent("sky_phone:mail:changed", function(data)
SendNUIMessage({ type = "mail:changed", data = data })
end)
@@ -103,7 +141,9 @@ RegisterNetEvent("sky_phone:mail:new", function(data)
end)
CreateThread(function()
TriggerEvent("chat:addSuggestion", "/" .. Config.Command, get_locale().CommandDescription)
if Config.Phone.DevelopmentCommand then
TriggerEvent("chat:addSuggestion", "/" .. Config.Command, get_locale().CommandDescription)
end
end)
AddEventHandler("onResourceStop", function(resource_name)
@@ -115,5 +155,7 @@ AddEventHandler("onResourceStop", function(resource_name)
SetNuiFocus(false, false)
end
TriggerEvent("chat:removeSuggestion", "/" .. Config.Command)
if Config.Phone.DevelopmentCommand then
TriggerEvent("chat:removeSuggestion", "/" .. Config.Command)
end
end)