# Custom App Usage

## GetCurrentTabletData

This document explains how to use the `GetCurrentTabletData` export provided by `0r-smarttab` to access the currently open tablet’s data (including gallery photos) from any client-side Lua resource.&#x20;

```lua
local tablet = exports['0r-smarttab']:GetCurrentTabletData(options)
```

returns a **Lua table** that describes the **tablet currently open for the local player**.

Base shape:

```lua
{
    isOpen = boolean,     -- whether the tablet UI is currently open
    serial = string|nil,  -- active tablet serial, or nil if none
    gallery = table|nil,  -- optional, only when requested
}
```

You can call this from **any client-side script** as long as `0r-smarttab` is running.

***

### 2. Basic usage

Minimal example:

```lua
local tablet = exports['0r-smarttab']:GetCurrentTabletData()

if tablet.isOpen and tablet.serial then
    print(("[SmartTab] Current tablet serial: %s"):format(tablet.serial))
else
    print("[SmartTab] No tablet is currently open.")
end
```

* `tablet.isOpen` → whether the player currently has the tablet open.
* `tablet.serial` → serial number of the active tablet (useful as a key in your own systems/DB).

***

### 3. Including gallery data

If you also want to fetch the **cloud gallery** for the active tablet owner, use the `includeGallery` option:

```lua
local tablet = exports['0r-smarttab']:GetCurrentTabletData({ includeGallery = true })

if tablet.isOpen and tablet.serial then
    print("Current tablet serial:", tablet.serial)

    if tablet.gallery then
        print("Gallery items:", #tablet.gallery)
        for i, photo in ipairs(tablet.gallery) do
            print(("[#%d] url=%s type=%s favorite=%s"):format(
                i,
                photo.url or photo.image or "nil",
                tostring(photo.type or "unknown"),
                tostring(photo.is_favorite)
            ))
        end
    end
end
```

When `includeGallery = true`, `tablet.gallery` is a list of rows based on the `0r_tablet_gallery` table, typically:

```lua
{
    id            = number,
    tablet_serial = string,
    image         = string,   -- stored image field
    url           = string,   -- same as image, provided for UI convenience
    type          = string,   -- e.g. "photo", "screenshot", etc.
    is_favorite   = boolean,
    album_id      = string|nil,
    created_at    = string|nil,
}
```

You can pass `photo.url` directly to your NUI or reuse it for your own mini-galleries / pickers.

***

### 4. Typical use cases

#### 4.1 Custom apps

Inside a custom app’s `client.lua`:

```lua
local tablet = exports['0r-smarttab']:GetCurrentTabletData({ includeGallery = true })

if tablet.isOpen and tablet.serial then
    -- attach your own data to this serial
    -- e.g. load job-specific info, tickets, etc.
    if tablet.gallery then
        -- show a custom gallery in your own NUI
    end
end
```

Use cases:

* Show the player’s gallery inside your own app UI.
* Filter photos by type or album.
* Use the serial as a key for app-specific data.

#### 4.2 Job / utility scripts

Any job script can:

* Check whether a tablet is currently open before performing actions.
* Link actions or logs to the **active tablet serial** instead of (or in addition to) player ID.

Example:

```lua
RegisterCommand('tabletdebug', function()
    local tablet = exports['0r-smarttab']:GetCurrentTabletData({ includeGallery = true })
    print(json.encode(tablet, { indent = true }))
end, false)
```

***

### 5. Notes and caveats

* The export is **client-side only**. Call it from client scripts, not from server code.
* If no tablet is open, you will always get at least:

  ```lua
  { isOpen = false, serial = nil }
  ```
* `includeGallery = true` triggers an async callback internally and waits for it; avoid calling it every frame. It’s intended for on-demand usage (e.g. when opening your custom app UI or pressing a key).

This export is designed to make it easy for **custom apps and other resources** to integrate with the tablet ecosystem and reuse existing tablet data (especially gallery photos) without duplicating logic.

```
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.0resmon.org/0resmon/0r-resources/0r-smarttab/create-custom-app/custom-app-usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
