notify.lua
-- ============================================================
-- EXIT FRAGMENTATION — Smart Notify Bridge (shared/notify.lua)
-- Desteklenen: qb | qbox | esx | ox_lib | okok | mythic | standalone
-- ============================================================
-- ÖNEMLI: Bu dosya shared_scripts içinde yüklenir.
-- 'lib' global'i ox_lib bağımlılığı gerektirdiğinden KULLANILMAZ.
-- Bunun yerine exports['ox_lib']:notify() yöntemi kullanılır.
-- Tip renk normalleştirme haritası
local typeMap = {
success = { qb = 'success', esx = 'success', ox = 'success', okok = 'GREEN' },
error = { qb = 'error', esx = 'error', ox = 'error', okok = 'RED' },
primary = { qb = 'primary', esx = 'info', ox = 'info', okok = 'BLUE' },
info = { qb = 'primary', esx = 'info', ox = 'info', okok = 'BLUE' },
warning = { qb = 'error', esx = 'warning', ox = 'warning', okok = 'ORANGE' },
}
--- Aktif bildirim sistemini döndürür (önbelleklenmiş)
local _notifyType = nil
local function GetNotifySystem()
if _notifyType then return _notifyType end
local cfgType = Config and Config.NotifySystem and Config.NotifySystem.type or 'auto'
if cfgType ~= 'auto' then
_notifyType = cfgType
return _notifyType
end
-- Otomatik algılama (öncelik sırasıyla)
if GetResourceState('ox_lib') == 'started' then
_notifyType = 'ox_lib'
elseif GetResourceState('okokNotify') == 'started' then
_notifyType = 'okok'
elseif GetResourceState('mythic_notify') == 'started' then
_notifyType = 'mythic'
elseif GetResourceState('qbx_core') == 'started' then
_notifyType = 'qbox'
elseif GetResourceState('qb-core') == 'started' then
_notifyType = 'qb'
elseif GetResourceState('es_extended') == 'started' then
_notifyType = 'esx'
else
_notifyType = 'standalone'
end
return _notifyType
end
--- QBCore Core nesnesi için güvenli sarıcı
local function SafeQBNotify(msg, qbType, duration)
local ok, core = pcall(function()
return ExitFramework and ExitFramework.GetCore()
end)
if ok and core and core.Functions and core.Functions.Notify then
core.Functions.Notify(msg, qbType, duration, "")
else
-- Event tabanlı fallback (her zaman çalışır)
TriggerEvent('QBCore:Notify', msg, qbType, duration, "")
end
end
--- Ana bildirim fonksiyonu
-- @param msg string — Mesaj metni
-- @param ntype string — 'success' | 'error' | 'primary' | 'info' | 'warning'
-- @param duration number — Süre (ms)
function ExitNotify(msg, ntype, duration)
ntype = ntype or 'primary'
duration = duration or (Config and Config.NotifySystem and Config.NotifySystem.defaultDuration) or 5000
-- Sunucu tarafında bu fonksiyon çağrılırsa erken çık
-- (Sunucu bildirimleri TriggerClientEvent ile yönlendirilir)
if IsDuplicityVersion() then return end
local system = GetNotifySystem()
local tm = typeMap[ntype] or typeMap['primary']
local title = ""
local pos = Config and Config.NotifySystem and Config.NotifySystem.position or 'top-right'
-- ── Dahili NUI toast (Tablet açıkken görünür) ─────────────
if Config and Config.NotifySystem and Config.NotifySystem.showTabletToast ~= false then
SendNUIMessage({ action = 'toast', msg = msg, type = ntype, duration = duration })
end
-- ── Zıplayıcı sistem seçimi ───────────────────────────────
if system == 'ox_lib' then
-- 'lib' global DEĞİL → exports üzerinden çağır (güvenli)
local ok = pcall(function()
exports['ox_lib']:notify({
title = nil, -- Başlık yok
description = msg,
type = tm.ox,
duration = duration,
position = pos
})
end)
if not ok then
-- ox_lib export başarısız → QBCore fallback
SafeQBNotify(msg, tm.qb, duration)
end
elseif system == 'okok' then
local ok = pcall(function()
exports['okokNotify']:Alert("", msg, duration, tm.okok)
end)
if not ok then SafeQBNotify(msg, tm.qb, duration) end
elseif system == 'mythic' then
local ok = pcall(function()
exports['mythic_notify']:DoHudText(ntype, msg)
end)
if not ok then SafeQBNotify(msg, tm.qb, duration) end
elseif system == 'qb' or system == 'qbox' then
SafeQBNotify(msg, tm.qb, duration)
elseif system == 'esx' then
local ok = pcall(function()
local core = ExitFramework.GetCore()
if core and core.ShowNotification then
core.ShowNotification(msg)
else
TriggerEvent('esx:showNotification', msg)
end
end)
if not ok then TriggerEvent('esx:showNotification', msg) end
else
-- ── STANDALONE: sadece NUI toast + opsiyonel chat ─────
if Config and Config.NotifySystem and Config.NotifySystem.standaloneChat then
local colors = { success = '~g~', error = '~r~', primary = '~b~', warning = '~y~' }
local c = colors[ntype] or ''
local t = title ~= "" and title or "SİSTEM"
TriggerEvent('chat:addMessage', {
color = { 255, 255, 255 },
multiline = false,
args = { t, c .. msg }
})
end
end
end
-- ─────────────────────────────────────────────────────────────
-- Client-side başlatma (shared_scripts'te sadece client çalıştırır)
-- ─────────────────────────────────────────────────────────────
if not IsDuplicityVersion() then
-- Sunucudan gelen showToast event'lerini yakala
RegisterNetEvent('exit-fragmentation:client:showToast')
AddEventHandler('exit-fragmentation:client:showToast', function(msg, ntype, duration)
ExitNotify(msg, ntype, duration)
end)
-- Config.Notify'ı smart notify ile override et
if Config then
Config.Notify = function(msg, ntype, duration)
ExitNotify(msg, ntype, duration)
end
end
end