@@ -195,10 +195,7 @@ fn set_always_on_top(app: AppHandle, on_top: bool) -> Result<(), String> {
195195#[ tauri:: command]
196196fn enter_floating ( app : AppHandle ) -> Result < ( ) , String > {
197197 // 创建悬浮球窗口(透明、无边框、置顶、隐藏任务栏)
198- append_log_line ( "[FLOAT] enter_floating invoked" ) ;
199- eprintln ! ( "[FLOAT] enter_floating invoked" ) ;
200198 // 切回“独立透明窗口”方案:新建 float 窗口 + 透明 + 无边框 + 置顶
201- eprintln ! ( "[FLOAT] creating dedicated transparent window" ) ;
202199 // 使用 App 协议,dev 模式会自动映射到 dev 服务器
203200 // 如果在配置中已声明 float 窗口,则直接获取并显示
204201 if let Some ( w) = app. get_webview_window ( "float" ) {
@@ -220,12 +217,9 @@ fn enter_floating(app: AppHandle) -> Result<(), String> {
220217 let _ = w. navigate ( Url :: parse ( "tauri://localhost/index.html#float" ) . unwrap_or_else ( |_| Url :: parse ( "tauri://localhost/#float" ) . unwrap ( ) ) ) ;
221218 let _ = w. show ( ) ;
222219 let _ = w. set_focus ( ) ;
223- eprintln ! ( "[FLOAT] show float window" ) ;
224- append_log_line ( "[FLOAT] show float window" ) ;
225220 } else {
226221 // 理论上不会发生(预声明的 float 始终存在且我们不再关闭它)
227- eprintln ! ( "[FLOAT] WARN: float window not found (should be pre-declared)" ) ;
228- append_log_line ( "[FLOAT] WARN: float window not found (should be pre-declared)" ) ;
222+ // 静默处理:若未找到浮窗,跳过
229223 }
230224 // 隐藏主窗口,避免任务栏占位(如果主窗口尚未创建则忽略)
231225 if let Some ( main) = app. get_webview_window ( "main" ) {
@@ -237,29 +231,33 @@ fn enter_floating(app: AppHandle) -> Result<(), String> {
237231
238232#[ tauri:: command]
239233fn exit_floating ( app : AppHandle ) -> Result < ( ) , String > {
240- append_log_line ( "[FLOAT] exit_floating invoked" ) ;
241- eprintln ! ( "[FLOAT] exit_floating invoked" ) ;
242234 // 不再关闭浮窗,改为仅隐藏
243235 if let Some ( f) = app. get_webview_window ( "float" ) { let _ = f. hide ( ) ; }
244236 if let Some ( main) = app. get_webview_window ( "main" ) {
245- append_log_line ( "[FLOAT] restore MAIN from floating style" ) ;
246- eprintln ! ( "[FLOAT] restore MAIN from floating style" ) ;
247237 let _ = main. set_decorations ( true ) ;
248238 let _ = main. set_resizable ( true ) ;
249239 let _ = main. set_skip_taskbar ( false ) ;
250240 let _ = main. set_always_on_top ( false ) ;
251241 let _ = main. set_min_size ( Some ( Size :: Logical ( LogicalSize :: new ( 220.0 , 120.0 ) ) ) ) ;
252242 let _ = main. set_max_size ( Some ( Size :: Logical ( LogicalSize :: new ( 560.0 , 560.0 ) ) ) ) ;
253243 let _ = main. set_size ( Size :: Logical ( LogicalSize :: new ( 390.0 , 390.0 ) ) ) ;
254- #[ cfg( debug_assertions) ]
255- { let _ = main. navigate ( Url :: parse ( "tauri://localhost/" ) . unwrap ( ) ) ; }
256- #[ cfg( not( debug_assertions) ) ]
257- { let _ = main. navigate ( Url :: parse ( "tauri://localhost/index.html" ) . unwrap ( ) ) ; }
258244 let _ = main. show ( ) ;
245+ // 尝试通过 1px 尺寸抖动强制 WebView2 重绘,缓解偶发黑/白屏
246+ if let ( Ok ( sz) , Ok ( sf) ) = ( main. inner_size ( ) , main. scale_factor ( ) ) {
247+ let w_log = ( sz. width as f64 ) / sf;
248+ let h_log = ( sz. height as f64 ) / sf;
249+ let _ = main. set_size ( Size :: Logical ( LogicalSize :: new ( w_log + 1.0 , h_log) ) ) ;
250+ let app2 = app. clone ( ) ;
251+ std:: thread:: spawn ( move || {
252+ std:: thread:: sleep ( Duration :: from_millis ( 30 ) ) ;
253+ if let Some ( win2) = app2. get_webview_window ( "main" ) {
254+ let _ = win2. set_size ( Size :: Logical ( LogicalSize :: new ( w_log, h_log) ) ) ;
255+ }
256+ } ) ;
257+ }
259258 let _ = main. set_focus ( ) ;
260259 } else {
261- append_log_line ( "[FLOAT] ERROR: main window not found on exit" ) ;
262- eprintln ! ( "[FLOAT] ERROR: main window not found on exit" ) ;
260+ // 静默处理:若未找到主窗口,跳过
263261 }
264262 Ok ( ( ) )
265263}
0 commit comments