From d673a224600ea913bd3e8689fe39b633b94e4301 Mon Sep 17 00:00:00 2001 From: swordtraveller Date: Tue, 28 Jan 2025 18:29:59 +0800 Subject: [PATCH] feat: add a semi-transparent frosted glass effect to the window --- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 1 + src-tauri/src/lib.rs | 15 +++++++++++++++ src-tauri/tauri.conf.json | 3 ++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c9e5e16..a8eb857 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -111,6 +111,7 @@ dependencies = [ "tauri-plugin-log", "tauri-plugin-opener", "tauri-plugin-shell", + "window-vibrancy", "windows-icons", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 5521861..7a818e8 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -29,3 +29,4 @@ tauri-plugin-shell = "2" tauri-plugin-fs = "2" lnk = "0.5.1" windows-icons = "0.1.1" +window-vibrancy = "0.5.2" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index bdfefa2..c836885 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -6,8 +6,10 @@ use std::path::Path; use std::process::Command; use tauri_plugin_log::{Target, TargetKind}; +use tauri::Manager; use lnk::ShellLink; use windows_icons::get_icon_base64_by_path; +use window_vibrancy::{apply_blur, apply_vibrancy, apply_mica, apply_acrylic, NSVisualEffectMaterial}; // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ #[tauri::command] @@ -47,6 +49,19 @@ fn is_shortcut(path: &str) -> bool { #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() + .setup(|app| { + let window = app.get_webview_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_acrylic(&window, Some((0, 0, 0, (256.0_f64 * 0.2_f64).round() as u8))) + .expect("Unsupported platform! 'apply_acrylic' is only supported on Windows"); + + Ok(()) + }) .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_fs::init()) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 75b4e17..83ab160 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -14,7 +14,8 @@ { "title": "app-launcher", "width": 800, - "height": 600 + "height": 600, + "transparent": true } ], "security": {