System Services
Modules are the services the host offers to PHP: storage, files, the network, databases, timers and system dialogs. They all share one contract: a call returns at once, blocking work runs on host threads, and the answer arrives later in a callback. This page explains that contract and covers the system services not described elsewhere. Storage and files, SQLite and the network have their own pages.
How module calls work
Section titled “How module calls work”use Pam\Desktop\Storage\Storage;
Storage::get('launches', function (?string $value): void { $this->launches = (int) $value + 1;});- A request gets exactly one answer: success with a payload, or failure with a message.
- Blocking work (disk, network, SQLite, the keychain) runs on host threads, never on the UI thread and never in PHP.
- The component renders again after the callback returns.
- After a hot reload, answers to requests of the previous worker are dropped.
Failures
Section titled “Failures”Each API reports failure in one of three ways, documented with each call:
| Style | On failure |
|---|---|
| Failure closure | An optional $failure (or $onError) argument receives the message or exception. Without it, the failure is thrown. |
| Thrown | A RuntimeException or NativeModuleException is thrown from the callback. |
| Quiet | The success callback receives null, false or an empty value. |
A thrown exception from a callback is reported like any uncaught error; in development the error overlay shows it. Pass failure closures for expected failures (no network, a missing file) to keep them out of the overlay.
Timers
Section titled “Timers”Pam\Desktop\System\Timers schedules callbacks. The host keeps the deadlines and PHP sleeps until one fires:
use Pam\Desktop\System\TimerHandle;use Pam\Desktop\System\Timers;
$tick = Timers::every(1000, fn (TimerHandle $timer) => $this->seconds++);Timers::timeout(3000, fn () => $this->toastVisible = false);$tick->cancel();timeout(), every() (at least 16 ms) and after() (cannot be cancelled) accept delays up to 86,400,000 ms. After each tick PHP arms the next one, so a repeating timer drifts by the time PHP takes per tick.
Device information
Section titled “Device information”use Pam\Desktop\System\DeviceInfo;
DeviceInfo::get(function (DeviceInfo $info): void { $this->device = sprintf('%s · %s · %s', $info->locale, $info->timeZone, $info->appVersion);});| Property | On desktop |
|---|---|
width, height, density |
The window’s content size and the display scale. |
appearance, appState |
Light or dark; Active, Inactive or Background. |
timeZone |
IANA id from TZ or the system; UTC when unknown. |
locale |
BCP 47 tag from LC_ALL, LC_NUMERIC or LANG; en-US when unknown. |
appVersion, buildNumber |
version and build of pam-desktop.json. |
Mobile-only properties (safeArea*, memoryClassMb, manufacturer…) are zero, false or empty.
Device status
Section titled “Device status”Pam\Desktop\System\DeviceStatus reports the battery, the network type and power saving, once or on change:
use Pam\Desktop\DeviceStatus as Status;use Pam\Desktop\NetworkType;use Pam\Desktop\System\DeviceStatus;
DeviceStatus::read(fn (Status $status) => $this->battery = $status->batteryLevel);
$this->watch = DeviceStatus::watch(function (Status $status): void { $this->offline = $status->networkType === NetworkType::None; $this->saving = $status->lowPowerMode;});
// In unmount():DeviceStatus::unwatch($this->watch);batteryLevel is 0 to 1, or -1 without a battery. networkType is None, Wifi, Cellular, Ethernet or Other. watch($callback, $intervalMs) samples every second by default (250 to 60,000 ms) on one polling thread that exits with the last unwatch(), and calls back only when something changed.
The Linux values come from /sys/class/power_supply, /sys/class/net and the ACPI platform profile. The macOS and Windows sources are written and type-checked but have not run on a real machine.
Links and deep links
Section titled “Links and deep links”Pam\Desktop\System\Linking opens URLs in the default application and reports the URL the application was launched with:
use Pam\Desktop\System\Linking;
Linking::open('https://example.com/help', failure: fn (string $message) => $this->error = $message);
Linking::initial(function (?string $url): void { if ($url !== null) { $this->route($url); }});
$this->linkListener = Linking::listen(fn (string $url) => $this->route($url));open() accepts https, http, mailto, tel and geo. initial() reports the launch URL once: the url argument of pam desktop run or dev, or PAM_DESKTOP_LAUNCH_URL. listen() receives every link that reaches the running application; links that arrive while no listener waits are kept (32 at most).
An application is opened by its own links when pam-desktop.json declares urlSchemes; the installers register them with the system. With singleInstance, a second launch hands its link to the running application and exits:
{ "applicationId": "com.example.notes", "urlSchemes": ["acme-notes"], "singleInstance": true}Try a launch link from a terminal; the url argument of run follows the project argument, and PAM_DESKTOP_LAUNCH_URL does the same without one:
PAM_DESKTOP_LAUNCH_URL=acme-notes://note/42 pam desktop runSee Distribution for how each system registers schemes.
Alerts
Section titled “Alerts”use Pam\Desktop\System\Alert;use Pam\Desktop\System\AlertButton;
Alert::choose( 'Save changes?', 'Your edits will be lost if you do not save them.', [AlertButton::cancel('Cancel'), AlertButton::destructive('Discard'), AlertButton::make('Save')], function (int $index): void { $this->answer = ['cancel', 'discard', 'save'][$index] ?? 'dismissed'; },);Alert::show($title, $message, $dismissed) shows a message with one button. choose() takes one to three buttons, at most one of them a cancel button, and reports Alert::DISMISSED (-1) when closed another way.
Toasts
Section titled “Toasts”Pam\Desktop\System\Toast shows a short message drawn by the host. One shows at a time; pressing it dismisses it:
use Pam\Desktop\System\Toast;use Pam\Desktop\System\ToastPosition;
Toast::show('Copied to the clipboard');Toast::success('Saved', 'Your changes are safe.');Toast::error('No connection', 'Trying again in 5 seconds.', ToastPosition::Bottom);For stacked toasts with severities, use the DesktopUI toast service.
Screen capture protection
Section titled “Screen capture protection”Pam\Desktop\System\Screen asks the system to keep the application’s windows out of screenshots and recordings, for screens that show secrets:
use Pam\Desktop\System\Screen;
Screen::secure(true, fn (bool $enforced) => $this->protected = $enforced);Screen::claim('payment-form');Screen::release('payment-form');A route can ask for protection while it is active with new ScreenOptions(secure: true). Linux does not enforce it (the callback receives false); macOS and Windows implement it but were not run on a real machine. Never rely on it as a security control.
Capabilities that are not on desktop
Section titled “Capabilities that are not on desktop”PAM Desktop shares its component syntax with PAM Native. Phone-only capabilities are not part of PAM Desktop: location, contacts, SMS, sensors, biometrics, push notifications, the camera, the media library and audio recording. Their class names still exist so shared code fails with a clear PluginException naming the class. Permission checks report “granted”, and haptics and vibration succeed without effect.