chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)

* chore: adjust prettier config, .gitignore and use taplo to format toml files

This brings the plugins-workspace repository to the same code style of the main tauri repo

* format toml

* ignore examples gen dir

* add .vscode/extensions.json

* remove packageManager field

* fmt

* fix audit

* taplo ignore permissions autogenerated files

* remove create dummy dist

* fix prettier workflow

* install fmt in prettier workflow

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>

Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/10701104849

Co-authored-by: lucasfernog <lucasfernog@users.noreply.github.com>
This commit is contained in:
Amr Bashir
2024-09-04 11:55:26 +00:00
committed by tauri-bot
parent 2b6941789b
commit 27148fdcff
11 changed files with 237 additions and 238 deletions

1
.gitignore vendored
View File

@@ -1 +0,0 @@
/.tauri

View File

@@ -10,12 +10,12 @@ repository = { workspace = true }
links = "tauri-plugin-notification"
[package.metadata.docs.rs]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]
targets = ["x86_64-unknown-linux-gnu", "x86_64-linux-android"]
[build-dependencies]
tauri-plugin = { workspace = true, features = [ "build" ] }
tauri-plugin = { workspace = true, features = ["build"] }
[dependencies]
serde = { workspace = true }

View File

@@ -72,24 +72,27 @@ Then you need to add the permissions to your capabilities file:
}
```
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
```javascript
import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification';
import {
isPermissionGranted,
requestPermission,
sendNotification
} from '@tauri-apps/plugin-notification'
async function checkPermission() {
if (!(await isPermissionGranted())) {
return (await requestPermission()) === 'granted';
return (await requestPermission()) === 'granted'
}
return true;
return true
}
export async function enqueueNotification(title, body) {
if (!(await checkPermission())) {
return;
return
}
sendNotification({ title, body });
sendNotification({ title, body })
}
```

View File

@@ -20,4 +20,4 @@ We prefer to receive reports in English.
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).

View File

@@ -30,21 +30,21 @@ class Schedule {
return {
at: { date, repeating, allowWhileIdle },
interval: undefined,
every: undefined,
every: undefined
};
}
static interval(interval, allowWhileIdle = false) {
return {
at: undefined,
interval: { interval, allowWhileIdle },
every: undefined,
every: undefined
};
}
static every(kind, count, allowWhileIdle = false) {
return {
at: undefined,
interval: undefined,
every: { interval: kind, count, allowWhileIdle },
every: { interval: kind, count, allowWhileIdle }
};
}
}
@@ -73,10 +73,10 @@ exports.Visibility = void 0;
* @since 2.0.0
*/
async function isPermissionGranted() {
if (window.Notification.permission !== "default") {
return await Promise.resolve(window.Notification.permission === "granted");
if (window.Notification.permission !== 'default') {
return await Promise.resolve(window.Notification.permission === 'granted');
}
return await core.invoke("plugin:notification|is_permission_granted");
return await core.invoke('plugin:notification|is_permission_granted');
}
/**
* Requests the permission to send notifications.
@@ -116,7 +116,7 @@ async function requestPermission() {
* @since 2.0.0
*/
function sendNotification(options) {
if (typeof options === "string") {
if (typeof options === 'string') {
new window.Notification(options);
}
else {
@@ -143,7 +143,7 @@ function sendNotification(options) {
* @since 2.0.0
*/
async function registerActionTypes(types) {
await core.invoke("plugin:notification|register_action_types", { types });
await core.invoke('plugin:notification|register_action_types', { types });
}
/**
* Retrieves the list of pending notifications.
@@ -159,7 +159,7 @@ async function registerActionTypes(types) {
* @since 2.0.0
*/
async function pending() {
return await core.invoke("plugin:notification|get_pending");
return await core.invoke('plugin:notification|get_pending');
}
/**
* Cancels the pending notifications with the given list of identifiers.
@@ -175,7 +175,7 @@ async function pending() {
* @since 2.0.0
*/
async function cancel(notifications) {
await core.invoke("plugin:notification|cancel", { notifications });
await core.invoke('plugin:notification|cancel', { notifications });
}
/**
* Cancels all pending notifications.
@@ -191,7 +191,7 @@ async function cancel(notifications) {
* @since 2.0.0
*/
async function cancelAll() {
await core.invoke("plugin:notification|cancel");
await core.invoke('plugin:notification|cancel');
}
/**
* Retrieves the list of active notifications.
@@ -207,7 +207,7 @@ async function cancelAll() {
* @since 2.0.0
*/
async function active() {
return await core.invoke("plugin:notification|get_active");
return await core.invoke('plugin:notification|get_active');
}
/**
* Removes the active notifications with the given list of identifiers.
@@ -223,7 +223,7 @@ async function active() {
* @since 2.0.0
*/
async function removeActive(notifications) {
await core.invoke("plugin:notification|remove_active", { notifications });
await core.invoke('plugin:notification|remove_active', { notifications });
}
/**
* Removes all active notifications.
@@ -239,7 +239,7 @@ async function removeActive(notifications) {
* @since 2.0.0
*/
async function removeAllActive() {
await core.invoke("plugin:notification|remove_active");
await core.invoke('plugin:notification|remove_active');
}
/**
* Creates a notification channel.
@@ -262,7 +262,7 @@ async function removeAllActive() {
* @since 2.0.0
*/
async function createChannel(channel) {
await core.invoke("plugin:notification|create_channel", { ...channel });
await core.invoke('plugin:notification|create_channel', { ...channel });
}
/**
* Removes the channel with the given identifier.
@@ -278,7 +278,7 @@ async function createChannel(channel) {
* @since 2.0.0
*/
async function removeChannel(id) {
await core.invoke("plugin:notification|delete_channel", { id });
await core.invoke('plugin:notification|delete_channel', { id });
}
/**
* Retrieves the list of notification channels.
@@ -294,13 +294,13 @@ async function removeChannel(id) {
* @since 2.0.0
*/
async function channels() {
return await core.invoke("plugin:notification|listChannels");
return await core.invoke('plugin:notification|listChannels');
}
async function onNotificationReceived(cb) {
return await core.addPluginListener("notification", "notification", cb);
return await core.addPluginListener('notification', 'notification', cb);
}
async function onAction(cb) {
return await core.addPluginListener("notification", "actionPerformed", cb);
return await core.addPluginListener('notification', 'actionPerformed', cb);
}
exports.Schedule = Schedule;

8
dist-js/index.d.ts vendored
View File

@@ -4,8 +4,8 @@
*
* @module
*/
import { type PluginListener } from "@tauri-apps/api/core";
export type { PermissionState } from "@tauri-apps/api/core";
import { type PluginListener } from '@tauri-apps/api/core';
export type { PermissionState } from '@tauri-apps/api/core';
/**
* Options to send a notification.
*
@@ -452,5 +452,5 @@ declare function removeChannel(id: string): Promise<void>;
declare function channels(): Promise<Channel[]>;
declare function onNotificationReceived(cb: (notification: Options) => void): Promise<PluginListener>;
declare function onAction(cb: (notification: Options) => void): Promise<PluginListener>;
export type { Attachment, Options, Action, ActionType, PendingNotification, ActiveNotification, Channel, ScheduleInterval, };
export { Importance, Visibility, sendNotification, requestPermission, isPermissionGranted, registerActionTypes, pending, cancel, cancelAll, active, removeActive, removeAllActive, createChannel, removeChannel, channels, onNotificationReceived, onAction, Schedule, ScheduleEvery, };
export type { Attachment, Options, Action, ActionType, PendingNotification, ActiveNotification, Channel, ScheduleInterval };
export { Importance, Visibility, sendNotification, requestPermission, isPermissionGranted, registerActionTypes, pending, cancel, cancelAll, active, removeActive, removeAllActive, createChannel, removeChannel, channels, onNotificationReceived, onAction, Schedule, ScheduleEvery };

View File

@@ -28,21 +28,21 @@ class Schedule {
return {
at: { date, repeating, allowWhileIdle },
interval: undefined,
every: undefined,
every: undefined
};
}
static interval(interval, allowWhileIdle = false) {
return {
at: undefined,
interval: { interval, allowWhileIdle },
every: undefined,
every: undefined
};
}
static every(kind, count, allowWhileIdle = false) {
return {
at: undefined,
interval: undefined,
every: { interval: kind, count, allowWhileIdle },
every: { interval: kind, count, allowWhileIdle }
};
}
}
@@ -71,10 +71,10 @@ var Visibility;
* @since 2.0.0
*/
async function isPermissionGranted() {
if (window.Notification.permission !== "default") {
return await Promise.resolve(window.Notification.permission === "granted");
if (window.Notification.permission !== 'default') {
return await Promise.resolve(window.Notification.permission === 'granted');
}
return await invoke("plugin:notification|is_permission_granted");
return await invoke('plugin:notification|is_permission_granted');
}
/**
* Requests the permission to send notifications.
@@ -114,7 +114,7 @@ async function requestPermission() {
* @since 2.0.0
*/
function sendNotification(options) {
if (typeof options === "string") {
if (typeof options === 'string') {
new window.Notification(options);
}
else {
@@ -141,7 +141,7 @@ function sendNotification(options) {
* @since 2.0.0
*/
async function registerActionTypes(types) {
await invoke("plugin:notification|register_action_types", { types });
await invoke('plugin:notification|register_action_types', { types });
}
/**
* Retrieves the list of pending notifications.
@@ -157,7 +157,7 @@ async function registerActionTypes(types) {
* @since 2.0.0
*/
async function pending() {
return await invoke("plugin:notification|get_pending");
return await invoke('plugin:notification|get_pending');
}
/**
* Cancels the pending notifications with the given list of identifiers.
@@ -173,7 +173,7 @@ async function pending() {
* @since 2.0.0
*/
async function cancel(notifications) {
await invoke("plugin:notification|cancel", { notifications });
await invoke('plugin:notification|cancel', { notifications });
}
/**
* Cancels all pending notifications.
@@ -189,7 +189,7 @@ async function cancel(notifications) {
* @since 2.0.0
*/
async function cancelAll() {
await invoke("plugin:notification|cancel");
await invoke('plugin:notification|cancel');
}
/**
* Retrieves the list of active notifications.
@@ -205,7 +205,7 @@ async function cancelAll() {
* @since 2.0.0
*/
async function active() {
return await invoke("plugin:notification|get_active");
return await invoke('plugin:notification|get_active');
}
/**
* Removes the active notifications with the given list of identifiers.
@@ -221,7 +221,7 @@ async function active() {
* @since 2.0.0
*/
async function removeActive(notifications) {
await invoke("plugin:notification|remove_active", { notifications });
await invoke('plugin:notification|remove_active', { notifications });
}
/**
* Removes all active notifications.
@@ -237,7 +237,7 @@ async function removeActive(notifications) {
* @since 2.0.0
*/
async function removeAllActive() {
await invoke("plugin:notification|remove_active");
await invoke('plugin:notification|remove_active');
}
/**
* Creates a notification channel.
@@ -260,7 +260,7 @@ async function removeAllActive() {
* @since 2.0.0
*/
async function createChannel(channel) {
await invoke("plugin:notification|create_channel", { ...channel });
await invoke('plugin:notification|create_channel', { ...channel });
}
/**
* Removes the channel with the given identifier.
@@ -276,7 +276,7 @@ async function createChannel(channel) {
* @since 2.0.0
*/
async function removeChannel(id) {
await invoke("plugin:notification|delete_channel", { id });
await invoke('plugin:notification|delete_channel', { id });
}
/**
* Retrieves the list of notification channels.
@@ -292,13 +292,13 @@ async function removeChannel(id) {
* @since 2.0.0
*/
async function channels() {
return await invoke("plugin:notification|listChannels");
return await invoke('plugin:notification|listChannels');
}
async function onNotificationReceived(cb) {
return await addPluginListener("notification", "notification", cb);
return await addPluginListener('notification', 'notification', cb);
}
async function onAction(cb) {
return await addPluginListener("notification", "actionPerformed", cb);
return await addPluginListener('notification', 'actionPerformed', cb);
}
export { Importance, Schedule, ScheduleEvery, Visibility, active, cancel, cancelAll, channels, createChannel, isPermissionGranted, onAction, onNotificationReceived, pending, registerActionTypes, removeActive, removeAllActive, removeChannel, requestPermission, sendNotification };

View File

@@ -12,10 +12,10 @@
import {
invoke,
type PluginListener,
addPluginListener,
} from "@tauri-apps/api/core";
addPluginListener
} from '@tauri-apps/api/core'
export type { PermissionState } from "@tauri-apps/api/core";
export type { PermissionState } from '@tauri-apps/api/core'
/**
* Options to send a notification.
@@ -26,54 +26,54 @@ interface Options {
/**
* The notification identifier to reference this object later. Must be a 32-bit integer.
*/
id?: number;
id?: number
/**
* Identifier of the {@link Channel} that deliveres this notification.
*
* If the channel does not exist, the notification won't fire.
* Make sure the channel exists with {@link listChannels} and {@link createChannel}.
*/
channelId?: string;
channelId?: string
/**
* Notification title.
*/
title: string;
title: string
/**
* Optional notification body.
* */
body?: string;
body?: string
/**
* Schedule this notification to fire on a later time or a fixed interval.
*/
schedule?: Schedule;
schedule?: Schedule
/**
* Multiline text.
* Changes the notification style to big text.
* Cannot be used with `inboxLines`.
*/
largeBody?: string;
largeBody?: string
/**
* Detail text for the notification with `largeBody`, `inboxLines` or `groupSummary`.
*/
summary?: string;
summary?: string
/**
* Defines an action type for this notification.
*/
actionTypeId?: string;
actionTypeId?: string
/**
* Identifier used to group multiple notifications.
*
* https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/1649872-threadidentifier
*/
group?: string;
group?: string
/**
* Instructs the system that this notification is the summary of a group on Android.
*/
groupSummary?: boolean;
groupSummary?: boolean
/**
* The sound resource name. Only available on mobile.
*/
sound?: string;
sound?: string
/**
* List of lines to add to the notification.
* Changes the notification style to inbox.
@@ -81,31 +81,31 @@ interface Options {
*
* Only supports up to 5 lines.
*/
inboxLines?: string[];
inboxLines?: string[]
/**
* Notification icon.
*
* On Android the icon must be placed in the app's `res/drawable` folder.
*/
icon?: string;
icon?: string
/**
* Notification large icon (Android).
*
* The icon must be placed in the app's `res/drawable` folder.
*/
largeIcon?: string;
largeIcon?: string
/**
* Icon color on Android.
*/
iconColor?: string;
iconColor?: string
/**
* Notification attachments.
*/
attachments?: Attachment[];
attachments?: Attachment[]
/**
* Extra payload to store in the notification.
*/
extra?: Record<string, unknown>;
extra?: Record<string, unknown>
/**
* If true, the notification cannot be dismissed by the user on Android.
*
@@ -113,29 +113,29 @@ interface Options {
* It is typically used to indicate a background task that is pending (e.g. a file download)
* or the user is engaged with (e.g. playing music).
*/
ongoing?: boolean;
ongoing?: boolean
/**
* Automatically cancel the notification when the user clicks on it.
*/
autoCancel?: boolean;
autoCancel?: boolean
/**
* Changes the notification presentation to be silent on iOS (no badge, no sound, not listed).
*/
silent?: boolean;
silent?: boolean
/**
* Notification visibility.
*/
visibility?: Visibility;
visibility?: Visibility
/**
* Sets the number of items this notification represents on Android.
*/
number?: number;
number?: number
}
interface ScheduleInterval {
year?: number;
month?: number;
day?: number;
year?: number
month?: number
day?: number
/**
* 1 - Sunday
* 2 - Monday
@@ -145,79 +145,79 @@ interface ScheduleInterval {
* 6 - Friday
* 7 - Saturday
*/
weekday?: number;
hour?: number;
minute?: number;
second?: number;
weekday?: number
hour?: number
minute?: number
second?: number
}
enum ScheduleEvery {
Year = "year",
Month = "month",
TwoWeeks = "twoWeeks",
Week = "week",
Day = "day",
Hour = "hour",
Minute = "minute",
Year = 'year',
Month = 'month',
TwoWeeks = 'twoWeeks',
Week = 'week',
Day = 'day',
Hour = 'hour',
Minute = 'minute',
/**
* Not supported on iOS.
*/
Second = "second",
Second = 'second'
}
class Schedule {
at:
| {
date: Date;
repeating: boolean;
allowWhileIdle: boolean;
date: Date
repeating: boolean
allowWhileIdle: boolean
}
| undefined;
| undefined
interval:
| {
interval: ScheduleInterval;
allowWhileIdle: boolean;
interval: ScheduleInterval
allowWhileIdle: boolean
}
| undefined;
| undefined
every:
| {
interval: ScheduleEvery;
count: number;
allowWhileIdle: boolean;
interval: ScheduleEvery
count: number
allowWhileIdle: boolean
}
| undefined;
| undefined
static at(date: Date, repeating = false, allowWhileIdle = false): Schedule {
return {
at: { date, repeating, allowWhileIdle },
interval: undefined,
every: undefined,
};
every: undefined
}
}
static interval(
interval: ScheduleInterval,
allowWhileIdle = false,
allowWhileIdle = false
): Schedule {
return {
at: undefined,
interval: { interval, allowWhileIdle },
every: undefined,
};
every: undefined
}
}
static every(
kind: ScheduleEvery,
count: number,
allowWhileIdle = false,
allowWhileIdle = false
): Schedule {
return {
at: undefined,
interval: undefined,
every: { interval: kind, count, allowWhileIdle },
};
every: { interval: kind, count, allowWhileIdle }
}
}
}
@@ -226,58 +226,58 @@ class Schedule {
*/
interface Attachment {
/** Attachment identifier. */
id: string;
id: string
/** Attachment URL. Accepts the `asset` and `file` protocols. */
url: string;
url: string
}
interface Action {
id: string;
title: string;
requiresAuthentication?: boolean;
foreground?: boolean;
destructive?: boolean;
input?: boolean;
inputButtonTitle?: string;
inputPlaceholder?: string;
id: string
title: string
requiresAuthentication?: boolean
foreground?: boolean
destructive?: boolean
input?: boolean
inputButtonTitle?: string
inputPlaceholder?: string
}
interface ActionType {
/**
* The identifier of this action type
*/
id: string;
id: string
/**
* The list of associated actions
*/
actions: Action[];
hiddenPreviewsBodyPlaceholder?: string;
customDismissAction?: boolean;
allowInCarPlay?: boolean;
hiddenPreviewsShowTitle?: boolean;
hiddenPreviewsShowSubtitle?: boolean;
actions: Action[]
hiddenPreviewsBodyPlaceholder?: string
customDismissAction?: boolean
allowInCarPlay?: boolean
hiddenPreviewsShowTitle?: boolean
hiddenPreviewsShowSubtitle?: boolean
}
interface PendingNotification {
id: number;
title?: string;
body?: string;
schedule: Schedule;
id: number
title?: string
body?: string
schedule: Schedule
}
interface ActiveNotification {
id: number;
tag?: string;
title?: string;
body?: string;
group?: string;
groupSummary: boolean;
data: Record<string, string>;
extra: Record<string, unknown>;
attachments: Attachment[];
actionTypeId?: string;
schedule?: Schedule;
sound?: string;
id: number
tag?: string
title?: string
body?: string
group?: string
groupSummary: boolean
data: Record<string, string>
extra: Record<string, unknown>
attachments: Attachment[]
actionTypeId?: string
schedule?: Schedule
sound?: string
}
enum Importance {
@@ -285,25 +285,25 @@ enum Importance {
Min,
Low,
Default,
High,
High
}
enum Visibility {
Secret = -1,
Private,
Public,
Public
}
interface Channel {
id: string;
name: string;
description?: string;
sound?: string;
lights?: boolean;
lightColor?: string;
vibration?: boolean;
importance?: Importance;
visibility?: Visibility;
id: string
name: string
description?: string
sound?: string
lights?: boolean
lightColor?: string
vibration?: boolean
importance?: Importance
visibility?: Visibility
}
/**
@@ -317,10 +317,10 @@ interface Channel {
* @since 2.0.0
*/
async function isPermissionGranted(): Promise<boolean> {
if (window.Notification.permission !== "default") {
return await Promise.resolve(window.Notification.permission === "granted");
if (window.Notification.permission !== 'default') {
return await Promise.resolve(window.Notification.permission === 'granted')
}
return await invoke("plugin:notification|is_permission_granted");
return await invoke('plugin:notification|is_permission_granted')
}
/**
@@ -340,7 +340,7 @@ async function isPermissionGranted(): Promise<boolean> {
* @since 2.0.0
*/
async function requestPermission(): Promise<NotificationPermission> {
return await window.Notification.requestPermission();
return await window.Notification.requestPermission()
}
/**
@@ -362,10 +362,10 @@ async function requestPermission(): Promise<NotificationPermission> {
* @since 2.0.0
*/
function sendNotification(options: Options | string): void {
if (typeof options === "string") {
new window.Notification(options);
if (typeof options === 'string') {
new window.Notification(options)
} else {
new window.Notification(options.title, options);
new window.Notification(options.title, options)
}
}
@@ -389,7 +389,7 @@ function sendNotification(options: Options | string): void {
* @since 2.0.0
*/
async function registerActionTypes(types: ActionType[]): Promise<void> {
await invoke("plugin:notification|register_action_types", { types });
await invoke('plugin:notification|register_action_types', { types })
}
/**
@@ -406,7 +406,7 @@ async function registerActionTypes(types: ActionType[]): Promise<void> {
* @since 2.0.0
*/
async function pending(): Promise<PendingNotification[]> {
return await invoke("plugin:notification|get_pending");
return await invoke('plugin:notification|get_pending')
}
/**
@@ -423,7 +423,7 @@ async function pending(): Promise<PendingNotification[]> {
* @since 2.0.0
*/
async function cancel(notifications: number[]): Promise<void> {
await invoke("plugin:notification|cancel", { notifications });
await invoke('plugin:notification|cancel', { notifications })
}
/**
@@ -440,7 +440,7 @@ async function cancel(notifications: number[]): Promise<void> {
* @since 2.0.0
*/
async function cancelAll(): Promise<void> {
await invoke("plugin:notification|cancel");
await invoke('plugin:notification|cancel')
}
/**
@@ -457,7 +457,7 @@ async function cancelAll(): Promise<void> {
* @since 2.0.0
*/
async function active(): Promise<ActiveNotification[]> {
return await invoke("plugin:notification|get_active");
return await invoke('plugin:notification|get_active')
}
/**
@@ -474,9 +474,9 @@ async function active(): Promise<ActiveNotification[]> {
* @since 2.0.0
*/
async function removeActive(
notifications: Array<{ id: number; tag?: string }>,
notifications: Array<{ id: number; tag?: string }>
): Promise<void> {
await invoke("plugin:notification|remove_active", { notifications });
await invoke('plugin:notification|remove_active', { notifications })
}
/**
@@ -493,7 +493,7 @@ async function removeActive(
* @since 2.0.0
*/
async function removeAllActive(): Promise<void> {
await invoke("plugin:notification|remove_active");
await invoke('plugin:notification|remove_active')
}
/**
@@ -517,7 +517,7 @@ async function removeAllActive(): Promise<void> {
* @since 2.0.0
*/
async function createChannel(channel: Channel): Promise<void> {
await invoke("plugin:notification|create_channel", { ...channel });
await invoke('plugin:notification|create_channel', { ...channel })
}
/**
@@ -534,7 +534,7 @@ async function createChannel(channel: Channel): Promise<void> {
* @since 2.0.0
*/
async function removeChannel(id: string): Promise<void> {
await invoke("plugin:notification|delete_channel", { id });
await invoke('plugin:notification|delete_channel', { id })
}
/**
@@ -551,19 +551,19 @@ async function removeChannel(id: string): Promise<void> {
* @since 2.0.0
*/
async function channels(): Promise<Channel[]> {
return await invoke("plugin:notification|listChannels");
return await invoke('plugin:notification|listChannels')
}
async function onNotificationReceived(
cb: (notification: Options) => void,
cb: (notification: Options) => void
): Promise<PluginListener> {
return await addPluginListener("notification", "notification", cb);
return await addPluginListener('notification', 'notification', cb)
}
async function onAction(
cb: (notification: Options) => void,
cb: (notification: Options) => void
): Promise<PluginListener> {
return await addPluginListener("notification", "actionPerformed", cb);
return await addPluginListener('notification', 'actionPerformed', cb)
}
export type {
@@ -574,8 +574,8 @@ export type {
PendingNotification,
ActiveNotification,
Channel,
ScheduleInterval,
};
ScheduleInterval
}
export {
Importance,
@@ -596,5 +596,5 @@ export {
onNotificationReceived,
onAction,
Schedule,
ScheduleEvery,
};
ScheduleEvery
}

View File

@@ -2,92 +2,89 @@
// SPDX-License-Identifier: Apache-2.0
// 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 () {
let permissionSettable = false;
let permissionValue = "default";
import { invoke } from '@tauri-apps/api/core'
import type { PermissionState } from '@tauri-apps/api/core'
import type { Options } from './index'
;(function () {
let permissionSettable = false
let permissionValue = 'default'
async function isPermissionGranted(): Promise<boolean> {
// @ts-expect-error __TEMPLATE_windows__ will be replaced in rust before it's injected.
if (window.Notification.permission !== "default" || __TEMPLATE_windows__) {
return await Promise.resolve(
window.Notification.permission === "granted",
);
if (window.Notification.permission !== 'default' || __TEMPLATE_windows__) {
return await Promise.resolve(window.Notification.permission === 'granted')
}
return await invoke("plugin:notification|is_permission_granted");
return await invoke('plugin:notification|is_permission_granted')
}
function setNotificationPermission(value: NotificationPermission): void {
permissionSettable = true;
permissionSettable = true
// @ts-expect-error we can actually set this value on the webview
window.Notification.permission = value;
permissionSettable = false;
window.Notification.permission = value
permissionSettable = false
}
async function requestPermission(): Promise<PermissionState> {
return await invoke<PermissionState>(
"plugin:notification|request_permission",
'plugin:notification|request_permission'
).then((permission) => {
setNotificationPermission(
permission === "prompt" || permission === "prompt-with-rationale"
? "default"
: permission,
);
return permission;
});
permission === 'prompt' || permission === 'prompt-with-rationale'
? 'default'
: permission
)
return permission
})
}
async function sendNotification(options: string | Options): Promise<void> {
if (typeof options === "object") {
Object.freeze(options);
if (typeof options === 'object') {
Object.freeze(options)
}
await invoke("plugin:notification|notify", {
await invoke('plugin:notification|notify', {
options:
typeof options === "string"
typeof options === 'string'
? {
title: options,
title: options
}
: options,
});
: options
})
}
// @ts-expect-error unfortunately we can't implement the whole type, so we overwrite it with our own version
window.Notification = function (title, options) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const opts = options || {};
const opts = options || {}
void sendNotification(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Object.assign(opts, {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
title,
}),
);
};
title
})
)
}
// @ts-expect-error tauri does not have sync IPC :(
window.Notification.requestPermission = requestPermission;
window.Notification.requestPermission = requestPermission
Object.defineProperty(window.Notification, "permission", {
Object.defineProperty(window.Notification, 'permission', {
enumerable: true,
get: () => permissionValue,
set: (v) => {
if (!permissionSettable) {
throw new Error("Readonly property");
throw new Error('Readonly property')
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
permissionValue = v;
},
});
permissionValue = v
}
})
void isPermissionGranted().then(function (response) {
if (response === null) {
setNotificationPermission("default");
setNotificationPermission('default')
} else {
setNotificationPermission(response ? "granted" : "denied");
setNotificationPermission(response ? 'granted' : 'denied')
}
});
})();
})
})()

View File

@@ -26,5 +26,5 @@ permissions = [
"allow-list-channels",
"allow-delete-channel",
"allow-create-channel",
"allow-permission-state"
"allow-permission-state",
]

View File

@@ -2,21 +2,21 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { createConfig } from "../../shared/rollup.config.js";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
import { createConfig } from '../../shared/rollup.config.js'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import terser from '@rollup/plugin-terser'
export default createConfig({
additionalConfigs: {
input: "guest-js/init.ts",
input: 'guest-js/init.ts',
output: {
file: "src/init-iife.js",
format: "iife",
file: 'src/init-iife.js',
format: 'iife'
},
plugins: [typescript(), terser(), nodeResolve()],
onwarn: (warning) => {
throw Object.assign(new Error(), warning);
},
},
});
throw Object.assign(new Error(), warning)
}
}
})