mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
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>
This commit is contained in:
@@ -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')
|
||||
}
|
||||
});
|
||||
})();
|
||||
})
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user