Skip to content

Commit e2e97db

Browse files
authored
feat: use PermissionState type from tauri, closes #979 (#1701)
1 parent 9ea9e05 commit e2e97db

File tree

17 files changed

+55
-89
lines changed

17 files changed

+55
-89
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"barcode-scanner": patch
3+
"barcode-scanner-js": patch
4+
"geolocation": patch
5+
"geolocation-js": patch
6+
"notification": patch
7+
"notification-js": patch
8+
---
9+
10+
Use `PermissionState` from the `tauri` crate, which now also includes a "prompt with rationale" variant for Android (returned when your app must explain to the user why it needs the permission).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"notification-js": patch
3+
---
4+
5+
**Breaking change**: The permission type when using the API is now `'granted' | 'denied' | 'prompt' | 'prompt-with-rationale'` instead of `'granted' | 'denied' | 'default'` for consistency with Rust types. When using the `window.Notification` API the type is unchanged to match the Web API type.

.changes/tauri-rc-7.md renamed to .changes/tauri-rc-8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@
5858
"geolocation-js": patch
5959
---
6060

61-
Update to tauri 2.0.0-rc.7
61+
Update to tauri 2.0.0-rc.8

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ resolver = "2"
1111
[workspace.dependencies]
1212
serde = { version = "1", features = ["derive"] }
1313
log = "0.4"
14-
tauri = { version = "2.0.0-rc.7", default-features = false }
14+
tauri = { version = "2.0.0-rc.8", default-features = false }
1515
tauri-build = "2.0.0-rc.7"
1616
tauri-plugin = "2.0.0-rc.7"
1717
tauri-utils = "2.0.0-rc.7"

plugins/barcode-scanner/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ serde_json = { workspace = true }
2323
tauri = { workspace = true }
2424
log = { workspace = true }
2525
thiserror = { workspace = true }
26+
27+
[target.'cfg(target_os = "ios")'.dependencies]
28+
tauri = { workspace = true, features = ["wry"] }

plugins/barcode-scanner/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/barcode-scanner/guest-js/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
import { invoke } from "@tauri-apps/api/core";
5+
import {
6+
invoke,
7+
requestPermissions as checkPermissions_,
8+
checkPermissions as requestPermissions_,
9+
} from "@tauri-apps/api/core";
610

7-
export type PermissionState = "granted" | "denied" | "prompt";
11+
export type { PermissionState } from "@tauri-apps/api/core";
812

913
export enum Format {
1014
QRCode = "QR_CODE",
@@ -53,17 +57,17 @@ export async function cancel(): Promise<void> {
5357
* Get permission state.
5458
*/
5559
export async function checkPermissions(): Promise<PermissionState> {
56-
return await invoke<{ camera: PermissionState }>(
57-
"plugin:barcode-scanner|check_permissions",
60+
return await checkPermissions_<{ camera: PermissionState }>(
61+
"barcode-scanner",
5862
).then((r) => r.camera);
5963
}
6064

6165
/**
6266
* Request permissions to use the camera.
6367
*/
6468
export async function requestPermissions(): Promise<PermissionState> {
65-
return await invoke<{ camera: PermissionState }>(
66-
"plugin:barcode-scanner|request_permissions",
69+
return await requestPermissions_<{ camera: PermissionState }>(
70+
"barcode-scanner",
6771
).then((r) => r.camera);
6872
}
6973

plugins/geolocation/src/models.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use serde::{Deserialize, Serialize};
66
use specta::Type;
7+
use tauri::plugin::PermissionState;
78

89
#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
910
#[serde(rename_all = "camelCase")]
@@ -24,19 +25,6 @@ pub struct PermissionStatus {
2425
pub coarse_location: PermissionState,
2526
}
2627

27-
/// Permission state.
28-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, Type)]
29-
#[serde(rename_all = "camelCase")]
30-
pub enum PermissionState {
31-
/// Permission access has been granted.
32-
Granted,
33-
/// Permission access has been denied.
34-
Denied,
35-
/// The end user should be prompted for permission.
36-
#[default]
37-
Prompt,
38-
}
39-
4028
#[derive(Debug, Clone, Default, Serialize, Deserialize, Type)]
4129
#[serde(rename_all = "camelCase")]
4230
pub struct PositionOptions {

plugins/notification/guest-js/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
addPluginListener,
1616
} from "@tauri-apps/api/core";
1717

18+
export type { PermissionState } from "@tauri-apps/api/core";
19+
1820
/**
1921
* Options to send a notification.
2022
*
@@ -304,9 +306,6 @@ interface Channel {
304306
visibility?: Visibility;
305307
}
306308

307-
/** Possible permission values. */
308-
type Permission = "granted" | "denied" | "default";
309-
310309
/**
311310
* Checks if the permission to send notifications is granted.
312311
* @example
@@ -340,7 +339,7 @@ async function isPermissionGranted(): Promise<boolean> {
340339
*
341340
* @since 2.0.0
342341
*/
343-
async function requestPermission(): Promise<Permission> {
342+
async function requestPermission(): Promise<NotificationPermission> {
344343
return await window.Notification.requestPermission();
345344
}
346345

@@ -570,7 +569,6 @@ async function onAction(
570569
export type {
571570
Attachment,
572571
Options,
573-
Permission,
574572
Action,
575573
ActionType,
576574
PendingNotification,

0 commit comments

Comments
 (0)