@@ -79,7 +79,6 @@ pub async fn init_ads_window<R: Runtime>(
79
79
override_shown : bool ,
80
80
) -> crate :: api:: Result < ( ) > {
81
81
use tauri:: WebviewUrl ;
82
- const LINK_SCRIPT : & str = include_str ! ( "ads-init.js" ) ;
83
82
84
83
let state = app. state :: < RwLock < AdsState > > ( ) ;
85
84
let mut state = state. write ( ) . await ;
@@ -102,25 +101,42 @@ pub async fn init_ads_window<R: Runtime>(
102
101
webview. set_position ( PhysicalPosition :: new ( -1000 , -1000 ) ) ;
103
102
}
104
103
} else if let Some ( window) = app. get_window ( "main" ) {
105
- let _ = window. add_child (
104
+ let webview = window. add_child (
106
105
tauri:: webview:: WebviewBuilder :: new (
107
106
"ads-window" ,
108
107
WebviewUrl :: External (
109
108
AD_LINK . parse ( ) . unwrap ( ) ,
110
109
) ,
111
110
)
112
- . initialization_script ( LINK_SCRIPT )
113
- // .initialization_script_for_main_only(LINK_SCRIPT, false )
114
- . user_agent ( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" )
115
- . zoom_hotkeys_enabled ( false )
116
- . transparent ( true ) ,
111
+ . initialization_script_for_all_frames ( include_str ! ( "ads-init.js" ) )
112
+ . user_agent ( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" )
113
+ . zoom_hotkeys_enabled ( false )
114
+ . transparent ( true )
115
+ . on_new_window ( |_ , _| tauri :: webview :: NewWindowResponse :: Deny ) ,
117
116
if state. shown {
118
117
position
119
118
} else {
120
119
PhysicalPosition :: new ( -1000.0 , -1000.0 )
121
120
} ,
122
121
size,
123
- ) ;
122
+ ) ?;
123
+
124
+ webview. with_webview ( #[ allow( unused_variables) ] |webview2| {
125
+ #[ cfg( windows) ]
126
+ {
127
+ use webview2_com:: Microsoft :: Web :: WebView2 :: Win32 :: ICoreWebView2_8 ;
128
+ use windows_core:: Interface ;
129
+
130
+ let webview2_controller = webview2. controller ( ) ;
131
+ let Ok ( webview2_8) = unsafe { webview2_controller. CoreWebView2 ( ) }
132
+ . and_then ( |core_webview2| core_webview2. cast :: < ICoreWebView2_8 > ( ) )
133
+ else {
134
+ return ;
135
+ } ;
136
+
137
+ unsafe { webview2_8. SetIsMuted ( true ) } . ok ( ) ;
138
+ }
139
+ } ) ?;
124
140
}
125
141
}
126
142
0 commit comments