Desktop apps

Your app is a folder: pb_hooks, pb_migrations and pb_public. pocketone serve runs it as a server, as always. pocketone desktop build turns the same folder into an app your users double-click:

pocketone serve                  # the app as a server
pocketone desktop build          # a desktop app for this machine, in dist/
pocketone desktop build --all    # macOS, Windows and Linux, arm64 and amd64

All you need is pocketone and Docker. The build runs in a build image that holds Go and PocketOne's source, so there's no Go, C compiler or Xcode to install, and every platform builds from any machine.

Preview. Desktop builds work today, but how a desktop app handles trust and settings is still settling (see What's next). The desktop runtime uses Wails' cgo-free backends, which Wails marks experimental on macOS and Linux.

How it works

The desktop app is your PocketOne app plus a window:

  1. Your pb_hooks, pb_migrations and pb_public are embedded in the executable. Nothing is read from disk, so nobody can change a shipped app's hooks.
  2. When it starts, it runs your app's server on a private 127.0.0.1 port, applying your migrations to the user's data.
  3. It opens a native window on that server, using the system's own webview: WebKit on macOS, WebView2 on Windows, WebKitGTK on Linux.

Your pages call the API with fetch, exactly as they do in a browser. The PocketBase JS SDK, realtime and file uploads work the same, because it's the same server.

Try it: hello world

PocketOne's source has a hello-world app in ext/desktop/example/hello: a hook, a migration and one page that lists and adds greetings.

// pb_hooks/main.pb.js
routerAdd("GET", "/api/hello", (e) => {
  const rows = $app.findRecordsByFilter("greetings", "", "-created", 50, 0)
  return e.json(200, { message: "Hello from PocketOne hooks", greetings: rows.map((r) => r.get("text")) })
})

Its pocketone.yaml keeps the server's data in the folder and names the desktop app:

app:
  dir: pb_data
server:
  public_dir: pb_public
desktop:
  name: Hello
  id: dev.pocketone.hello
  width: 900
  height: 640

Run it both ways:

cd ext/desktop/example/hello
pocketone superuser upsert [email protected] password
pocketone serve                  # http://127.0.0.1:8090
pocketone desktop build          # dist/darwin-arm64/Hello.app on an Apple Silicon Mac
open dist/darwin-arm64/Hello.app

The server and the desktop app keep separate data: the server's in pb_data/, the desktop app's in your app-data folder.

Next

  • Building: targets, the build image, building with your own Go, and what lands in dist/.
  • How the app runs: where each user's data lives, upgrades, the window and what each platform needs.
  • Signing and sharing: signing and notarizing for macOS, signing for Windows, and checksums for Linux.
  • Extension reference: the desktop section of pocketone.yaml and building on the runtime from Go.

What's next

A desktop app has one person at the keyboard and data on their machine, so PocketBase's users and superusers don't quite fit. Being worked out:

  • Trust: requests from the app's own window run as its owner, and nothing else on the machine can reach the server.
  • Settings: a native Preferences window for the settings your app and its extensions declare, since the superuser dashboard isn't part of a shipped app.