mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
🌱 发送通知
This commit is contained in:
@@ -80,6 +80,7 @@
|
||||
"@tauri-apps/plugin-fs": "^2.4.4",
|
||||
"@tauri-apps/plugin-http": "github:tauri-apps/tauri-plugin-http",
|
||||
"@tauri-apps/plugin-log": "^2.7.1",
|
||||
"@tauri-apps/plugin-notification": "^2.3.3",
|
||||
"@tauri-apps/plugin-opener": "^2.5.2",
|
||||
"@tauri-apps/plugin-os": "^2.3.2",
|
||||
"@tauri-apps/plugin-process": "^2.3.1",
|
||||
|
||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -38,6 +38,9 @@ importers:
|
||||
'@tauri-apps/plugin-log':
|
||||
specifier: ^2.7.1
|
||||
version: 2.7.1
|
||||
'@tauri-apps/plugin-notification':
|
||||
specifier: ^2.3.3
|
||||
version: 2.3.3
|
||||
'@tauri-apps/plugin-opener':
|
||||
specifier: ^2.5.2
|
||||
version: 2.5.2
|
||||
@@ -1413,6 +1416,9 @@ packages:
|
||||
'@tauri-apps/plugin-log@2.7.1':
|
||||
resolution: {integrity: sha512-jdb+o0wxQc8PjnLktgGpOs9Dh1YupaOGDXzO+Y8peA1UZ1ep3eXv4E1oiJ7nIQVN0XUFDDhnn3aBszl8ijhR+A==}
|
||||
|
||||
'@tauri-apps/plugin-notification@2.3.3':
|
||||
resolution: {integrity: sha512-Zw+ZH18RJb41G4NrfHgIuofJiymusqN+q8fGUIIV7vyCH+5sSn5coqRv/MWB9qETsUs97vmU045q7OyseCV3Qg==}
|
||||
|
||||
'@tauri-apps/plugin-opener@2.5.2':
|
||||
resolution: {integrity: sha512-ei/yRRoCklWHImwpCcDK3VhNXx+QXM9793aQ64YxpqVF0BDuuIlXhZgiAkc15wnPVav+IbkYhmDJIv5R326Mew==}
|
||||
|
||||
@@ -5426,6 +5432,10 @@ snapshots:
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.9.1
|
||||
|
||||
'@tauri-apps/plugin-notification@2.3.3':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.9.1
|
||||
|
||||
'@tauri-apps/plugin-opener@2.5.2':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.9.1
|
||||
|
||||
68
src-tauri/Cargo.lock
generated
68
src-tauri/Cargo.lock
generated
@@ -22,6 +22,7 @@ dependencies = [
|
||||
"tauri-plugin-fs",
|
||||
"tauri-plugin-http",
|
||||
"tauri-plugin-log",
|
||||
"tauri-plugin-notification",
|
||||
"tauri-plugin-opener",
|
||||
"tauri-plugin-os",
|
||||
"tauri-plugin-process",
|
||||
@@ -3150,6 +3151,18 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
|
||||
|
||||
[[package]]
|
||||
name = "mac-notification-sys"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65fd3f75411f4725061682ed91f131946e912859d0044d39c4ec0aac818d7621"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "markup5ever"
|
||||
version = "0.14.1"
|
||||
@@ -3362,6 +3375,20 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"
|
||||
|
||||
[[package]]
|
||||
name = "notify-rust"
|
||||
version = "4.11.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6442248665a5aa2514e794af3b39661a8e73033b1cc5e59899e1276117ee4400"
|
||||
dependencies = [
|
||||
"futures-lite",
|
||||
"log",
|
||||
"mac-notification-sys",
|
||||
"serde",
|
||||
"tauri-winrt-notification",
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.6"
|
||||
@@ -4126,7 +4153,7 @@ checksum = "740ebea15c5d1428f910cd1a5f52cebf8d25006245ed8ade92702f4943d91e07"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"indexmap 2.12.1",
|
||||
"quick-xml",
|
||||
"quick-xml 0.38.4",
|
||||
"serde",
|
||||
"time",
|
||||
]
|
||||
@@ -4380,6 +4407,15 @@ version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.37.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.38.4"
|
||||
@@ -6290,6 +6326,24 @@ dependencies = [
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-notification"
|
||||
version = "2.3.3"
|
||||
source = "git+ssh://git@github.com/tauri-apps/plugins-workspace.git?branch=v2#31415effdf5a9ced19934a681cb044a732174088"
|
||||
dependencies = [
|
||||
"log",
|
||||
"notify-rust",
|
||||
"rand 0.9.2",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"tauri",
|
||||
"tauri-plugin",
|
||||
"thiserror 2.0.17",
|
||||
"time",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-opener"
|
||||
version = "2.5.2"
|
||||
@@ -6490,6 +6544,18 @@ dependencies = [
|
||||
"toml 0.9.10+spec-1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-winrt-notification"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b1e66e07de489fe43a46678dd0b8df65e0c973909df1b60ba33874e297ba9b9"
|
||||
dependencies = [
|
||||
"quick-xml 0.37.5",
|
||||
"thiserror 2.0.17",
|
||||
"windows",
|
||||
"windows-version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.24.0"
|
||||
|
||||
@@ -80,6 +80,11 @@ features = ["unsafe-headers"]
|
||||
git = "ssh://git@github.com/tauri-apps/plugins-workspace.git"
|
||||
branch = "v2"
|
||||
|
||||
# notification 插件
|
||||
[dependencies.tauri-plugin-notification]
|
||||
git = "ssh://git@github.com/tauri-apps/plugins-workspace.git"
|
||||
branch = "v2"
|
||||
|
||||
# opener 插件
|
||||
[dependencies.tauri-plugin-opener]
|
||||
git = "ssh://git@github.com/tauri-apps/plugins-workspace.git"
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"http:allow-fetch",
|
||||
"log:default",
|
||||
"log:allow-log",
|
||||
"notification:default",
|
||||
"opener:default",
|
||||
"process:default",
|
||||
"process:allow-exit",
|
||||
|
||||
@@ -73,6 +73,7 @@ pub fn run() {
|
||||
}));
|
||||
builder
|
||||
.on_window_event(move |app, event| window_event_handler(app, event))
|
||||
.plugin(tauri_plugin_notification::init())
|
||||
.plugin(tauri_plugin_deep_link::init())
|
||||
.plugin(tauri_plugin_cli::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
|
||||
@@ -19,26 +19,22 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { onMounted, onUnmounted } from "vue";
|
||||
|
||||
let textScaleListener: UnlistenFn | null = null;
|
||||
onMounted(async () => {
|
||||
textScaleListener = await listen("text_scale_change", (payload) => {
|
||||
console.log(payload);
|
||||
});
|
||||
});
|
||||
onUnmounted(() => {
|
||||
if (textScaleListener !== null) {
|
||||
textScaleListener();
|
||||
textScaleListener = null;
|
||||
}
|
||||
});
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import {
|
||||
isPermissionGranted,
|
||||
requestPermission,
|
||||
sendNotification,
|
||||
} from "@tauri-apps/plugin-notification";
|
||||
|
||||
async function test() {
|
||||
const res = await invoke("read_text_scale");
|
||||
console.log(res);
|
||||
const check = await isPermissionGranted();
|
||||
console.log(check);
|
||||
if (!check) {
|
||||
showSnackbar.warn("没有通知权限");
|
||||
const permission = await requestPermission();
|
||||
console.log(permission);
|
||||
}
|
||||
sendNotification({ title: "New Message", body: "You have a new message" });
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
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