From 6b7f2216afdddbcf4b845861676eec74153f2db9 Mon Sep 17 00:00:00 2001 From: Zebulun McNeill Date: Sat, 4 Jan 2025 16:38:41 -0600 Subject: [PATCH] notification system ig --- Slopify/package-lock.json | 10 + Slopify/package.json | 1 + Slopify/src-tauri/2 | 7 + Slopify/src-tauri/Cargo.lock | 194 ++++++++++++++++++-- Slopify/src-tauri/Cargo.toml | 1 + Slopify/src-tauri/capabilities/default.json | 12 +- Slopify/src-tauri/src/lib.rs | 1 + Slopify/src-tauri/tauri.conf.json | 4 +- Slopify/src/components/MessageList.jsx | 29 ++- Slopify/src/pages/ChatPage.jsx | 2 +- 10 files changed, 229 insertions(+), 32 deletions(-) create mode 100644 Slopify/src-tauri/2 diff --git a/Slopify/package-lock.json b/Slopify/package-lock.json index 5afd4809..9ab2f65e 100644 --- a/Slopify/package-lock.json +++ b/Slopify/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@supabase/supabase-js": "^2.47.10", "@tauri-apps/api": "^2", + "@tauri-apps/plugin-notification": "^2.2.0", "@tauri-apps/plugin-opener": "^2", "prettier": "^3.4.2", "react": "^18.3.1", @@ -1248,6 +1249,15 @@ "node": ">= 10" } }, + "node_modules/@tauri-apps/plugin-notification": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-notification/-/plugin-notification-2.2.0.tgz", + "integrity": "sha512-uhE3a2gFlqwiWhY/JbhXOF13K4iILEYxUk0D2Y+q69HP6tnfPqKCuNTHxDM0H+oFAakXESNmJVnYw0Vi4IrMMQ==", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@tauri-apps/api": "^2.0.0" + } + }, "node_modules/@tauri-apps/plugin-opener": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.2.2.tgz", diff --git a/Slopify/package.json b/Slopify/package.json index a0cf7a49..5e9a220e 100644 --- a/Slopify/package.json +++ b/Slopify/package.json @@ -12,6 +12,7 @@ "dependencies": { "@supabase/supabase-js": "^2.47.10", "@tauri-apps/api": "^2", + "@tauri-apps/plugin-notification": "^2.2.0", "@tauri-apps/plugin-opener": "^2", "prettier": "^3.4.2", "react": "^18.3.1", diff --git a/Slopify/src-tauri/2 b/Slopify/src-tauri/2 new file mode 100644 index 00000000..88506863 --- /dev/null +++ b/Slopify/src-tauri/2 @@ -0,0 +1,7 @@ + +added 1 package, and audited 89 packages in 2s + +10 packages are looking for funding + run `npm fund` for details + +found 0 vulnerabilities diff --git a/Slopify/src-tauri/Cargo.lock b/Slopify/src-tauri/Cargo.lock index e05f7193..e3874e4f 100644 --- a/Slopify/src-tauri/Cargo.lock +++ b/Slopify/src-tauri/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -768,6 +768,16 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" version = "0.4.1" @@ -780,6 +790,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -1990,6 +2011,19 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" +[[package]] +name = "mac-notification-sys" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce8f34f3717aa37177e723df6c1fc5fb02b2a1087374ea3fe0ea42316dc8f91" +dependencies = [ + "cc", + "dirs-next", + "objc-foundation", + "objc_id", + "time", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -2135,6 +2169,19 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "notify-rust" +version = "4.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5134a72dc570b178bff81b01e81ab14a6fcc015391ed4b3b14853090658cd3a3" +dependencies = [ + "log", + "mac-notification-sys", + "serde", + "tauri-winrt-notification", + "zbus", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -2180,6 +2227,17 @@ dependencies = [ "malloc_buf", ] +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + [[package]] name = "objc-sys" version = "0.3.5" @@ -2398,6 +2456,15 @@ dependencies = [ "objc2-foundation", ] +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + [[package]] name = "object" version = "0.36.7" @@ -2677,7 +2744,7 @@ checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" dependencies = [ "base64 0.22.1", "indexmap 2.7.0", - "quick-xml", + "quick-xml 0.32.0", "serde", "time", ] @@ -2790,6 +2857,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "memchr", +] + [[package]] name = "quick-xml" version = "0.32.0" @@ -3301,6 +3377,7 @@ dependencies = [ "serde_json", "tauri", "tauri-build", + "tauri-plugin-notification", "tauri-plugin-opener", ] @@ -3511,7 +3588,7 @@ dependencies = [ "tao-macros", "unicode-segmentation", "url", - "windows", + "windows 0.58.0", "windows-core 0.58.0", "windows-version", "x11-dl", @@ -3581,7 +3658,7 @@ dependencies = [ "webkit2gtk", "webview2-com", "window-vibrancy", - "windows", + "windows 0.58.0", ] [[package]] @@ -3664,6 +3741,25 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-notification" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46ab803095f14ac6521fdb6477210a49e86fed6623c3c97d8e4b2b35e045e922" +dependencies = [ + "log", + "notify-rust", + "rand 0.8.5", + "serde", + "serde_json", + "serde_repr", + "tauri", + "tauri-plugin", + "thiserror 2.0.9", + "time", + "url", +] + [[package]] name = "tauri-plugin-opener" version = "2.2.2" @@ -3682,7 +3778,7 @@ dependencies = [ "tauri-plugin", "thiserror 2.0.9", "url", - "windows", + "windows 0.58.0", "zbus", ] @@ -3702,7 +3798,7 @@ dependencies = [ "tauri-utils", "thiserror 2.0.9", "url", - "windows", + "windows 0.58.0", ] [[package]] @@ -3727,7 +3823,7 @@ dependencies = [ "url", "webkit2gtk", "webview2-com", - "windows", + "windows 0.58.0", "wry", ] @@ -3778,6 +3874,17 @@ dependencies = [ "toml 0.7.8", ] +[[package]] +name = "tauri-winrt-notification" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f89f5fb70d6f62381f5d9b2ba9008196150b40b75f3068eb24faeddf1c686871" +dependencies = [ + "quick-xml 0.31.0", + "windows 0.56.0", + "windows-version", +] + [[package]] name = "tempfile" version = "3.14.0" @@ -4394,10 +4501,10 @@ checksum = "6f61ff3d9d0ee4efcb461b14eb3acfda2702d10dc329f339303fc3e57215ae2c" dependencies = [ "webview2-com-macros", "webview2-com-sys", - "windows", + "windows 0.58.0", "windows-core 0.58.0", - "windows-implement", - "windows-interface", + "windows-implement 0.58.0", + "windows-interface 0.58.0", ] [[package]] @@ -4418,7 +4525,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3a3e2eeb58f82361c93f9777014668eb3d07e7d174ee4c819575a9208011886" dependencies = [ "thiserror 1.0.69", - "windows", + "windows 0.58.0", "windows-core 0.58.0", ] @@ -4467,6 +4574,16 @@ dependencies = [ "windows-version", ] +[[package]] +name = "windows" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132" +dependencies = [ + "windows-core 0.56.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows" version = "0.58.0" @@ -4486,19 +4603,42 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6" +dependencies = [ + "windows-implement 0.56.0", + "windows-interface 0.56.0", + "windows-result 0.1.2", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" dependencies = [ - "windows-implement", - "windows-interface", - "windows-result", + "windows-implement 0.58.0", + "windows-interface 0.58.0", + "windows-result 0.2.0", "windows-strings", "windows-targets 0.52.6", ] +[[package]] +name = "windows-implement" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.93", +] + [[package]] name = "windows-implement" version = "0.58.0" @@ -4510,6 +4650,17 @@ dependencies = [ "syn 2.0.93", ] +[[package]] +name = "windows-interface" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.93", +] + [[package]] name = "windows-interface" version = "0.58.0" @@ -4527,11 +4678,20 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-strings", "windows-targets 0.52.6", ] +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-result" version = "0.2.0" @@ -4547,7 +4707,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-targets 0.52.6", ] @@ -4842,7 +5002,7 @@ dependencies = [ "webkit2gtk", "webkit2gtk-sys", "webview2-com", - "windows", + "windows 0.58.0", "windows-core 0.58.0", "windows-version", "x11-dl", diff --git a/Slopify/src-tauri/Cargo.toml b/Slopify/src-tauri/Cargo.toml index 1a09c009..ef77e100 100644 --- a/Slopify/src-tauri/Cargo.toml +++ b/Slopify/src-tauri/Cargo.toml @@ -22,4 +22,5 @@ tauri = { version = "2", features = [] } tauri-plugin-opener = "2" serde = { version = "1", features = ["derive"] } serde_json = "1" +tauri-plugin-notification = "2" diff --git a/Slopify/src-tauri/capabilities/default.json b/Slopify/src-tauri/capabilities/default.json index f7783640..01273f1a 100644 --- a/Slopify/src-tauri/capabilities/default.json +++ b/Slopify/src-tauri/capabilities/default.json @@ -2,6 +2,12 @@ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "default", "description": "Capability for the main window", - "windows": ["main"], - "permissions": ["core:default", "opener:default"] -} + "windows": [ + "main" + ], + "permissions": [ + "core:default", + "opener:default", + "notification:default" + ] +} \ No newline at end of file diff --git a/Slopify/src-tauri/src/lib.rs b/Slopify/src-tauri/src/lib.rs index 4a277ef3..651a7c30 100644 --- a/Slopify/src-tauri/src/lib.rs +++ b/Slopify/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_opener::init()) .invoke_handler(tauri::generate_handler![greet]) .run(tauri::generate_context!()) diff --git a/Slopify/src-tauri/tauri.conf.json b/Slopify/src-tauri/tauri.conf.json index 0bef3b75..9bf5f45a 100644 --- a/Slopify/src-tauri/tauri.conf.json +++ b/Slopify/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", - "productName": "slopify", - "version": "0.3.1", + "productName": "Slopify", + "version": "0.4.0", "identifier": "com.slopify.app", "build": { "beforeDevCommand": "npm run dev", diff --git a/Slopify/src/components/MessageList.jsx b/Slopify/src/components/MessageList.jsx index 2df04985..771d0d1c 100644 --- a/Slopify/src/components/MessageList.jsx +++ b/Slopify/src/components/MessageList.jsx @@ -1,22 +1,16 @@ import { useEffect, useState } from "react"; import { supabase } from "../supabaseClient"; import Message from "./Message"; +import { sendNotification } from "@tauri-apps/plugin-notification"; const PAGE_SIZE = 50; -export default function MessageList() { +export default function MessageList(data) { const [messages, setMessages] = useState([]); const [loading, setLoading] = useState(true); const [hasMore, setHasMore] = useState(true); const [scrolling, setScrolling] = useState(false); - useEffect(() => { - const messageBox = document.getElementById("message-box"); - if (messageBox) { - messageBox.scrollTop = messageBox.scrollHeight; - } - }, [messages]); - useEffect(() => { fetchMessages(); const subscription = supabase @@ -28,8 +22,11 @@ export default function MessageList() { const newMessage = payload.new; attachDisplayName(newMessage).then((msgWithDisplayName) => { setMessages((prev) => [...prev, msgWithDisplayName]); + if (data.currentUser && msgWithDisplayName.content.includes(`@${data.currentUser}`)) { + triggerNotification(msgWithDisplayName); + } }); - }, + } ) .subscribe(); @@ -38,6 +35,13 @@ export default function MessageList() { }; }, []); + useEffect(() => { + const messageBox = document.getElementById("message-box"); + if (messageBox) { + messageBox.scrollTop = messageBox.scrollHeight; + } + }, [messages]); + const formatDate = (utcDateString) => { const messageDate = new Date(`${utcDateString}Z`); const now = new Date(); @@ -141,6 +145,13 @@ export default function MessageList() { } }; + const triggerNotification = (message) => { + sendNotification({ + title: `${message.display_name} mentioned you!`, + body: message.content, + }); + }; + return (

Welcome back to Slopify, {displayName}!

- + {/*