From 6c66b1cd7dde1868ab51ce46b02cc20922e9a08b Mon Sep 17 00:00:00 2001 From: eiiko6 Date: Thu, 22 Jan 2026 09:21:54 +0100 Subject: [PATCH] added notifications --- package.json | 1 + src-tauri/Cargo.lock | 69 ++++++++++++++++++++++++++++- src-tauri/Cargo.toml | 1 + src-tauri/capabilities/default.json | 3 +- src-tauri/src/lib.rs | 1 + src/components/ChatWindow.vue | 12 ++++- src/locales/en.ftl | 3 ++ src/locales/fr.ftl | 3 ++ src/main.ts | 26 +++++++++-- yarn.lock | 7 +++ 10 files changed, 118 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index e2f3bc0..e7274ff 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@tauri-apps/plugin-dialog": "~2", "@tauri-apps/plugin-fs": "~2", "@tauri-apps/plugin-http": "~2", + "@tauri-apps/plugin-notification": "~2", "@tauri-apps/plugin-opener": "^2", "@tauri-apps/plugin-os": "~2", "@tauri-apps/plugin-store": "~2", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index b9b59dd..9752ef0 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1027,6 +1027,7 @@ dependencies = [ "tauri-plugin-dialog", "tauri-plugin-fs", "tauri-plugin-http", + "tauri-plugin-notification", "tauri-plugin-opener", "tauri-plugin-os", "tauri-plugin-store", @@ -2053,6 +2054,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" @@ -2202,6 +2215,20 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[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-conv" version = "0.1.0" @@ -2767,7 +2794,7 @@ checksum = "740ebea15c5d1428f910cd1a5f52cebf8d25006245ed8ade92702f4943d91e07" dependencies = [ "base64 0.22.1", "indexmap 2.12.1", - "quick-xml", + "quick-xml 0.38.4", "serde", "time", ] @@ -2913,6 +2940,15 @@ dependencies = [ "psl-types", ] +[[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" @@ -4134,6 +4170,25 @@ dependencies = [ "urlpattern", ] +[[package]] +name = "tauri-plugin-notification" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01fc2c5ff41105bd1f7242d8201fdf3efd70749b82fa013a17f2126357d194cc" +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" @@ -4329,6 +4384,18 @@ dependencies = [ "toml 0.9.8", ] +[[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.23.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 1720d65..f847f6e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -29,4 +29,5 @@ tauri-plugin-upload = "2" tauri-plugin-dialog = "2" tauri-plugin-fs = "2" tauri-plugin-os = "2" +tauri-plugin-notification = "2" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 628361f..cb0eae5 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -54,6 +54,7 @@ "*" ] }, - "os:default" + "os:default", + "notification:default" ] } \ No newline at end of file diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a46662f..4edcbc6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -7,6 +7,7 @@ fn greet(name: &str) -> String { #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() + .plugin(tauri_plugin_notification::init()) .plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_dialog::init()) diff --git a/src/components/ChatWindow.vue b/src/components/ChatWindow.vue index 8cbac44..2ea5720 100644 --- a/src/components/ChatWindow.vue +++ b/src/components/ChatWindow.vue @@ -3,8 +3,9 @@ @close="showInviteModal = false" @room-changed="handleRoomChanged" /> + :roomName="currentRoom?.name || 'Unknown room'" :isGlobal="currentRoom?.global || false" + :ownerUuid="currentRoom?.owner_uuid || ''" @close="showDetailsModal = false" + @room-changed="handleRoomChanged" />
@@ -66,6 +67,7 @@ import WebSocket from '@tauri-apps/plugin-websocket'; import { getAuthData } from "../store.ts"; import { fetchRoomInfo } from "../api/rooms.ts"; import { useFluent } from 'fluent-vue'; +import { sendNotification } from '@tauri-apps/plugin-notification'; const { $t } = useFluent(); @@ -194,6 +196,12 @@ async function connectGlobalWebSocket() { } else { // Notifications for other rooms emit('notification', data.room_uuid); + + sendNotification({ + title: $t('notifications-message-title', { messageType: data.message_type, senderUsername: data.sender }), + body: data.content, + // channelId: 'messages', + }); } } catch (e) { diff --git a/src/locales/en.ftl b/src/locales/en.ftl index 7d4e071..31bfffe 100644 --- a/src/locales/en.ftl +++ b/src/locales/en.ftl @@ -123,3 +123,6 @@ shared-updating = Updating shared-delete = Delete shared-leave = Leave shared-confirm = Confirm + +## Notifications +notifications-message-title = New {$messageType} message from {$senderUsername} diff --git a/src/locales/fr.ftl b/src/locales/fr.ftl index 01045ec..af7f8ae 100644 --- a/src/locales/fr.ftl +++ b/src/locales/fr.ftl @@ -121,3 +121,6 @@ shared-updating = Mise à jour... shared-delete = Supprimer shared-leave = Quitter shared-confirm = Confirmer + +## Notifications +notifications-message-title = Nouveau message {$messageType} de {$senderUsername} diff --git a/src/main.ts b/src/main.ts index bfcdfec..a4ae5f4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,12 @@ import router from './router.ts' import App from './App.vue' import { validateToken, initTheme } from './store.ts' import { fluent, setLanguage } from './i18n' +// import { +// createChannel, +// Importance, +// Visibility, +// } from '@tauri-apps/plugin-notification'; + import './base.css' import { getLocalePreference } from './store.ts' @@ -25,14 +31,26 @@ async function init() { setLanguage(osLocale); } + // await createChannel({ + // id: 'messages', + // name: 'Messages', + // description: 'Notifications for new messages', + // importance: Importance.High, + // visibility: Visibility.Private, + // lights: true, + // lightColor: '#ff0000', + // vibration: true, + // sound: 'notification_sound', + // }); + app.mount('#app') } init() -// export const API = 'http://127.0.0.1:8080' +export const API = 'http://127.0.0.1:8080' // export const API = 'http://192.168.1.183:8080' -export const API = 'https://alatreon.org/frangipane' -// export const API_WS = 'ws://127.0.0.1:8080/ws' +// export const API = 'https://alatreon.org/frangipane' +export const API_WS = 'ws://127.0.0.1:8080/ws' // export const API_WS = 'ws://192.168.1.183:8080/ws' -export const API_WS = 'wss://alatreon.org/frangipane/ws' +// export const API_WS = 'wss://alatreon.org/frangipane/ws' diff --git a/yarn.lock b/yarn.lock index b1de062..5b11525 100644 --- a/yarn.lock +++ b/yarn.lock @@ -423,6 +423,13 @@ dependencies: "@tauri-apps/api" "^2.8.0" +"@tauri-apps/plugin-notification@~2": + version "2.3.3" + resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-notification/-/plugin-notification-2.3.3.tgz#01581e3abd3bd18200121b213d3e6ebff2967fe2" + integrity sha512-Zw+ZH18RJb41G4NrfHgIuofJiymusqN+q8fGUIIV7vyCH+5sSn5coqRv/MWB9qETsUs97vmU045q7OyseCV3Qg== + dependencies: + "@tauri-apps/api" "^2.8.0" + "@tauri-apps/plugin-opener@^2": version "2.5.2" resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-opener/-/plugin-opener-2.5.2.tgz#6e2127d0ad7627a16103215ed596e4fa42bda199"