Usage

Creating items as external devices

Laptop has it's own storage, which accepts items with only specific metadata. Those items correspond as devices, it can be used to enable app, or use in your custom app, maybe like gps modules, identification device and etc. If you ask us, pretty cool, and it lets to expand your custom apps to whole different level.

This also makes laptop quite unique, since devices are unique per laptop, so if you loose your laptop you'll need to put device in the storage to access somekind of once again.

Item metadata

To be able to put device into laptop storage, item has to have specific metadata.

 ---@class LaptopDeviceMetadata
 ---@field deviceId string
 ---@field deviceLabel string
 ---@comment noDuplicate field defines, if item with this deviceId is allowed to be in laptop storage.
 ---@comment This basically makes that only device with such deviceId can be in laptop storage.
 ---@field noDuplicate? boolean
 ...

Create items with metadata

With ox_inventory you can simple create your chosen item with metadata by using hooks. Here's an example:

    ox_inventory:registerHook('createItem', function(payload)
        return {
            deviceId = 'some_device_id',
            deviceLabel = 'Very awesome label',
            noDuplicate = false
        }
    end, {
        itemFilter = {
            ['laptop_usb'] = true
        }
    })

Every time laptop_usb is created, it'll add the needed metadata.

Make app available only with item

While registering custom app, you can set deviceId, which will make app only appear if device with such id is detected in laptop storage. Here's an example:

server.lua
   CreateThread(function()
      while GetResourceState("fd_laptop") ~= "started" do
          Wait(500)
      end

      --
      local added, errorMessage = exports.fd_laptop:addCustomApp({
          id = "testing_app",
          name = "Testing App",
          isDefaultApp = true,
          needsUpdate = false,
          icon = 'question.svg',
          ui = ("https://cfx-nui-%s/web/index.html"):format(GetCurrentResourceName()),
          deviceId = 'some_device_id' -- <-- This defines required device with that id.
          keepAlive = true,
          ignoreInternalLoading = true,
          windowActions = {
              isResizable = false,
              isMaximizable = false,
              isClosable = true,
              isMinimizable = true,
              isDraggable = false
          },
          windowDefaultStates = {
              isMaximized = true,
              isMinimized = false
          },
      })

      if not added then
          print("Could not add app:", errorMessage)
      end
  end)