enable native notification

This commit is contained in:
Ren Amamiya 2023-06-01 16:51:00 +07:00
parent ea3e5a69f6
commit f61adb2ff5
5 changed files with 111 additions and 20 deletions

70
src-tauri/Cargo.lock generated
View File

@ -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"

View File

@ -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"] }

View File

@ -55,7 +55,7 @@
"open": true
},
"notification": {
"all": false
"all": true
},
"window": {
"startDragging": true,

View File

@ -14,6 +14,20 @@ export function ChatsList() {
fetchChats(account.pubkey);
}, [fetchChats]);
if (!account)
return (
<div className="flex flex-col">
<div className="inline-flex h-8 items-center gap-2 rounded-md px-2.5">
<div className="relative h-5 w-5 shrink-0 animate-pulse rounded bg-zinc-800" />
<div className="h-3 w-full rounded-sm animate-pulse bg-zinc-800" />
</div>
<div className="inline-flex h-8 items-center gap-2 rounded-md px-2.5">
<div className="relative h-5 w-5 shrink-0 animate-pulse rounded bg-zinc-800" />
<div className="h-3 w-full rounded-sm animate-pulse bg-zinc-800" />
</div>
</div>
);
return (
<div className="flex flex-col gap-1">
<ChatsListSelfItem data={account} />
@ -21,11 +35,11 @@ export function ChatsList() {
<>
<div className="inline-flex h-8 items-center gap-2 rounded-md px-2.5">
<div className="relative h-5 w-5 shrink-0 animate-pulse rounded bg-zinc-800" />
<div className="h-3 w-full animate-pulse bg-zinc-800" />
<div className="h-3 w-full rounded-sm animate-pulse bg-zinc-800" />
</div>
<div className="inline-flex h-8 items-center gap-2 rounded-md px-2.5">
<div className="relative h-5 w-5 shrink-0 animate-pulse rounded bg-zinc-800" />
<div className="h-3 w-full animate-pulse bg-zinc-800" />
<div className="h-3 w-full rounded-sm animate-pulse bg-zinc-800" />
</div>
</>
) : (

View File

@ -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),
},
),
);