UNPKG

@mirawision/chrome-api

Version:

A comprehensive TypeScript library for Chrome Extension API, providing type-safe wrappers and utilities for bookmarks, commands, context menus, cookies, downloads, storage, notifications, runtime, scripting, and side panel functionalities.

86 lines (85 loc) 3.5 kB
interface Button { title: string; iconUrl?: string; } interface Item { title: string; message: string; } interface NotificationOptions { type: 'basic' | 'image' | 'list' | 'progress'; title: string; message: string; iconUrl: string; buttons?: Button[]; priority?: number; eventTime?: number; imageUrl?: string; items?: Item[]; progress?: number; requireInteraction?: boolean; silent?: boolean; } type NotificationCallback = (notificationId: string) => void; type ButtonClickCallback = (notificationId: string, buttonIndex: number) => void; type PermissionLevel = 'granted' | 'denied' | 'default'; /** * A class that provides a type-safe wrapper around Chrome's notifications API. * This class allows you to create, update, and manage system notifications, * as well as handle user interactions with notifications. */ declare class Notifications { /** * Creates a new notification. * @param options - The notification options including type, title, message, etc. * @returns A promise that resolves to the notification ID * @throws {Error} If there's an error creating the notification */ static create(options: NotificationOptions): Promise<string>; /** * Updates an existing notification. * @param notificationId - The ID of the notification to update * @param options - The new notification options * @returns A promise that resolves to true if the notification was updated * @throws {Error} If there's an error updating the notification */ static update(notificationId: string, options: NotificationOptions): Promise<boolean>; /** * Clears an existing notification. * @param notificationId - The ID of the notification to clear * @returns A promise that resolves to true if the notification was cleared * @throws {Error} If there's an error clearing the notification */ static clear(notificationId: string): Promise<boolean>; /** * Retrieves all active notifications. * @returns A promise that resolves to an array of notification IDs * @throws {Error} If there's an error retrieving the notifications */ static getAll(): Promise<string[]>; /** * Gets the current permission level for notifications. * @returns A promise that resolves to the permission level * @throws {Error} If there's an error retrieving the permission level */ static getPermissionLevel(): Promise<PermissionLevel>; /** * Adds a listener for notification click events. * @param callback - Function called when a notification is clicked * @returns A function that removes the listener when called */ static addClickedListener(callback: NotificationCallback): () => void; /** * Adds a listener for notification button click events. * @param callback - Function called when a notification button is clicked * @returns A function that removes the listener when called */ static addButtonClickedListener(callback: ButtonClickCallback): () => void; /** * Adds a listener for notification close events. * @param callback - Function called when a notification is closed * @returns A function that removes the listener when called */ static addClosedListener(callback: NotificationCallback): () => void; } export { Notifications, NotificationOptions, NotificationCallback, ButtonClickCallback, PermissionLevel, Button, Item };