diff --git a/packages/js-api-generator/build.ts b/packages/js-api-generator/build.ts index c65928596..4fa261e42 100644 --- a/packages/js-api-generator/build.ts +++ b/packages/js-api-generator/build.ts @@ -68,7 +68,9 @@ async function generator() { 'deep-link', 'dialog', 'fs', + 'geolocation', 'global-shortcut', + 'haptics', 'http', 'log', 'nfc', diff --git a/src/content/docs/plugin/geolocation.mdx b/src/content/docs/plugin/geolocation.mdx new file mode 100644 index 000000000..8b5cfec86 --- /dev/null +++ b/src/content/docs/plugin/geolocation.mdx @@ -0,0 +1,172 @@ +--- +title: Geolocation +description: Get and track the device's current position, including information about altitude, heading, and speed (if available). +plugin: geolocation +i18nReady: true +--- + +import PluginLinks from '@components/PluginLinks.astro'; +import Compatibility from '@components/plugins/Compatibility.astro'; + +import { Tabs, TabItem, Steps } from '@astrojs/starlight/components'; +import CommandTabs from '@components/CommandTabs.astro'; +import PluginPermissions from '@components/PluginPermissions.astro'; + + + +Get and track the device's current position, including information about altitude, heading, and speed (if available). + +## Supported Platforms + + + +## Setup + +Install the geolocation plugin to get started. + + + + + Use your project's package manager to add the dependency: + + {' '} + + + + + + + + 1. Run the following command in the `src-tauri` folder to add the plugin to the project's dependencies in `Cargo.toml`: + + ```sh frame=none + cargo add tauri-plugin-geolocation --target 'cfg(any(target_os = "android", target_os = "ios"))' + ``` + + 2. Modify `lib.rs` to initialize the plugin: + + ```rust title="src-tauri/src/lib.rs" ins={5-6} + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + .setup(|app| { + #[cfg(mobile)] + app.handle().plugin(tauri_plugin_geolocation::init()); + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + 3. Install the JavaScript Guest bindings using your preferred JavaScript package manager: + + + + + + + + +## Configuration + +### iOS + +Apple requires privacy descriptions to be specified in Info.plist for location information, where you should describe why your app needs to access it. Illustrated below is an example description: + +```xml {6-7} + + + + + NSLocationWhenInUseDescription + Required to do XY + + +``` + +### Android + +This plugin automatically adds the following permissions to your `AndroidManifest.xml` file: + +```xml + + +``` + +If your app requires GPS functionality to function, you should add the following to your `AndroidManifest.xml` file: + +```xml + +``` + +The Google Play Store uses this property to decide whether it should show the app to devices without GPS capabilities. + +## Usage + +The geolocation plugin is available in JavaScript. + +```javascript +import { + checkPermissions, + requestPermissions, + getCurrentPosition, + watchPosition, +} from '@tauri-apps/plugin-geolocation'; + +let permissions = await checkPermissions(); +if ( + permissions.location === 'prompt' || + permissions.location === 'prompt-with-rationale' +) { + permissions = await requestPermissions(['location']); +} + +if (permissions.location === 'granted') { + const pos = await getCurrentPosition(); + + await watchPosition( + { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 }, + (pos) => { + console.log(pos); + } + ); +} +``` + +## Permissions + +By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your `capabilities` configuration to enable these. + +See the [Capabilities Overview](/security/capabilities/) for more information and the [step by step guide](/learn/security/using-plugin-permissions/) to use plugin permissions. + +```json title="src-tauri/capabilities/mobile.json" ins={7-11} +{ + "$schema": "../gen/schemas/mobile-schema.json", + "identifier": "mobile-capability", + "windows": ["main"], + "platforms": ["iOS", "android"], + "permissions": [ + "core:default", + "geolocation:allow-check-permissions", + "geolocation:allow-request-permissions", + "geolocation:allow-get-current-position", + "geolocation:allow-watch-position" + ] +} +``` + + diff --git a/src/content/docs/plugin/haptics.mdx b/src/content/docs/plugin/haptics.mdx new file mode 100644 index 000000000..5c2cb5a95 --- /dev/null +++ b/src/content/docs/plugin/haptics.mdx @@ -0,0 +1,125 @@ +--- +title: Haptics +description: Haptic feedback and vibrations on Android and iOS +plugin: haptics +i18nReady: true +--- + +import PluginLinks from '@components/PluginLinks.astro'; +import Compatibility from '@components/plugins/Compatibility.astro'; + +import { Tabs, TabItem, Steps } from '@astrojs/starlight/components'; +import CommandTabs from '@components/CommandTabs.astro'; +import PluginPermissions from '@components/PluginPermissions.astro'; + + + +Haptic feedback and vibrations on Android and iOS. + +There are no standards/requirements for vibration support on Android, so the feedback APIs may not work correctly on more affordable phones, including recently released ones. + +## Supported Platforms + + + +## Setup + +Install the haptics plugin to get started. + + + + + Use your project's package manager to add the dependency: + + {' '} + + + + + + + + 1. Run the following command in the `src-tauri` folder to add the plugin to the project's dependencies in `Cargo.toml`: + + ```sh frame=none + cargo add tauri-plugin-haptics --target 'cfg(any(target_os = "android", target_os = "ios"))' + ``` + + 2. Modify `lib.rs` to initialize the plugin: + + ```rust title="src-tauri/src/lib.rs" ins={5-6} + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + .setup(|app| { + #[cfg(mobile)] + app.handle().plugin(tauri_plugin_haptics::init()); + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + 3. Install the JavaScript Guest bindings using your preferred JavaScript package manager: + + + + + + + + +## Usage + +The haptics plugin is available in JavaScript. + +```javascript +import { + vibrate, + impactFeedback, + notificationFeedback, + selectionFeedback, +} from '@tauri-apps/plugin-haptics'; + +await vibrate(1); +await impactFeedback('medium'); +await notificationFeedback('warning'); +await selectionFeedback(); +``` + +## Permissions + +By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your `capabilities` configuration to enable these. + +See the [Capabilities Overview](/security/capabilities/) for more information and the [step by step guide](/learn/security/using-plugin-permissions/) to use plugin permissions. + +```json title="src-tauri/capabilities/mobile.json" ins={7-10} +{ + "$schema": "../gen/schemas/mobile-schema.json", + "identifier": "mobile-capability", + "windows": ["main"], + "platforms": ["iOS", "android"], + "permissions": [ + "haptics:allow-impact-feedback", + "haptics:allow-notification-feedback", + "haptics:allow-selection-feedback", + "haptics:allow-vibrate" + ] +} +``` + + diff --git a/src/content/docs/plugin/websocket.mdx b/src/content/docs/plugin/websocket.mdx index c02649c22..d29a99a8c 100644 --- a/src/content/docs/plugin/websocket.mdx +++ b/src/content/docs/plugin/websocket.mdx @@ -87,12 +87,15 @@ import WebSocket from '@tauri-apps/plugin-websocket'; const ws = await WebSocket.connect('ws://127.0.0.1:8080'); -ws.addListener((msg) => { +const removeListener = ws.addListener((msg) => { console.log('Received Message:', msg); }); await ws.send('Hello World!'); +// optionally remove the listener +removeListener(); + await ws.disconnect(); ```