Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

System APIs Overview

The perry/system module provides access to platform-native system features: preferences, secure storage, notifications, dark-mode detection, audio capture, and app introspection. Every snippet below is excerpted from docs/examples/system/snippets.ts — CI links the file on every PR.

// import {
//     openURL, isDarkMode,
//     preferencesGet, preferencesSet,
//     keychainSave, keychainGet, keychainDelete,
//     notificationSend,
//     audioStart, audioStop, audioGetLevel, audioGetPeak, audioGetWaveform,
// } from "perry/system"

Available APIs

FunctionDescriptionPlatforms
openURL(url)Open URL in default browser/appAll
isDarkMode()Check system dark modeAll
getDeviceIdiom()"phone", "pad", "mac", "tv", …All
getDeviceModel()Device model identifier (e.g. "iPhone13,4")All
preferencesSet(key, value)Store a preference (string or number)All
preferencesGet(key)Read a preference (returns `stringnumber
keychainSave(key, value)Secure storage writeAll
keychainGet(key)Secure storage readAll
keychainDelete(key)Secure storage removeAll
notificationSend(title, body)Local notificationAll
notificationCancel(id)Cancel a scheduled notificationApple
notificationOnTap(cb)Handle banner tapsApple
notificationRegisterRemote(cb) / notificationOnReceive(cb)Push (APNs)iOS, macOS
audioStart() / audioStop()Microphone captureAll
audioGetLevel() / audioGetPeak()RMS / peak amplitude (0..1)All
audioGetWaveform(n)Recent waveform samples for visualizationAll
audioSetOutputFilename(p) / audioStartRecording() / audioStopRecording()Capture mic to a WAV fileAll native
geolocationGetCurrent(ok, err)One-shot device positioniOS, Android, macOS
geolocationWatch(cb) / geolocationStopWatch(id)Subscribe to position updatesiOS, Android, macOS
geolocationRequestPermission(cb)Request location permissioniOS, Android, macOS
imagePickerPick(max, multi, cb)Native photo-library pickeriOS, Android, macOS
registerTask(id, fn) / schedule(id, …) / cancel(id)Deferred / periodic background work — see perry/backgroundiOS, Android, tvOS, visionOS, watchOS, macOS

Clipboard lives in perry/ui (not perry/system): import clipboardRead and clipboardWrite from there.

Quick Example

if (isDarkMode()) {
    console.log("Dark mode is active")
}
// Strings and numbers round-trip natively — no manual stringification needed.
preferencesSet("theme", "dark")
preferencesSet("font-size", 14)

const theme = preferencesGet("theme")        // string | number | undefined
const fontSize = preferencesGet("font-size") // → 14 (number)

if (typeof theme === "string") {
    console.log(`saved theme: ${theme}`)
}
if (typeof fontSize === "number") {
    console.log(`saved font-size: ${fontSize}`)
}
openURL("https://example.com")

Next Steps