Docs/Yecoyz Tablet

Your own apps

Put a page from your own resource on Yecoyz Tablet with the app SDK.

An app is a web page from your resource (plain HTML, React, Vue, anything) that the tablet shows full screen. Your page talks to your own Lua the usual way (RegisterNUICallback), and the SDK adds messages from Lua, notifications, closing and typing into text fields.

A complete example is in sdk/example/yecoyz_tablet_example. Copy it to your resources, ensure it after yecoyz_tablet and open the tablet to see the Example app.

1. Register the app (client)

lua
local function register()
    local ok, err = exports.yecoyz_tablet:RegisterApp({
        id = 'garage',                   -- unique: letters, digits, _ and -
        label = 'Garage',                -- under the icon (max 24 characters)
        ui = 'web/dist/index.html',      -- a path in your resource
        icon = 'car',                    -- a built-in icon name or an image like 'web/icon.png'
        color = '#29292f',               -- optional tile colour
        description = 'Your vehicles',
        jobs = { mechanic = 0 },         -- optional: only these jobs (and minimum grades) see it
        installedByDefault = true,       -- false: install it from the Apps app first
        removable = true,
    })
    if not ok then print(err) end
end

CreateThread(register)

-- The tablet forgets apps when it restarts, so register again:
AddEventHandler('onClientResourceStart', function(res)
    if res == 'yecoyz_tablet' then register() end
end)

List the page in your fxmanifest files { }. It doesn't have to be your ui_page. When your resource stops, its apps are removed.

Important

jobs only hides the icon. Check permissions on your server for anything that matters.

The page is shown at 1280 x 766 pixels (the screen minus the status bar).

2. Load the SDK in your page

html
<script src="https://cfx-nui-yecoyz_tablet/sdk/tablet.js"></script>

That gives the page a global Tablet:

Tablet.ready(fn) fn(info) once the tablet has connected
Tablet.on(action, fn) Messages from Lua, plus 'visibility' when the app is shown or hidden
Tablet.off(action, fn) Stop listening
Tablet.post(event, data) POST to RegisterNUICallback(event) in your resource. Returns a Promise
Tablet.notify(title, text) A notification on the tablet, linked to your app
Tablet.close() Back to the home screen
Tablet.inGame false in a normal browser, for building the page with a dev server

Typing works in <input> and <textarea>, with Ctrl+V, Ctrl+A and Enter. Esc always puts the tablet away.

3. Talk to the app from Lua

Client:

lua
exports.yecoyz_tablet:SendAppMessage('garage', 'vehicleStored', { plate = 'ABC123' })
exports.yecoyz_tablet:Notify({ app = 'garage', title = 'Stored', text = 'ABC123' })
exports.yecoyz_tablet:OpenApp('garage')   -- takes the tablet out and opens the app
exports.yecoyz_tablet:IsOpen()
exports.yecoyz_tablet:Open()
exports.yecoyz_tablet:Close()
exports.yecoyz_tablet:GetApps()
exports.yecoyz_tablet:UnregisterApp('garage')

Server:

lua
exports.yecoyz_tablet:SendAppMessage(source, 'garage', 'vehicleStored', data)
exports.yecoyz_tablet:Notify(source, { app = 'garage', title = 'Stored', text = 'ABC123' })
exports.yecoyz_tablet:IsOpen(source)

Messages are dropped while the app's page isn't loaded. Load what the page needs with Tablet.post when it becomes ready or visible, and use messages for live updates.

Client events: yecoyz_tablet:client:appOpened and yecoyz_tablet:client:appClosed, with the app id.

Built-in icons

alert app badge bank book briefcase calculator calendar camera car chart chat clipboard clock cloud cpu database dollar file fingerprint fire folder fuel gamepad gavel globe heart home id image info key layers list lock mail map medical mic music notes package phone radio scan search settings shield shop star store tag terminal truck user users video wallet wrench zap

Stuck on this step?

Open a ticket in the Discord with what you tried and what you see, and I'll help you get it running.

Ask on Discord