feat(Program.cs): implement automatic first and last index calculation for sequence mode
This commit is contained in:
@@ -47,6 +47,23 @@ namespace DD2Switcher {
|
||||
|
||||
public static void StartSequenceMode() {
|
||||
Console.WriteLine($"StartSequenceMode called. FirstIndex: {FirstIndex}, LastIndex: {LastIndex}");
|
||||
|
||||
// Compute default indices if not set by user
|
||||
if (FirstIndex == -1 || LastIndex == -1) {
|
||||
FirstIndex = FindFirstNonNullWindow();
|
||||
LastIndex = FindLastNonNullWindow();
|
||||
Console.WriteLine($"Computed default indices: FirstIndex={FirstIndex}, LastIndex={LastIndex}");
|
||||
|
||||
// Ensure LastIndex is different from FirstIndex if there are multiple windows
|
||||
if (FirstIndex != -1 && LastIndex != -1 && FirstIndex == LastIndex) {
|
||||
int nextWindow = FindNextNonNullWindow(FirstIndex + 1);
|
||||
if (nextWindow != -1) {
|
||||
LastIndex = nextWindow;
|
||||
Console.WriteLine($"Adjusted LastIndex to: {LastIndex} (different from FirstIndex)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (FirstIndex >= 0 && LastIndex >= 0 && FirstIndex <= LastIndex) {
|
||||
CurrentState = SequenceState.PROCESSING;
|
||||
CurrentSequenceIndex = FirstIndex;
|
||||
@@ -101,6 +118,8 @@ namespace DD2Switcher {
|
||||
SequenceKeybind = settings.SequenceKeybind;
|
||||
Console.WriteLine(
|
||||
$"Loaded settings: First={FirstIndex}, Last={LastIndex}, Keybind={SequenceKeybind}");
|
||||
} else {
|
||||
Console.WriteLine("No settings file found, using defaults");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Console.WriteLine($"Error loading settings: {ex.Message}");
|
||||
@@ -155,6 +174,16 @@ namespace DD2Switcher {
|
||||
LastIndex = FindLastNonNullWindow();
|
||||
Console.WriteLine($"Set default LastIndex to: {LastIndex}");
|
||||
}
|
||||
|
||||
// Ensure LastIndex is different from FirstIndex if there are multiple windows
|
||||
if (FirstIndex != -1 && LastIndex != -1 && FirstIndex == LastIndex) {
|
||||
// Find the next non-null window after FirstIndex
|
||||
int nextWindow = FindNextNonNullWindow(FirstIndex + 1);
|
||||
if (nextWindow != -1) {
|
||||
LastIndex = nextWindow;
|
||||
Console.WriteLine($"Adjusted LastIndex to: {LastIndex} (different from FirstIndex)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateSequenceHotkey(Keys newKey) {
|
||||
@@ -175,6 +204,10 @@ namespace DD2Switcher {
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
public static void SaveFirstLastIndices() {
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
// Static properties for first/last selection persistence
|
||||
public static int FirstIndex { get; set; } = -1;
|
||||
public static int LastIndex { get; set; } = -1;
|
||||
@@ -371,10 +404,6 @@ namespace DD2Switcher {
|
||||
PushHistory(firstNullIndex);
|
||||
ActiveIndex = firstNullIndex;
|
||||
Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
|
||||
|
||||
// Set default first/last indices if not set
|
||||
SetDefaultFirstLastIndices();
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
private static void TrackProcess() {
|
||||
|
Reference in New Issue
Block a user