For the complete documentation index, see llms.txt. This page is also available as Markdown.

πŸŒ‰Custom Widget

Making a special widget for Gksphone v2

Adding the widget

To add a home-screen widget, use the AddCustomWidget export.

We have template widget that you can use for reference.

Install the demo resource

  1. Copy the custom-widget folder into your server resources directory.

  2. Add to server.cfg:

ensure gksphone
ensure custom-widget
  1. In-game: open the phone β†’ long-press home β†’ + β†’ Widgets β†’ Demo Widget.

Resource setup

Your resource must expose the widget HTML via FiveM files so the phone can load it as an iframe:

-- fxmanifest.lua
files {
    'ui/widget.html',
    'ui/widget.css',
    'ui/widget.js'
}

Prefer a cfx-nui URL:

Exports - Client

AddCustomWidget

Registers (or updates) a widget in the phone gallery.

Recommended pattern (wait until gksphone is started):

RemoveCustomWidget

Removes a widget from the gallery registry. Home-screen instances of that id are cleaned up by the phone.

Example on resource stop:

If your widgetUrl uses https://cfx-nui-<resource>/..., GKSPHONE also auto-removes matching widgets when that resource stops.

Widget sizes

Size
Cells
Notes

1x1

1Γ—1

Compact

2x2

2Γ—2

Default (recommended for demos)

4x2

Full width Γ— 2 rows

Wide strip

4x4

Full width Γ— 4 rows

Large

The size is stored on each home-screen instance when the player adds the widget from the gallery.

Javascript UI

The phone embeds your page in an iframe and sends postMessage events.

Init message

Sent when the iframe finishes loading:

Editing message

Sent when the player enters or leaves home edit mode:

While editing, the phone disables pointer events on the iframe (same jiggle behavior as built-in widgets). Use the editing flag if you want to show an in-widget hint.

Minimal HTML example

Config (optional)

You can also list static widgets in gksphone config:

Runtime registration via AddCustomWidget is preferred for third-party resources.

Last updated