Other System APIs
Additional platform-level APIs. Every snippet below is excerpted from a real
file CI compiles on every PR — see
docs/examples/system/snippets.ts for
the perry/system pieces and
docs/examples/ui/events/snippets.ts
for clipboard.
Open URL
Open a URL in the default browser or application:
openURL("https://example.com")
| Platform | Implementation |
|---|---|
| macOS | NSWorkspace.open |
| iOS | UIApplication.open |
| Android | Intent.ACTION_VIEW |
| Windows | ShellExecuteW |
| Linux | xdg-open |
| Web | window.open |
Dark Mode Detection
if (isDarkMode()) {
console.log("Dark mode is active")
}
| Platform | Detection |
|---|---|
| macOS | NSApp.effectiveAppearance |
| iOS | UITraitCollection |
| Android | Configuration.uiMode |
| Windows | Registry (AppsUseLightTheme) |
| Linux | GTK settings |
| Web | prefers-color-scheme media query |
Clipboard
Clipboard helpers live in perry/ui (not perry/system):
// Copy to clipboard
clipboardWrite("Hello, clipboard!")
// Read from clipboard
const text = clipboardRead()
log.set(`clipboard length: ${text.length}`)
Device Identity
console.log(`device idiom: ${getDeviceIdiom()}`)
console.log(`device model: ${getDeviceModel()}`)
getDeviceIdiom() returns the broad form factor ("phone", "pad", "mac",
"tv", …); getDeviceModel() returns the platform-specific model identifier
("iPhone15,2", "MacBookPro18,3", etc.).
Next Steps
- Overview — All system APIs
- UI Overview — Building UIs