mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-24 17:20:51 +02:00
Run formatter on new plugins
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
|
||||
/**
|
||||
* Options to send a notification.
|
||||
@@ -33,15 +33,15 @@ import { invoke } from '@tauri-apps/api/tauri'
|
||||
*/
|
||||
interface Options {
|
||||
/** Notification title. */
|
||||
title: string
|
||||
title: string;
|
||||
/** Optional notification body. */
|
||||
body?: string
|
||||
body?: string;
|
||||
/** Optional notification icon. */
|
||||
icon?: string
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
/** Possible permission values. */
|
||||
type Permission = 'granted' | 'denied' | 'default'
|
||||
type Permission = "granted" | "denied" | "default";
|
||||
|
||||
/**
|
||||
* Checks if the permission to send notifications is granted.
|
||||
@@ -54,10 +54,10 @@ type Permission = 'granted' | 'denied' | 'default'
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function isPermissionGranted(): Promise<boolean> {
|
||||
if (window.Notification.permission !== 'default') {
|
||||
return Promise.resolve(window.Notification.permission === 'granted')
|
||||
if (window.Notification.permission !== "default") {
|
||||
return Promise.resolve(window.Notification.permission === "granted");
|
||||
}
|
||||
return invoke('plugin:notification|is_permission_granted')
|
||||
return invoke("plugin:notification|is_permission_granted");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ async function isPermissionGranted(): Promise<boolean> {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function requestPermission(): Promise<Permission> {
|
||||
return window.Notification.requestPermission()
|
||||
return window.Notification.requestPermission();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,15 +99,15 @@ async function requestPermission(): Promise<Permission> {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function sendNotification(options: Options | string): void {
|
||||
if (typeof options === 'string') {
|
||||
if (typeof options === "string") {
|
||||
// eslint-disable-next-line no-new
|
||||
new window.Notification(options)
|
||||
new window.Notification(options);
|
||||
} else {
|
||||
// eslint-disable-next-line no-new
|
||||
new window.Notification(options.title, options)
|
||||
new window.Notification(options.title, options);
|
||||
}
|
||||
}
|
||||
|
||||
export type { Options, Permission }
|
||||
export type { Options, Permission };
|
||||
|
||||
export { sendNotification, requestPermission, isPermissionGranted }
|
||||
export { sendNotification, requestPermission, isPermissionGranted };
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
(function () {
|
||||
let permissionSettable = false
|
||||
let permissionValue = 'default'
|
||||
let permissionSettable = false;
|
||||
let permissionValue = "default";
|
||||
|
||||
function isPermissionGranted() {
|
||||
if (window.Notification.permission !== 'default') {
|
||||
return Promise.resolve(window.Notification.permission === 'granted')
|
||||
if (window.Notification.permission !== "default") {
|
||||
return Promise.resolve(window.Notification.permission === "granted");
|
||||
}
|
||||
return __TAURI__.invoke('plugin:notification|is_permission_granted')
|
||||
return __TAURI__.invoke("plugin:notification|is_permission_granted");
|
||||
}
|
||||
|
||||
function setNotificationPermission(value) {
|
||||
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;
|
||||
}
|
||||
|
||||
function requestPermission() {
|
||||
return __TAURI__.invoke('plugin:notification|request_permission')
|
||||
return __TAURI__
|
||||
.invoke("plugin:notification|request_permission")
|
||||
.then(function (permission) {
|
||||
setNotificationPermission(permission)
|
||||
return permission
|
||||
})
|
||||
setNotificationPermission(permission);
|
||||
return permission;
|
||||
});
|
||||
}
|
||||
|
||||
function sendNotification(options) {
|
||||
if (typeof options === 'object') {
|
||||
Object.freeze(options)
|
||||
if (typeof options === "object") {
|
||||
Object.freeze(options);
|
||||
}
|
||||
|
||||
return __TAURI__.invoke('plugin:notification|notify', {
|
||||
options: typeof options === 'string'
|
||||
? {
|
||||
title: options
|
||||
}
|
||||
: options
|
||||
})
|
||||
return __TAURI__.invoke("plugin:notification|notify", {
|
||||
options:
|
||||
typeof options === "string"
|
||||
? {
|
||||
title: 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) {
|
||||
const opts = options || {}
|
||||
sendNotification(
|
||||
Object.assign(opts, { title })
|
||||
)
|
||||
}
|
||||
const opts = options || {};
|
||||
sendNotification(Object.assign(opts, { title }));
|
||||
};
|
||||
|
||||
window.Notification.requestPermission = requestPermission
|
||||
window.Notification.requestPermission = requestPermission;
|
||||
|
||||
Object.defineProperty(window.Notification, 'permission', {
|
||||
Object.defineProperty(window.Notification, "permission", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return permissionValue
|
||||
return permissionValue;
|
||||
},
|
||||
set: function (v) {
|
||||
if (!permissionSettable) {
|
||||
throw new Error('Readonly property')
|
||||
throw new Error("Readonly property");
|
||||
}
|
||||
permissionValue = v
|
||||
}
|
||||
})
|
||||
permissionValue = v;
|
||||
},
|
||||
});
|
||||
|
||||
isPermissionGranted().then(function (response) {
|
||||
if (response === null) {
|
||||
setNotificationPermission('default')
|
||||
setNotificationPermission("default");
|
||||
} else {
|
||||
setNotificationPermission(response ? 'granted' : 'denied')
|
||||
setNotificationPermission(response ? "granted" : "denied");
|
||||
}
|
||||
})
|
||||
})()
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user