Skip to content

Bundled Packages

Beyond the core framework, pushinbr/pam-desktop ships a set of libraries in their own namespaces. They are autoloaded with the package, so there is nothing else to require (QR codes additionally need bacon/bacon-qr-code). None of them starts work on its own: each registers tags or classes you call, and the ones that talk to the host use the same asynchronous modules as the rest of the framework. Register the ones that provide template tags in index.php, before App::run().

Namespace What it provides Registration
Pam\DesktopUi Select, Autocomplete, MultiSelect, DatePicker, Toast, Checkbox, Slider, Popover, Tooltip, SplitView, TreeView, CodeEditor DesktopUI::boot($cachePath)
Pam\Desktop\Charts Line, area, bar and donut charts, sparklines, progress rings Charts::register()
Pam\Desktop\Canvas Paths, gradients and text on a native canvas —
Pam\Desktop\Markdown Markdown rendered as native, selectable rich text Markdown::register()
Pam\Desktop\Code Syntax highlighting and language server clients —
Pam\Desktop\Auth OAuth 2.0 / OpenID Connect sign-in with PKCE —
Pam\DesktopSsh SSH sessions, SFTP, port forwarding, the Terminal element —
Pam\DesktopPrinting Text documents and receipts through the system print dialog —
Pam\Desktop\Qr Local QR codes drawn on the canvas Qr::register()
Pam\Desktop\Realtime Laravel Reverb private channels over native WebSockets —
Pam\Desktop\Sync\Durable A durable SQLite outbox and bounded dispatcher —
index.php
use Pam\Desktop\Charts\Charts;
use Pam\Desktop\Markdown\Markdown;
use Pam\DesktopUi\DesktopUI;
Markdown::register();
Charts::register();
DesktopUI::boot(__DIR__.'/.pam-desktop/desktop-ui');
App::components(__DIR__.'/src', __DIR__.'/.pam-desktop/components');
App::run(AppRouter::make());

Pam\DesktopUi is a set of controls written as PAM Desktop templates. They are ordinary components made of native views, so they follow the backend they run on. Controls you configure in PHP are created by the component that owns them and placed in its template with <Slot :content>.

Popups (a select’s list, autocomplete suggestions) are drawn in a portal above the screen. Wrap the screen in a SelectProvider and give the controls the same host:

src/Screens/Settings/SettingsScreen.pam.php
<?php
declare(strict_types=1);
namespace App\Screens\Settings;
use Pam\Desktop\Component;
use Pam\DesktopUi\Select;
use Pam\DesktopUi\SelectOption;
final class SettingsScreen extends Component
{
public string $host;
public Select $theme;
public function __construct()
{
$this->host = 'settings-'.spl_object_id($this);
$this->theme = new Select(
options: [new SelectOption('light', 'Light'), new SelectOption('dark', 'Dark')],
value: 'light',
changed: fn (int|string|null $value) => $this->apply($value),
host: $this->host,
placeholder: 'Choose a theme',
label: 'Theme',
);
}
private function apply(int|string|null $value): void
{
// …
}
}
?>
<template>
<SelectProvider :host="$host">
<Column class="form">
<Slot :content="$theme" />
</Column>
</SelectProvider>
</template>
Control Use
Select A closed list with optional filter and clear button.
Autocomplete, MultiSelect Text with asynchronous, paged suggestions; several values.
DatePicker Date, date and time, or range, in a modal calendar. DatePickerLocale::system() follows the app language.
Toast A stack of messages with severities. Toast::service()->success('Saved', 'The product was updated.') draws above everything, modals included.
Checkbox, Slider Accessible controls; a slider can report committed once the drag ends.
<Popover>, <Tooltip> Content anchored to a nativeRef, flipping to fit the window.
<SplitView> Two panes with a draggable, keyboard-accessible divider.
<TreeView> A virtualized tree with lazy branches, keyboard navigation and context menus.
<CodeEditor> Highlighting, several cursors, undo and VS Code keys, rendering only visible lines.
<SplitView :size="$sidebar" min="170" max="480" on:resize="resizeSidebar">
<Explorer />
<Editor />
</SplitView>

Default texts are localized in English, Portuguese and Spanish; see Localization.

Pam\Desktop\Charts draws charts as vector scenes painted by the native canvas: Cairo on GTK, Core Graphics on AppKit, Direct2D on Win32. Nothing is rasterized in PHP and no web view is involved.

use Pam\Desktop\Charts\{BarChart, LegendPosition, Series};
$this->sales = BarChart::make(width: 430, height: 300)
->series(Series::make('Units', [12, 18, 9, 22])->color('#6366F1'))
->labels(['Jan', 'Feb', 'Mar', 'Apr'])
->barRadius(8)
->grid(5)
->legend(LegendPosition::Bottom);
<Slot :content="$sales" />

LineChart, AreaChart and BarChart share series(), labels(), grid(), beginAtZero(), legend(), valueFormatter() and onSelect(). DonutChart, Sparkline and ProgressRing cover the rest. Value axes pick “nice” ticks the way Chart.js does.

