mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-03 06:55:06 +08:00
🌱 发送通知
This commit is contained in:
33
src/utils/TGNotify.ts
Normal file
33
src/utils/TGNotify.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 系统通知简单封装
|
||||
* @since Beta v.0.9.1
|
||||
*/
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import {
|
||||
isPermissionGranted,
|
||||
requestPermission,
|
||||
sendNotification,
|
||||
} from "@tauri-apps/plugin-notification";
|
||||
|
||||
/**
|
||||
* 展示通知
|
||||
* @param title - 标题
|
||||
* @param text - 内容
|
||||
*/
|
||||
async function showNormalNotify(title: string, text: string): Promise<void> {
|
||||
const check = await isPermissionGranted();
|
||||
if (!check) {
|
||||
const permission = await requestPermission();
|
||||
if (permission !== "granted") {
|
||||
showSnackbar.warn("Notify permission is not allowed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendNotification({ title: title, body: text });
|
||||
}
|
||||
|
||||
const TGNotify = {
|
||||
normal: showNormalNotify,
|
||||
};
|
||||
|
||||
export default TGNotify;
|
||||
Reference in New Issue
Block a user