mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-20 21:20:42 +02:00
@@ -15,6 +15,8 @@ import {
|
||||
addPluginListener,
|
||||
} from "@tauri-apps/api/core";
|
||||
|
||||
export type { PermissionState } from "@tauri-apps/api/core";
|
||||
|
||||
/**
|
||||
* Options to send a notification.
|
||||
*
|
||||
@@ -304,9 +306,6 @@ interface Channel {
|
||||
visibility?: Visibility;
|
||||
}
|
||||
|
||||
/** Possible permission values. */
|
||||
type Permission = "granted" | "denied" | "default";
|
||||
|
||||
/**
|
||||
* Checks if the permission to send notifications is granted.
|
||||
* @example
|
||||
@@ -340,7 +339,7 @@ async function isPermissionGranted(): Promise<boolean> {
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function requestPermission(): Promise<Permission> {
|
||||
async function requestPermission(): Promise<NotificationPermission> {
|
||||
return await window.Notification.requestPermission();
|
||||
}
|
||||
|
||||
@@ -570,7 +569,6 @@ async function onAction(
|
||||
export type {
|
||||
Attachment,
|
||||
Options,
|
||||
Permission,
|
||||
Action,
|
||||
ActionType,
|
||||
PendingNotification,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { PermissionState } from "@tauri-apps/api/core";
|
||||
import type { Options } from "./index";
|
||||
|
||||
(function () {
|
||||
@@ -19,23 +20,21 @@ import type { Options } from "./index";
|
||||
return await invoke("plugin:notification|is_permission_granted");
|
||||
}
|
||||
|
||||
function setNotificationPermission(
|
||||
value: "granted" | "denied" | "default",
|
||||
): void {
|
||||
function setNotificationPermission(value: NotificationPermission): void {
|
||||
permissionSettable = true;
|
||||
// @ts-expect-error we can actually set this value on the webview
|
||||
window.Notification.permission = value;
|
||||
permissionSettable = false;
|
||||
}
|
||||
|
||||
async function requestPermission(): Promise<
|
||||
"default" | "denied" | "granted" | "prompt"
|
||||
> {
|
||||
return await invoke<"prompt" | "default" | "granted" | "denied">(
|
||||
async function requestPermission(): Promise<PermissionState> {
|
||||
return await invoke<PermissionState>(
|
||||
"plugin:notification|request_permission",
|
||||
).then((permission) => {
|
||||
setNotificationPermission(
|
||||
permission === "prompt" ? "default" : permission,
|
||||
permission === "prompt" || permission === "prompt-with-rationale"
|
||||
? "default"
|
||||
: permission,
|
||||
);
|
||||
return permission;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user