From 03548fc8a8c2df619b079dda3a73b4713b59860c Mon Sep 17 00:00:00 2001 From: kess Date: Sun, 11 Oct 2026 22:11:38 -0500 Subject: [PATCH 1/9] docs(camera): align README with implemented API - permissions namespace camera-kessdev:* (was camera:*) - iOS test command xcodebuild test (was swift test) - add openAppSettings to imports + usage - intro mentions introspection - beta version + Types section --- README.md | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e5e8270..dd1ad40 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ A [Tauri v2](https://v2.tauri.app) plugin that provides a **unified JavaScript API** for camera access across Android, iOS and desktop. It supports live preview, photo capture, -video recording (with audio), camera controls (front/back, flash, zoom), saving to the +video recording (with audio), camera controls (front/back, flash, zoom), camera +introspection (list the available cameras and query their capabilities), saving to the photo gallery, and camera permission management. | Platform | Supported | @@ -25,7 +26,7 @@ Add the Rust crate to `src-tauri/Cargo.toml`: ```toml [dependencies] -tauri-plugin-camera-kessdev = "0.1.0" +tauri-plugin-camera-kessdev = "0.2.0-beta.0" # beta # or from a git/path source: # tauri-plugin-camera-kessdev = { path = "../tauri-plugin-camera" } ``` @@ -61,15 +62,16 @@ Add the default permission set to `src-tauri/capabilities/default.json`: { "permissions": [ "core:default", - "camera:default" + "camera-kessdev:default" ] } ``` To allow only specific commands, use the granular permissions instead of -`camera:default` (e.g. `camera:allow-capture`, `camera:allow-start-recording`, -`camera:allow-check-permissions`, …). The full list is generated under -`permissions/autogenerated/commands/` as `allow-` / `deny-`. +`camera-kessdev:default` (e.g. `camera-kessdev:allow-capture`, +`camera-kessdev:allow-start-recording`, `camera-kessdev:allow-check-permissions`, …). +The full list is generated under `permissions/autogenerated/commands/` as +`allow-` / `deny-`. ### Android @@ -135,6 +137,7 @@ import { saveToGallery, checkPermissions, requestPermissions, + openAppSettings, getPreviewStream, convertFileSrc } from 'tauri-plugin-camera-kessdev' @@ -282,6 +285,9 @@ webm, 3gp, mkv are treated as video); pass `{ type }` to force it. ```ts const state = await checkPermissions() // 'granted' | 'denied' | 'prompt' await requestPermissions() + +// Mobile: open the OS settings screen (e.g. after a permanent denial). +await openAppSettings() ``` ## Image return pattern @@ -305,7 +311,7 @@ hardware, emulator or device is required. | Rust | `src/models.rs` (inline tests) | `cargo test` | plugin root | Rust + Cargo | | JS | `guest-js/index.test.ts` | `npm test` | plugin root | Node.js 18+ + npm | | Android | `android/src/test/java/CameraPluginTest.kt`| `gradle test` | `android/` (or generated app) | JDK 17+, Android SDK, Gradle | -| iOS | `ios/Tests/PluginTests/PluginTests.swift` | `swift test` | `ios/` | macOS + Xcode | +| iOS | `ios/Tests/PluginTests/PluginTests.swift` | `xcodebuild test` | iOS Simulator (generated app) | macOS + Xcode | ### Prerequisites @@ -428,3 +434,61 @@ destination from the generated Xcode project (`src-tauri/gen/apple`). | `requestPermissions()` | ✓ | ✓ | | `openAppSettings()` | ✓ | ✗ (throws) | | `getPreviewStream()` | `null` | `MediaStream` | + +## Types + +```ts +type CameraDirection = 'front' | 'back' +type FlashMode = 'on' | 'off' | 'auto' +type CameraFacing = 'front' | 'back' | 'external' +type CameraLens = 'wide' | 'ultraWide' | 'telephoto' | (string & {}) +type PermissionState = 'granted' | 'denied' | 'prompt' // re-exported from @tauri-apps/api/core + +interface StartPreviewOptions { camera?: CameraDirection; windowed?: boolean } +interface CaptureOptions { flash?: FlashMode } + +interface Photo { + path?: string // mobile: absolute path to the captured file + dataUrl?: string // desktop: base64 data URL + blob?: Blob // desktop + width: number + height: number + orientation: number // EXIF orientation + format: string + thumbnail?: string // base64 JPEG thumbnail (mobile; desktop reuses dataUrl) +} + +interface Video { + path?: string // mobile + duration: number + blob?: Blob // desktop + url?: string // desktop object URL + thumbnail?: string // base64 JPEG when requested via stopRecording({ thumbnail: true }) +} + +interface ZoomRange { min: number; max: number } + +interface CameraInfo { + id: string // native, session-stable identifier + facing?: CameraFacing + lens?: CameraLens + label?: string +} + +interface CameraCapabilities { + cameraId?: string + hasFlash: boolean + hasTorch: boolean + zoomRange?: ZoomRange + supportsFocus: boolean + focusModes?: string[] + photoFormats?: string[] + supportsPause: boolean +} + +interface RecordingProgress { duration: number; bytesRecorded?: number; bitrate?: number } + +interface StartRecordingOptions { onProgress?: Channel } +interface StopRecordingOptions { thumbnail?: boolean } +interface SaveToGalleryOptions { type?: 'image' | 'video' } +``` From 098e163e2151eb26a855d0f621c4ef4de87ca2ae Mon Sep 17 00:00:00 2001 From: kess Date: Sun, 11 Oct 2026 22:16:25 -0500 Subject: [PATCH 2/9] feat(camera): select a camera/lens by cameraId in startPreview - add startPreview({ cameraId }); precedence cameraId > camera > default - Android: CameraSelector filter by Camera2 cameraId (+ pure resolve helper) - iOS: AVCaptureDevice(uniqueID:) with resolve helper - desktop: getUserMedia deviceId constraint - invalid cameraId rejects with a descriptive error - README documents the option --- README.md | 4 ++ android/src/main/java/CameraMath.kt | 10 ++++ android/src/main/java/CameraPlugin.kt | 73 ++++++++++++++--------- android/src/test/java/CameraPluginTest.kt | 11 ++++ examples/tauri-app/src/App.svelte | 8 ++- guest-js/index.test.ts | 22 ++++++- guest-js/index.ts | 14 +++-- ios/Sources/CameraPlugin.swift | 39 ++++++++---- ios/Tests/PluginTests/PluginTests.swift | 6 ++ src/models.rs | 10 ++++ 10 files changed, 151 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index dd1ad40..065233a 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,10 @@ import { // windowed: true keeps the webview transparent so your UI renders over the camera. await startPreview({ camera: 'back', windowed: true }) +// Or pick a specific lens by id (from getAvailableCameras()); cameraId takes precedence. +const cameras = await getAvailableCameras() +await startPreview({ cameraId: cameras[0].id }) + // Desktop: attach the stream to a