@@ -8,7 +8,6 @@ use std::{
88} ;
99
1010use anyhow:: Context ;
11- use csscolorparser:: Color ;
1211use serde:: Serialize ;
1312use tauri:: {
1413 AppHandle , Manager , PhysicalPosition , PhysicalSize , WebviewUrl ,
@@ -19,12 +18,13 @@ use tokio::{
1918 task,
2019} ;
2120use tracing:: { error, info} ;
21+ use window_vibrancy:: apply_vibrancy;
2222
2323use crate :: {
24- common:: { PathExt , WindowExt } ,
24+ common:: { parse_rgba , PathExt , WindowExt } ,
2525 config:: {
26- AnchorPoint , BackgroundEffect , Config , WidgetConfig , WidgetPlacement ,
27- ZOrder ,
26+ AnchorPoint , Config , MacOsBackgroundEffect , WidgetConfig ,
27+ WidgetPlacement , WindowsBackgroundEffect ,
2828 } ,
2929 monitor_state:: MonitorState ,
3030} ;
@@ -195,8 +195,6 @@ impl WidgetFactory {
195195 Self :: to_asset_url ( & html_path. to_unicode_string ( ) ) . into ( ) ,
196196 ) ;
197197
198- let window_effect = & widget_config. background_effect ;
199-
200198 // Note that window label needs to be globally unique.
201199 let window = WebviewWindowBuilder :: new (
202200 & self . app_handle ,
@@ -262,38 +260,48 @@ impl WidgetFactory {
262260
263261 #[ cfg( target_os = "windows" ) ]
264262 {
265- if let Some ( window_effect) = & widget_config. background_effect {
266- if * window_effect != BackgroundEffect :: None {
267- let color = if let Some ( color_str) =
268- & widget_config. background_effect_color
269- {
270- let color = csscolorparser:: parse ( color_str) ?. to_rgba8 ( ) ;
271- Some ( ( color[ 1 ] , color[ 2 ] , color[ 3 ] , color[ 4 ] ) )
272- } else {
273- Some ( ( 18 , 18 , 18 , 125 ) )
274- } ;
263+ use window_vibrancy:: { apply_acrylic, apply_blur, apply_mica} ;
275264
276- use window_vibrancy:: { apply_acrylic, apply_blur, apply_mica} ;
277- match window_effect {
278- BackgroundEffect :: Blur => {
279- if let Err ( e) = apply_blur ( & window, color) {
280- error ! ( "Failed to apply blur: {:?}" , e) ;
265+ if let Some ( window_effect) = & widget_config. background_effect {
266+ if let Some ( effect) = & window_effect. windows {
267+ let result = match effect {
268+ WindowsBackgroundEffect :: Blur { color }
269+ | WindowsBackgroundEffect :: Acrylic { color } => {
270+ let color =
271+ parse_rgba ( color) . unwrap_or ( ( 255 , 255 , 255 , 200 ) ) ;
272+ match effect {
273+ WindowsBackgroundEffect :: Blur { .. } => {
274+ apply_blur ( & window, Some ( color) )
275+ }
276+ _ => apply_acrylic ( & window, Some ( color) ) ,
281277 }
282278 }
283- BackgroundEffect :: Acrylic => {
284- if let Err ( e) = apply_acrylic ( & window, color) {
285- error ! ( "Failed to apply acrylic: {:?}" , e) ;
286- }
279+ WindowsBackgroundEffect :: Mica { prefer_dark } => {
280+ apply_mica ( & window, Some ( * prefer_dark) )
287281 }
288- BackgroundEffect :: Mica => {
289- let mica_dark = widget_config
290- . background_effect_mica_dark
291- . unwrap_or ( false ) ;
292- if let Err ( e) = apply_mica ( & window, Some ( mica_dark) ) {
293- error ! ( "Failed to apply mica: {:?}" , e) ;
294- }
282+ } ;
283+
284+ if let Err ( e) = result {
285+ error ! ( "Failed to apply effect: {:?}" , e) ;
286+ }
287+ }
288+ }
289+ }
290+
291+ #[ cfg( target_os = "macos" ) ]
292+ {
293+ use window_vibrancy:: apply_vibrancy;
294+
295+ if let Some ( window_effect) = & widget_config. background_effect {
296+ if let Some ( effect) = & window_effect. mac_os {
297+ let result = match effect {
298+ MacOsBackgroundEffect :: Vibrancy { material } => {
299+ apply_vibrancy ( & window, * material, None , None ) ;
295300 }
296- _ => { }
301+ } ;
302+
303+ if let Err ( e) = result {
304+ error ! ( "Failed to apply macos effect: {:?}" , e) ;
297305 }
298306 }
299307 }
0 commit comments