diff --git a/modules/notifications/client.lua b/modules/notifications/client.lua new file mode 100644 index 0000000..580c504 --- /dev/null +++ b/modules/notifications/client.lua @@ -0,0 +1,50 @@ +local inventory = require 'bridge.inventory' + +---@type boolean +local doNotDisturb = false + +---@type number +local lastNotificationSound = 0 + +---@type string | nil +local item = lib.callback.await('fd_laptop:laptopItem', false) + +---@param data Notification +local function sendNotification(data) + if not data then return end + if not data.summary then return end + if not data.detail then return end + + if doNotDisturb then + return + end + + if not inventory.hasItem(item, nil) then + return + end + + if GetGameTimer() - lastNotificationSound >= 5000 then + PlaySoundFrontend(-1, "Text_Arrive_Tone", "Phone_SoundSet_Default", true) + lastNotificationSound = GetGameTimer() + 5000 + end + + SendNUIMessage({ + action = 'newNotification', + data = { + summary = data.summary, + detail = data.detail + } + }) +end +exports('sendNotification', sendNotification) + +RegisterNUICallback('setDoNotDisturb', function(data, cb) + doNotDisturb = data.doNotDisturb + + cb(1) +end) + +RegisterNetEvent('fd_laptop:server:playerUnloaded', function() + doNotDisturb = false + lastNotificationSound = 0 +end) diff --git a/web/src/App.vue b/web/src/App.vue index b15707b..af9426e 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -2,6 +2,7 @@ import { defineAsyncComponent, onMounted } from 'vue' import { useDevelopment } from './stores/development.store' import { useLaptop } from './stores/laptop.store' +import { useNotifications } from './stores/notifications.store' const Laptop = defineAsyncComponent(() => import('./components/Laptop.vue')) const DevelopmentToolbar = defineAsyncComponent( @@ -10,6 +11,7 @@ const DevelopmentToolbar = defineAsyncComponent( const dev = useDevelopment() const laptop = useLaptop() +const notif = useNotifications() onMounted(() => { if (dev.isDevEnv) { @@ -21,6 +23,6 @@ onMounted(() => { diff --git a/web/src/components/overlays/NotificationsOverlay.vue b/web/src/components/overlays/NotificationsOverlay.vue index 452e553..8ace5ec 100644 --- a/web/src/components/overlays/NotificationsOverlay.vue +++ b/web/src/components/overlays/NotificationsOverlay.vue @@ -1,7 +1,7 @@