From b4957bae1f7165e2c0e310c0d3e554df5d2f05c7 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Sat, 2 Sep 2023 12:49:04 +0700 Subject: [PATCH] native fetch and shadow --- src-tauri/Cargo.lock | 104 +++++++++++++++++++++++++++++++++----- src-tauri/Cargo.toml | 7 ++- src-tauri/src/main.rs | 18 +++++++ src-tauri/tauri.conf.json | 3 +- src/shared/nip05.tsx | 6 ++- 5 files changed, 122 insertions(+), 16 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d15d1714..a48a5374 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -776,8 +776,24 @@ dependencies = [ "block", "cocoa-foundation", "core-foundation", - "core-graphics", - "foreign-types", + "core-graphics 0.22.3", + "foreign-types 0.3.2", + "libc", + "objc", +] + +[[package]] +name = "cocoa" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6140449f97a6e97f9511815c5632d84c8aacf8ac271ad77c559218161a1373c" +dependencies = [ + "bitflags 1.3.2", + "block", + "cocoa-foundation", + "core-foundation", + "core-graphics 0.23.1", + "foreign-types 0.5.0", "libc", "objc", ] @@ -792,7 +808,7 @@ dependencies = [ "block", "core-foundation", "core-graphics-types", - "foreign-types", + "foreign-types 0.3.2", "libc", "objc", ] @@ -896,7 +912,20 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types", + "foreign-types 0.3.2", + "libc", +] + +[[package]] +name = "core-graphics" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-graphics-types", + "foreign-types 0.5.0", "libc", ] @@ -1469,7 +1498,28 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared", + "foreign-types-shared 0.1.1", +] + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared 0.3.1", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.29", ] [[package]] @@ -1478,6 +1528,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + [[package]] name = "form_urlencoded" version = "1.2.0" @@ -2523,6 +2579,8 @@ dependencies = [ "tauri-plugin-store", "tauri-plugin-stronghold", "tauri-plugin-upload", + "window-shadows", + "window-vibrancy", ] [[package]] @@ -2962,7 +3020,7 @@ checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ "bitflags 2.4.0", "cfg-if", - "foreign-types", + "foreign-types 0.3.2", "libc", "once_cell", "openssl-macros", @@ -4719,9 +4777,9 @@ dependencies = [ "bitflags 1.3.2", "cairo-rs", "cc", - "cocoa", + "cocoa 0.24.1", "core-foundation", - "core-graphics", + "core-graphics 0.22.3", "crossbeam-channel", "dispatch", "gdk", @@ -4793,7 +4851,7 @@ checksum = "7fbe522898e35407a8e60dc3870f7579fea2fc262a6a6072eccdd37ae1e1d91e" dependencies = [ "anyhow", "bytes", - "cocoa", + "cocoa 0.24.1", "dirs-next", "embed_plist", "encoding_rs", @@ -5013,7 +5071,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7aa256a1407a3a091b5d843eccc1a5042289baf0a43d1179d9f0fcfea37c1b" dependencies = [ - "cocoa", + "cocoa 0.24.1", "gtk", "percent-encoding", "rand 0.8.5", @@ -5780,6 +5838,28 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "window-shadows" +version = "0.2.1" +source = "git+https://github.com/tauri-apps/window-shadows?branch=dev#a9f5f1f7725609c71404539befca1f1a98095cd2" +dependencies = [ + "cocoa 0.25.0", + "objc", + "raw-window-handle", + "windows-sys 0.48.0", +] + +[[package]] +name = "window-vibrancy" +version = "0.4.0" +source = "git+https://github.com/tauri-apps/window-vibrancy?branch=dev#84b45368cb9aa8ce5107ae3d508092720226da22" +dependencies = [ + "cocoa 0.25.0", + "objc", + "raw-window-handle", + "windows-sys 0.48.0", +] + [[package]] name = "windows" version = "0.36.1" @@ -6144,8 +6224,8 @@ checksum = "33748f35413c8a98d45f7a08832d848c0c5915501803d1faade5a4ebcd258cea" dependencies = [ "base64 0.13.1", "block", - "cocoa", - "core-graphics", + "cocoa 0.24.1", + "core-graphics 0.22.3", "crossbeam-channel", "dunce", "gdk", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2cd33150..e1c3fb9d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -16,7 +16,10 @@ tauri-build = { version = "1.4.0", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.4.0", features = [ "window-start-dragging", "path-all", "http-all", +tauri = { version = "1.4.0", features = [ + "window-start-dragging", + "path-all", + "http-all", "clipboard-write-text", "os-all", "notification-all", @@ -36,6 +39,8 @@ tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspac tauri-plugin-stronghold = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } tauri-plugin-upload = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } +window-vibrancy = { git = "https://github.com/tauri-apps/window-vibrancy", branch = "dev" } +window-shadows = { git = "https://github.com/tauri-apps/window-shadows", branch = "dev" } sqlx-cli = { version = "0.7.0", default-features = false, features = [ "sqlite", ] } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index b7491cf6..0dacb1d4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -6,6 +6,8 @@ use tauri::Manager; use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_sql::{Migration, MigrationKind}; +use window_shadows::set_shadow; +use window_vibrancy::{apply_mica, apply_vibrancy, NSVisualEffectMaterial}; #[derive(Clone, serde::Serialize)] struct Payload { @@ -171,6 +173,22 @@ fn main() { .plugin(tauri_plugin_upload::init()) .plugin(tauri_plugin_store::Builder::default().build()) .invoke_handler(tauri::generate_handler![close_splashscreen]) + .setup(|app| { + let window = app.get_window("main").unwrap(); + + #[cfg(target_os = "macos")] + apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, None) + .expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS"); + + #[cfg(target_os = "windows")] + apply_mica(&window, Some(true)) + .expect("Unsupported platform! 'apply_blur' is only supported on Windows"); + + // set native shadow + set_shadow(&window, true).expect("Unsupported platform!"); + + Ok(()) + }) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index f0a103ea..9b4eb01f 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -48,7 +48,8 @@ "http": { "all": true, "scope": [ - "https://void.cat/*" + "http://**", + "https://**" ] }, "shell": { diff --git a/src/shared/nip05.tsx b/src/shared/nip05.tsx index f7c140c7..0f125dd4 100644 --- a/src/shared/nip05.tsx +++ b/src/shared/nip05.tsx @@ -1,4 +1,5 @@ import { useQuery } from '@tanstack/react-query'; +import { fetch } from '@tauri-apps/api/http'; import { twMerge } from 'tailwind-merge'; import { UnverifiedIcon, VerifiedIcon } from '@shared/icons'; @@ -29,6 +30,7 @@ export function NIP05({ const res = await fetch(verifyURL, { method: 'GET', + timeout: 10, headers: { 'Content-Type': 'application/json; charset=utf-8', }, @@ -36,9 +38,9 @@ export function NIP05({ if (!res.ok) throw new Error(`Failed to fetch NIP-05 service: ${nip05}`); - const data: NIP05 = await res.json(); + const data = res.data as NIP05; if (data.names) { - if (data.names.username !== pubkey) return false; + if (data.names[localPath] !== pubkey) return false; return true; } return false;