@@ -48,27 +48,6 @@ pub fn run() {
4848 )
4949 . init ( ) ;
5050
51- // On Windows, verify that WebView2 Runtime is installed before proceeding.
52- // Without WebView2 the app window would start hidden and never become visible
53- // because the frontend JS (which calls `show()`) cannot load.
54- #[ cfg( target_os = "windows" ) ]
55- {
56- if !windows_utils:: is_webview2_installed ( ) {
57- tracing:: error!( "WebView2 Runtime not found — cannot start AQBot" ) ;
58- let user_ok = windows_utils:: show_warning_ok_cancel (
59- "AQBot" ,
60- "未检测到 Microsoft Edge WebView2 Runtime,AQBot 无法启动。\n \n \
61- 点击「确定」打开下载页面进行安装,安装完成后重新启动 AQBot。",
62- ) ;
63- if user_ok {
64- let _ = std:: process:: Command :: new ( "cmd" )
65- . args ( [ "/c" , "start" , "https://developer.microsoft.com/en-us/microsoft-edge/webview2/?form=MA13LH#download" ] )
66- . spawn ( ) ;
67- }
68- std:: process:: exit ( 1 ) ;
69- }
70- }
71-
7251 #[ allow( unused_mut) ]
7352 let mut builder = tauri:: Builder :: default ( )
7453 . plugin ( tauri_plugin_opener:: init ( ) )
@@ -88,7 +67,7 @@ pub fn run() {
8867 builder = builder. plugin ( tauri_plugin_mcp_bridge:: init ( ) ) ;
8968 }
9069
91- builder
70+ let build_result = builder
9271 . invoke_handler ( tauri:: generate_handler![
9372 // providers
9473 commands:: providers:: list_providers,
@@ -655,9 +634,41 @@ pub fn run() {
655634 }
656635 }
657636 } )
658- . build ( tauri:: generate_context!( ) )
659- . expect ( "error while building tauri application" )
660- . run ( |app, event| {
637+ . build ( tauri:: generate_context!( ) ) ;
638+
639+ let app = match build_result {
640+ Ok ( app) => app,
641+ Err ( e) => {
642+ let error_msg = e. to_string ( ) ;
643+ tracing:: error!( "Failed to build Tauri application: {}" , error_msg) ;
644+
645+ #[ cfg( target_os = "windows" ) ]
646+ {
647+ let lower = error_msg. to_lowercase ( ) ;
648+ if lower. contains ( "webview2" ) || lower. contains ( "webview" ) || lower. contains ( "edge" ) {
649+ let user_ok = windows_utils:: show_warning_ok_cancel (
650+ "AQBot" ,
651+ "未检测到 Microsoft Edge WebView2 Runtime,AQBot 无法启动。\n \n \
652+ 点击「确定」打开下载页面进行安装,安装完成后重新启动 AQBot。",
653+ ) ;
654+ if user_ok {
655+ let _ = std:: process:: Command :: new ( "cmd" )
656+ . args ( [ "/c" , "start" , "https://developer.microsoft.com/en-us/microsoft-edge/webview2/?form=MA13LH#download" ] )
657+ . spawn ( ) ;
658+ }
659+ } else {
660+ windows_utils:: show_error_dialog (
661+ "AQBot" ,
662+ & format ! ( "应用启动失败:{}" , error_msg) ,
663+ ) ;
664+ }
665+ }
666+
667+ std:: process:: exit ( 1 ) ;
668+ }
669+ } ;
670+
671+ app. run ( |app, event| {
661672 #[ cfg( target_os = "macos" ) ]
662673 if let tauri:: RunEvent :: Reopen { has_visible_windows, .. } = event {
663674 if !has_visible_windows {
0 commit comments