From bad2313c188cfb942fab2eb3621dc05fc87b209a Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Tue, 26 Aug 2025 21:50:58 +0200 Subject: [PATCH] fix(Program.cs): add try-catch block to handle potential errors when getting the foreground process --- DD2Switcher/Program.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/DD2Switcher/Program.cs b/DD2Switcher/Program.cs index f073870..fe88640 100644 --- a/DD2Switcher/Program.cs +++ b/DD2Switcher/Program.cs @@ -246,10 +246,14 @@ namespace DD2Switcher { } private static void TabToPrevious() { - var foreground = GetForegroundProcess(); - if (!ProcessTracked(foreground.Id)) { - Console.WriteLine("Foreground process not tracked, skipping"); - return; + try { + var foreground = GetForegroundProcess(); + if (!ProcessTracked(foreground.Id)) { + Console.WriteLine("Foreground process not tracked, skipping"); + return; + } + } catch (Exception e) { + Console.WriteLine($"Error setting foreground window: {e}"); } if (lastWindows.Count == 0) { @@ -261,7 +265,7 @@ namespace DD2Switcher { for (int i = lastWindows.Count - 1; i >= 0; i--) { int index = lastWindows[i]; if (index != ActiveIndex) { - TabTo(index+1); // Our windows are 1-indexed because... I don't remember why + TabTo(index + 1); // Our windows are 1-indexed because... I don't remember why break; } }