Files
Sable/src/types/tauri-plugin-notifications-api.d.ts
T
Erwan Leboucher 753e87c96d fix(notifications): use native permission tri-state to sync background push toggle
The native plugin returns Option<bool> (true=granted, false=denied,
null=never-asked) but the JS bindings typed it as Promise<boolean>,
flattening the tri-state. Fix the types to Promise<boolean | null>,
add a non-prompting isUnifiedPushPermissionGranted, and pre-check
permission at startup: if denied, sync backgroundPushEnabled to false
and skip registration; if never-asked or granted, proceed (prompting
if needed). On registration failure, re-check and sync if now denied.
2026-07-20 14:36:24 +02:00

92 lines
2.8 KiB
TypeScript

declare module '@choochmeque/tauri-plugin-notifications-api' {
export type { PermissionState } from '@tauri-apps/api/core';
export const Importance: {
readonly None: 0;
readonly Min: 1;
readonly Low: 2;
readonly Default: 3;
readonly High: 4;
};
export type NotificationOptions = {
id?: number;
channelId?: string;
title: string;
body?: string;
schedule?: unknown;
largeBody?: string;
summary?: string;
actionTypeId?: string;
group?: string;
groupSummary?: boolean;
sound?: string;
inboxLines?: string[];
icon?: string;
largeIcon?: string;
iconColor?: string;
attachments?: unknown[];
extra?: Record<string, unknown>;
ongoing?: boolean;
autoCancel?: boolean;
silent?: boolean;
source?: string;
};
export type Channel = {
id: string;
name: string;
description?: string;
sound?: string;
lights?: boolean;
lightColor?: string;
vibration?: boolean;
importance?: (typeof Importance)[keyof typeof Importance];
visibility?: number;
};
export type ActiveNotification = {
id: number;
tag?: string;
title?: string;
body?: string;
extra?: Record<string, unknown>;
};
export type NotificationClickedData = {
id: number;
data?: Record<string, string>;
};
export type PluginListener = {
unregister: () => Promise<void> | void;
};
export function isPermissionGranted(): Promise<boolean | null>;
export function requestPermission(): Promise<NotificationPermission>;
export function sendNotification(options: NotificationOptions | string): Promise<void>;
export function registerForPushNotifications(): Promise<string>;
export function unregisterForPushNotifications(): Promise<void>;
export function listDistributors(): Promise<string[]>;
export function setDistributor(name: string): Promise<void>;
export function setToken(token: string): Promise<void>;
export function createChannel(channel: Channel): Promise<void>;
export function removeChannel(id: string): Promise<void>;
export function channels(): Promise<Channel[]>;
export function active(): Promise<ActiveNotification[]>;
export function removeActive(notifications: Array<{ id: number }>): Promise<void>;
export function removeAllActive(): Promise<void>;
export function pending(): Promise<unknown[]>;
export function cancel(notifications: number[]): Promise<void>;
export function cancelAll(): Promise<void>;
export function onNotificationReceived(
cb: (notification: NotificationOptions) => void
): Promise<PluginListener>;
export function onAction(
cb: (notification: NotificationOptions) => void
): Promise<PluginListener>;
export function onNotificationClicked(
cb: (data: NotificationClickedData) => void
): Promise<PluginListener>;
}