Electron

Electron apps combine desktop runtime needs with web-style UI patterns. FFDB works well here when you treat the app as local-first and explicitly model sync state in the interface.

Why Electron setup is different

  • Name
    Desktop process lifecycle
    Description

    Electron apps may run longer than browser tabs, so cleanup and reconnect behavior matter more.

  • Name
    Offline by default expectations
    Description

    Desktop users often expect full usability during poor connectivity.

  • Name
    Template choices
    Description

    FFDB CLI supports Electron starts with Vite + React or Vite + Vanilla TypeScript.

CLI setup flow

ffdb-cli init

Recommended prompt path:

  1. Platform: Electron
  2. Template: Vite + React or Vite + Vanilla TypeScript
  3. Optional offline support: better-sqlite3
  4. Optional Tailwind CSS
  5. Env setup: writes VITE_FFDB_API_URL and FFDB_AUTH_TOKEN

Core client setup

import { createClient } from 'ffdb-client'
import type { Database } from './ffdb.types'

const client = await createClient<Database>({
  config: {
    apiUrl: import.meta.env.VITE_FFDB_API_URL,
  },
})

const { db, auth, sync, destroy } = client

Desktop offline pattern

When you enable offline mode, wire a local adapter and show sync status in the UI:

const { sync } = await createClient<Database>({
  config: {
    apiUrl: import.meta.env.VITE_FFDB_API_URL,
  },
  storage: desktopStorageAdapter,
  offline: {
    adapter: localSqliteAdapter,
    syncOnReconnect: true,
    syncOnFocus: true,
    syncInterval: 30_000,
  },
})

if (sync) {
  const off = sync.subscribe(() => {
    console.log(sync.status)
  })

  await sync.run()
  off()
}

Practical guidance

  1. Treat offline support as a product decision, not just a technical option.
  2. Expose online/offline and pending mutation state in visible UI.
  3. Use explicit teardown (destroy) during app shutdown flows.
  4. Keep privileged credentials in trusted runtime boundaries only.

Next pages

  1. Reference: createClient
  2. Reference: React hooks
  3. Reference: errors

Was this page helpful?