diff --git a/program/Appconfig.cs b/program/Appconfig.cs new file mode 100644 index 0000000..e56a470 --- /dev/null +++ b/program/Appconfig.cs @@ -0,0 +1,9 @@ +using System; +using System.Linq; + +public static class AppConfig +{ + // Computed once, cached forever — reading it anywhere costs nothing. + public static readonly bool DebugMode = + Environment.GetCommandLineArgs().Contains("--debug"); +} \ No newline at end of file diff --git a/program/MainWindow.cs b/program/MainWindow.cs index 65e15cc..9ee24f4 100644 --- a/program/MainWindow.cs +++ b/program/MainWindow.cs @@ -143,9 +143,16 @@ _soundWindow.CaseSelected += OnCaseSelected; - OnArduinoConnectionChanged(false); + // OnArduinoConnectionChanged(false); + + StartAutoDetectOnLoad(); + + if (AppConfig.DebugMode) + this.Title = (this.Title ?? "App") + " [DEBUG MODE]"; } + + // ---------- settings panel ---------- private void OnSettingClicked(object sender, EventArgs e) @@ -174,9 +181,31 @@ RootNoteBook.CurrentPage = PageSplash; } + private async void StartAutoDetectOnLoad() + { + // Lock down splash options until we know the device state. + OnArduinoConnectionChanged(false); + + string found = await _arduino.DetectPortAsync(); + + if (found != null) + _arduino.Connect(found); // fires ConnectionChanged(true) -> unlocks options + else + OnArduinoConnectionChanged(false); // still no device -> stays locked unless debug + } + private void OnArduinoConnectionChanged(bool connected) { _connected = connected; + + // Debug mode bypasses the "device required" restriction entirely. + bool allowFullAccess = connected || AppConfig.DebugMode; + + Option1Button.Sensitive = allowFullAccess; + Option2Button.Sensitive = allowFullAccess; + Option3Button.Sensitive = allowFullAccess; + SettingButton.Sensitive = true; // always reachable, device or not + if (ConnectionIcon == null) return; ConnectionIcon.SetFromIconName(