From f61adb2ff58549e8b8127ba11c882e4516ca46e8 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Thu, 1 Jun 2023 16:51:00 +0700 Subject: [PATCH] enable native notification --- src-tauri/Cargo.lock | 70 +++++++++++++++++++++++++++++++- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- src/app/chat/components/list.tsx | 18 +++++++- src/stores/accounts.tsx | 39 +++++++++++------- 5 files changed, 111 insertions(+), 20 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 7fa7fd4e..3278ad68 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2096,6 +2096,19 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" +[[package]] +name = "mac-notification-sys" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e72d50edb17756489e79d52eb146927bec8eba9dd48faadf9ef08bca3791ad5" +dependencies = [ + "cc", + "dirs-next", + "objc-foundation", + "objc_id", + "time", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -2333,6 +2346,19 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "notify-rust" +version = "4.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfa211d18e360f08e36c364308f394b5eb23a6629150690e109a916dc6f610e" +dependencies = [ + "log", + "mac-notification-sys", + "serde", + "tauri-winrt-notification", + "zbus", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2787,7 +2813,7 @@ dependencies = [ "base64 0.21.0", "indexmap", "line-wrap", - "quick-xml", + "quick-xml 0.28.2", "serde", "time", ] @@ -2891,6 +2917,15 @@ dependencies = [ "rustyline", ] +[[package]] +name = "quick-xml" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11bafc859c6815fbaffbbbf4229ecb767ac913fecb27f9ad4343662e9ef099ea" +dependencies = [ + "memchr", +] + [[package]] name = "quick-xml" version = "0.28.2" @@ -3813,6 +3848,27 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7ac893c7d471c8a21f31cfe213ec4f6d9afeed25537c772e08ef3f005f8729e" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339f799d8b549e3744c7ac7feb216383e4005d94bdb22561b3ab8f3b808ae9fb" +dependencies = [ + "heck 0.3.3", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "syn" version = "1.0.109" @@ -3960,6 +4016,7 @@ dependencies = [ "http", "ignore", "minisign-verify", + "notify-rust", "objc", "once_cell", "open", @@ -4172,6 +4229,17 @@ dependencies = [ "toml 0.7.3", ] +[[package]] +name = "tauri-winrt-notification" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c58de036c4d2e20717024de2a3c4bf56c301f07b21bc8ef9b57189fce06f1f3b" +dependencies = [ + "quick-xml 0.23.1", + "strum", + "windows 0.39.0", +] + [[package]] name = "tempfile" version = "3.5.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2021e595..63d2d20f 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -16,7 +16,7 @@ tauri-build = { version = "1.2", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.2", features = ["clipboard-read-text", "clipboard-write-text", "dialog-open", "fs-read-dir", "fs-read-file", "http-all", "http-multipart", "os-all", "shell-open", "system-tray", "updater", "window-close", "window-start-dragging"] } +tauri = { version = "1.2", features = ["clipboard-read-text", "clipboard-write-text", "dialog-open", "fs-read-dir", "fs-read-file", "http-all", "http-multipart", "notification-all", "os-all", "shell-open", "system-tray", "updater", "window-close", "window-start-dragging"] } tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" } tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" } sqlx-cli = {version = "0.6.3", default-features = false, features = ["sqlite"] } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index c753450b..f94d9a06 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -55,7 +55,7 @@ "open": true }, "notification": { - "all": false + "all": true }, "window": { "startDragging": true, diff --git a/src/app/chat/components/list.tsx b/src/app/chat/components/list.tsx index 957a035e..fae34fcb 100644 --- a/src/app/chat/components/list.tsx +++ b/src/app/chat/components/list.tsx @@ -14,6 +14,20 @@ export function ChatsList() { fetchChats(account.pubkey); }, [fetchChats]); + if (!account) + return ( +
+
+
+
+
+
+
+
+
+
+ ); + return (
@@ -21,11 +35,11 @@ export function ChatsList() { <>
-
+
-
+
) : ( diff --git a/src/stores/accounts.tsx b/src/stores/accounts.tsx index 74aaaa87..b21fa778 100644 --- a/src/stores/accounts.tsx +++ b/src/stores/accounts.tsx @@ -1,18 +1,27 @@ import { getActiveAccount, getLastLogin } from "@utils/storage"; import { create } from "zustand"; +import { createJSONStorage, persist } from "zustand/middleware"; -export const useActiveAccount = create((set) => ({ - account: null, - lastLogin: 0, - fetch: async () => { - const response = await getActiveAccount(); - set({ account: response }); - }, - fetchLastLogin: async () => { - const response = await getLastLogin(); - set({ lastLogin: parseInt(response) }); - }, - updateFollows: (list: any) => { - set((state: any) => ({ account: { ...state.account, follows: list } })); - }, -})); +export const useActiveAccount = create( + persist( + (set) => ({ + account: null, + lastLogin: 0, + fetch: async () => { + const response = await getActiveAccount(); + set({ account: response }); + }, + fetchLastLogin: async () => { + const response = await getLastLogin(); + set({ lastLogin: parseInt(response) }); + }, + updateFollows: (list: any) => { + set((state: any) => ({ account: { ...state.account, follows: list } })); + }, + }), + { + name: "account", + storage: createJSONStorage(() => sessionStorage), + }, + ), +);