Pam\Desktop\Canvas (Canvas, Path, CanvasView) draws filled and stroked paths, linear gradients and single lines of text, and reports pointer events. It is the library the charts and QR codes are built on. See Media & Web for the core Canvas element.

Pam\Desktop\Markdown renders Markdown as native elements: paragraphs and headings are selectable rich text with pressable links; lists, quotes, code blocks and tables are boxes.

use Pam\Desktop\Markdown\Markdown;
Markdown::render("**Deploy** is done, see [the log](https://ci.example.com/42).");
<Markdown :source="$message->body" theme="dark" />

Pam\Desktop\Code colors source code. PHP goes through PHP’s own tokenizer; JavaScript, TypeScript, JSON, CSS, HTML, SQL, Python, Rust, Go, YAML and more use token rules:

use Pam\Desktop\Code\Highlighter;
$language = Highlighter::language($path); // 'php', 'rust', … or null
$lines = Highlighter::lines($source, $language); // per line: list of [text, ARGB color]

lines() suits a virtualized list of Text runs; runs() feeds Markdown::render(highlight: …). The package also includes language server clients.

Pam\Desktop\Auth\OAuthClient signs users in with OAuth 2.0 and OpenID Connect the way native apps should (RFC 8252): the system browser opens the provider’s page, the provider redirects to your app’s URL scheme, and the code is exchanged with PKCE. Tokens are kept in the system keychain and refreshed before they expire.

use Pam\Desktop\Auth\OAuthClient;
use Pam\Desktop\Auth\Tokens;
$this->auth = new OAuthClient(
authorizeUrl: 'https://accounts.example.com/oauth/authorize',
tokenUrl: 'https://accounts.example.com/oauth/token',
clientId: 'desktop-app',
redirectUri: 'acme://oauth/callback',
scopes: ['openid', 'profile', 'email', 'offline_access'],
);
$this->auth->signIn(
fn (Tokens $tokens) => $this->user = $tokens->claims()['name'] ?? null,
fn (string $error) => $this->error = $error,
);

List the scheme in pam-desktop.json ("urlSchemes": ["acme"]). accessToken() returns a fresh token, signOut() deletes (and optionally revokes) the tokens. Claims from the id token are read but not verified: verify the token on your server before you trust them.

Pam\DesktopSsh keeps SSH sessions in the host: remote commands, SFTP with progress, local port forwarding and interactive shells. It runs on pure Rust crypto (no OpenSSL), on threads that exist only while a session is open.

use Pam\DesktopSsh\{ExecResult, HostKeyMismatch, Ssh, SshException, SshOptions, SshSession};
$this->session = Ssh::connect(
SshOptions::password('server.example.com', 'deploy', $password, expectedFingerprint: $this->knownFingerprint),
function (SshSession $session): void {
$this->knownFingerprint ??= $session->fingerprint(); // trust on first use
$session->exec('uptime', fn (ExecResult $result) => $this->uptime = trim($result->stdout));
},
fn (SshException $error) => $this->error = $error instanceof HostKeyMismatch
? 'The server key changed to '.$error->fingerprint
: $error->getMessage(),
owner: $this,
);

The <Terminal> element draws an xterm-256color terminal for a shell channel, fed natively without PHP, with keys, selection, scrollback and themes.

Pam\DesktopPrinting prints text documents and receipts through the system print dialog (GTK with Cairo and Pango, AppKit, or Windows GDI). No browser is involved:

use Pam\DesktopPrinting\Printing;
use Pam\DesktopPrinting\PrintResult;
use Pam\DesktopPrinting\Receipt;
$document = (new Receipt('Receipt 42'))
->text('Payment receipt', bold: true, size: 12)
->separator()
->pair('2x Notebook', '$ 19.90')
->pair('Total:', '$ 19.90', bold: true)
->document();
Printing::print($document,
fn (PrintResult $result) => $this->printed = true,
fn (Throwable $error) => $this->error = $error->getMessage(),
);

Verified on Linux with Print to File; not tested on a physical printer or on macOS and Windows.

Pam\Desktop\Qr encodes QR codes locally with BaconQrCode and draws them on the native canvas, with no remote service. Require the encoder, register the tag, and use it:

Terminal window
pam composer require bacon/bacon-qr-code
<QrCode :data="$paymentCode" size="256" />

Pam\Desktop\Realtime\ReverbSubscription::privateChannel() subscribes to a Laravel Reverb private channel over a native WebSocket, with an exact allowlist of events. It suspends itself while the application is in the background and resumes when it returns, and it is disposed with its owner component.

Pam\Desktop\Sync\Durable provides a durable SQLite outbox (SQLiteOutbox) and a bounded dispatcher (OutboxDispatcher). It creates no timer and keeps nothing running while the application is hidden: you call dispatch() when the app is visible and online, with an adapter that sends each operation and resolves it as applied, retry or rejected. Applied state and local projections commit atomically, and retries back off exponentially.