From 157d90273b202ff490422e39fa374f5cefcb264e Mon Sep 17 00:00:00 2001 From: BruceChen Date: Sun, 29 Mar 2026 01:57:21 +0800 Subject: [PATCH] Handle TUI startup failures with classic fallback --- MinecraftClient/Program.cs | 27 ++++++++++++++++--- .../Translations/Translations.Designer.cs | 27 +++++++++++++++++++ .../Resources/Translations/Translations.resx | 9 +++++++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 946a4d85..8c1e7644 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -177,9 +177,16 @@ namespace MinecraftClient if (!ConsoleIO.BasicIO && Config.Console.General.ConsoleMode == ConsoleModeType.tui) { ConsoleIO.Backend?.Shutdown(); - var tuiBackend = new Tui.TuiConsoleBackend(); - ConsoleIO.Backend = tuiBackend; - tuiBackend.RunTuiMainLoop(args, startupState); + try + { + var tuiBackend = new Tui.TuiConsoleBackend(); + ConsoleIO.Backend = tuiBackend; + tuiBackend.RunTuiMainLoop(args, startupState); + } + catch (Exception ex) + { + HandleTuiStartupFailure(ex); + } return; } @@ -199,6 +206,20 @@ namespace MinecraftClient RunStartupSequence(args); } + private static void HandleTuiStartupFailure(Exception exception) + { + Config.Console.General.ConsoleMode = ConsoleModeType.classic; + WriteBackSettings(enableBackup: false); + + ConsoleIO.Backend = new ClassicConsoleBackend(); + ConsoleIO.Backend.Init(); + + ConsoleIO.WriteLineFormatted("§c" + Translations.mcc_tui_startup_failed); + ConsoleIO.WriteLine(exception.ToString()); + ConsoleIO.WriteLineFormatted("§e" + Translations.mcc_report_issue); + ConsoleIO.WriteLineFormatted("§e" + Translations.mcc_tui_startup_fallback_classic); + } + /// /// Prints the application banner and processes the startup state collected before /// the console backend was ready. Called once from classic mode or from TUI after diff --git a/MinecraftClient/Resources/Translations/Translations.Designer.cs b/MinecraftClient/Resources/Translations/Translations.Designer.cs index 242752e6..96419311 100644 --- a/MinecraftClient/Resources/Translations/Translations.Designer.cs +++ b/MinecraftClient/Resources/Translations/Translations.Designer.cs @@ -5587,6 +5587,33 @@ namespace MinecraftClient { return ResourceManager.GetString("mcc.console_mode_tui_recommendation", resourceCulture); } } + + /// + /// Looks up a localized string similar to MCC encountered a problem while starting TUI mode.. + /// + internal static string mcc_tui_startup_failed { + get { + return ResourceManager.GetString("mcc.tui_startup_failed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to As a fallback, MCC has automatically switched [Console.General] ConsoleMode to "classic". This will take effect after you restart MCC.. + /// + internal static string mcc_tui_startup_fallback_classic { + get { + return ResourceManager.GetString("mcc.tui_startup_fallback_classic", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Please report this issue to the MCC Team.. + /// + internal static string mcc_report_issue { + get { + return ResourceManager.GetString("mcc.report_issue", resourceCulture); + } + } /// /// Looks up a localized string similar to To sign in, open {0} in your browser and enter the code: {1}. diff --git a/MinecraftClient/Resources/Translations/Translations.resx b/MinecraftClient/Resources/Translations/Translations.resx index b028064d..c3ecd406 100644 --- a/MinecraftClient/Resources/Translations/Translations.resx +++ b/MinecraftClient/Resources/Translations/Translations.resx @@ -1881,6 +1881,15 @@ You can use "/chunk status {0:0.0} {1:0.0} {2:0.0}" to check the chunk loading s Tip: try TUI mode for a cleaner interface, mouse-friendly inventory actions, and a nicer layout. Run {0}tryout tui§8 to switch [Console.General] ConsoleMode to "tui" for the next restart. + + MCC encountered a problem while starting TUI mode. + + + As a fallback, MCC has automatically switched [Console.General] ConsoleMode to "classic". This will take effect after you restart MCC. + + + Please report this issue to the MCC Team. + To sign in, open {0} in your browser and enter the code: §e{1}