@@ -721,52 +721,60 @@ void ShowRuntimeWindow()
721721 }
722722 else
723723 {
724- // Linux/macOS: 尝试显示原生对话框
725- try
724+ var shortMessage = message . Length > 2048
725+ ? message . Substring ( 0 , 2048 ) + "...\n \n (Log truncated)"
726+ : message ;
727+
728+ MessageBox ( IntPtr . Zero , shortMessage , $ "MFAAvalonia { title } ", 0x10 ) ; // MB_ICONERROR
729+ }
730+ }
731+ else
732+ {
733+ // Linux/macOS: 尝试显示原生对话框
734+ try
735+ {
736+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
726737 {
727- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
738+ var escapedMessage = message . Replace ( "\\ " , "\\ \\ " ) . Replace ( "\" " , "\\ \" " ) . Replace ( "\n " , "\\ r" ) ;
739+ var escapedTitle = title . Replace ( "\\ " , "\\ \\ " ) . Replace ( "\" " , "\\ \" " ) ;
740+ var psi = new ProcessStartInfo
741+ {
742+ FileName = "osascript" ,
743+ Arguments = $ "-e \" display alert \\ \" { escapedTitle } \\ \" message \\ \" { escapedMessage } \\ \" as critical\" ",
744+ UseShellExecute = false ,
745+ CreateNoWindow = true
746+ } ;
747+ Process . Start ( psi ) ? . WaitForExit ( ) ;
748+ }
749+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
750+ {
751+ // 尝试 zenity
752+ try
728753 {
729- var escapedMessage = message . Replace ( "\\ " , "\\ \\ " ) . Replace ( "\" " , "\\ \" " ) . Replace ( "\n " , "\\ r" ) ;
730- var escapedTitle = title . Replace ( "\\ " , "\\ \\ " ) . Replace ( "\" " , "\\ \" " ) ;
731754 var psi = new ProcessStartInfo
732755 {
733- FileName = "osascript" ,
734- Arguments = $ "-e \" display alert \\ \" { escapedTitle } \\ \" message \\ \" { escapedMessage } \\ \" as critical\" ",
735- UseShellExecute = false ,
736- CreateNoWindow = true
756+ FileName = "zenity" ,
757+ Arguments = $ "--error --text=\" { message . Replace ( "\" " , "\\ \" " ) } \" --title=\" { title } \" ",
758+ UseShellExecute = true
737759 } ;
738760 Process . Start ( psi ) ? . WaitForExit ( ) ;
739761 }
740- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
762+ catch
741763 {
742- // 尝试 zenity
743- try
744- {
745- var psi = new ProcessStartInfo
746- {
747- FileName = "zenity" ,
748- Arguments = $ "--error --text=\" { message . Replace ( "\" " , "\\ \" " ) } \" --title=\" { title } \" ",
749- UseShellExecute = true
750- } ;
751- Process . Start ( psi ) ? . WaitForExit ( ) ;
752- }
753- catch
764+ // 尝试 kdialog
765+ var psi = new ProcessStartInfo
754766 {
755- // 尝试 kdialog
756- var psi = new ProcessStartInfo
757- {
758- FileName = "kdialog" ,
759- Arguments = $ "--error \" { message . Replace ( "\" " , "\\ \" " ) } \" --title \" { title } \" ",
760- UseShellExecute = true
761- } ;
762- Process . Start ( psi ) ? . WaitForExit ( ) ;
763- }
767+ FileName = "kdialog" ,
768+ Arguments = $ "--error \" { message . Replace ( "\" " , "\\ \" " ) } \" --title \" { title } \" ",
769+ UseShellExecute = true
770+ } ;
771+ Process . Start ( psi ) ? . WaitForExit ( ) ;
764772 }
765773 }
766- catch
767- {
768- // 忽略跨平台对话框启动失败,已在上方输出到 Console
769- }
774+ }
775+ catch
776+ {
777+ // 忽略跨平台对话框启动失败,已在上方输出到 Console
770778 }
771779 }
772780 }
0 commit comments