This commit is contained in:
2025-08-31 22:11:04 +02:00
parent df936e187d
commit 88005c2125
3 changed files with 34 additions and 37 deletions

View File

@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
using System.Threading; using System.Threading;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks;
namespace DD2Switcher { namespace DD2Switcher {
public class Settings { public class Settings {
@@ -71,8 +72,6 @@ namespace DD2Switcher {
} }
} }
public static void ExitSequenceMode() { public static void ExitSequenceMode() {
CurrentState = SequenceState.INACTIVE; CurrentState = SequenceState.INACTIVE;
CurrentSequenceIndex = -1; CurrentSequenceIndex = -1;
@@ -203,12 +202,11 @@ namespace DD2Switcher {
private static bool AltPressed = false; private static bool AltPressed = false;
// State handlers // State handlers
private static readonly Dictionary<SequenceState, Action> stateHandlers = new Dictionary<SequenceState, Action> { private static readonly Dictionary<SequenceState, Action> stateHandlers =
{ SequenceState.INACTIVE, HandleInactive }, new Dictionary<SequenceState, Action> { { SequenceState.INACTIVE, HandleInactive },
{ SequenceState.WAITING_FOR_EVENT, HandleWaitingForEvent }, { SequenceState.WAITING_FOR_EVENT, HandleWaitingForEvent },
{ SequenceState.WAITING_TO_ADVANCE, HandleWaitingToAdvance }, { SequenceState.WAITING_TO_ADVANCE, HandleWaitingToAdvance },
{ SequenceState.ADVANCE, HandleAdvance } { SequenceState.ADVANCE, HandleAdvance } };
};
private static void HandleInactive() { private static void HandleInactive() {
// Inactive state - do nothing // Inactive state - do nothing
@@ -224,18 +222,17 @@ namespace DD2Switcher {
private static void HandleWaitingToAdvance() { private static void HandleWaitingToAdvance() {
// Start timer to advance after N milliseconds // Start timer to advance after N milliseconds
Console.WriteLine($"Starting 500ms timer in WAITING_TO_ADVANCE state"); Console.WriteLine($"Starting 500ms timer in WAITING_TO_ADVANCE state");
Task.Delay(500).ContinueWith(_ => { System.Threading.Thread.Sleep(500);
if (CurrentState == SequenceState.WAITING_TO_ADVANCE) { if (CurrentState == SequenceState.WAITING_TO_ADVANCE) {
CurrentState = SequenceState.ADVANCE; CurrentState = SequenceState.ADVANCE;
Console.WriteLine($"Timer expired, transitioning to ADVANCE state"); Console.WriteLine($"Timer expired, transitioning to ADVANCE state");
HandleSequenceEvent(); HandleSequenceEvent();
} }
});
} }
private static void HandleAdvance() { private static void HandleAdvance() {
Console.WriteLine($"Advancing sequence from ADVANCE state"); Console.WriteLine($"Advancing sequence from ADVANCE state");
CurrentSequenceIndex++; CurrentSequenceIndex++;
Console.WriteLine($"Advanced to index {CurrentSequenceIndex}"); Console.WriteLine($"Advanced to index {CurrentSequenceIndex}");

View File

@@ -16,7 +16,7 @@ namespace DD2Switcher {
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
@@ -31,9 +31,9 @@ namespace DD2Switcher {
this.pickButton = new System.Windows.Forms.Button(); this.pickButton = new System.Windows.Forms.Button();
this.untrackButton = new System.Windows.Forms.Button(); this.untrackButton = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// indexLabel // indexLabel
// //
this.indexLabel.AutoSize = true; this.indexLabel.AutoSize = true;
this.indexLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); this.indexLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.indexLabel.Location = new System.Drawing.Point(10, 5); this.indexLabel.Location = new System.Drawing.Point(10, 5);
@@ -41,9 +41,9 @@ namespace DD2Switcher {
this.indexLabel.Size = new System.Drawing.Size(52, 15); this.indexLabel.Size = new System.Drawing.Size(52, 15);
this.indexLabel.TabIndex = 0; this.indexLabel.TabIndex = 0;
this.indexLabel.Text = "Index: 0"; this.indexLabel.Text = "Index: 0";
// //
// nameLabel // nameLabel
// //
this.nameLabel.AutoSize = true; this.nameLabel.AutoSize = true;
this.nameLabel.Font = new System.Drawing.Font("Segoe UI", 9F); this.nameLabel.Font = new System.Drawing.Font("Segoe UI", 9F);
this.nameLabel.Location = new System.Drawing.Point(12, 35); this.nameLabel.Location = new System.Drawing.Point(12, 35);
@@ -51,9 +51,9 @@ namespace DD2Switcher {
this.nameLabel.Size = new System.Drawing.Size(45, 15); this.nameLabel.Size = new System.Drawing.Size(45, 15);
this.nameLabel.TabIndex = 1; this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name: "; this.nameLabel.Text = "Name: ";
// //
// pidLabel // pidLabel
// //
this.pidLabel.AutoSize = true; this.pidLabel.AutoSize = true;
this.pidLabel.Font = new System.Drawing.Font("Segoe UI", 9F); this.pidLabel.Font = new System.Drawing.Font("Segoe UI", 9F);
this.pidLabel.Location = new System.Drawing.Point(12, 50); this.pidLabel.Location = new System.Drawing.Point(12, 50);
@@ -61,9 +61,9 @@ namespace DD2Switcher {
this.pidLabel.Size = new System.Drawing.Size(28, 15); this.pidLabel.Size = new System.Drawing.Size(28, 15);
this.pidLabel.TabIndex = 2; this.pidLabel.TabIndex = 2;
this.pidLabel.Text = "PID:"; this.pidLabel.Text = "PID:";
// //
// titleLabel // titleLabel
// //
this.titleLabel.AutoSize = true; this.titleLabel.AutoSize = true;
this.titleLabel.Font = new System.Drawing.Font("Segoe UI", 9F); this.titleLabel.Font = new System.Drawing.Font("Segoe UI", 9F);
this.titleLabel.Location = new System.Drawing.Point(12, 20); this.titleLabel.Location = new System.Drawing.Point(12, 20);
@@ -72,9 +72,9 @@ namespace DD2Switcher {
this.titleLabel.Size = new System.Drawing.Size(36, 15); this.titleLabel.Size = new System.Drawing.Size(36, 15);
this.titleLabel.TabIndex = 3; this.titleLabel.TabIndex = 3;
this.titleLabel.Text = "Title: "; this.titleLabel.Text = "Title: ";
// //
// firstLastLabel // firstLastLabel
// //
this.firstLastLabel.AutoSize = true; this.firstLastLabel.AutoSize = true;
this.firstLastLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); this.firstLastLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.firstLastLabel.ForeColor = System.Drawing.Color.DarkBlue; this.firstLastLabel.ForeColor = System.Drawing.Color.DarkBlue;
@@ -82,9 +82,9 @@ namespace DD2Switcher {
this.firstLastLabel.Name = "firstLastLabel"; this.firstLastLabel.Name = "firstLastLabel";
this.firstLastLabel.Size = new System.Drawing.Size(0, 15); this.firstLastLabel.Size = new System.Drawing.Size(0, 15);
this.firstLastLabel.TabIndex = 4; this.firstLastLabel.TabIndex = 4;
// //
// pickButton // pickButton
// //
this.pickButton.Location = new System.Drawing.Point(420, 10); this.pickButton.Location = new System.Drawing.Point(420, 10);
this.pickButton.Name = "pickButton"; this.pickButton.Name = "pickButton";
this.pickButton.Size = new System.Drawing.Size(88, 25); this.pickButton.Size = new System.Drawing.Size(88, 25);
@@ -92,9 +92,9 @@ namespace DD2Switcher {
this.pickButton.Text = "Pick"; this.pickButton.Text = "Pick";
this.pickButton.UseVisualStyleBackColor = true; this.pickButton.UseVisualStyleBackColor = true;
this.pickButton.Click += new System.EventHandler(this.pickButton_Click); this.pickButton.Click += new System.EventHandler(this.pickButton_Click);
// //
// untrackButton // untrackButton
// //
this.untrackButton.Location = new System.Drawing.Point(420, 45); this.untrackButton.Location = new System.Drawing.Point(420, 45);
this.untrackButton.Name = "untrackButton"; this.untrackButton.Name = "untrackButton";
this.untrackButton.Size = new System.Drawing.Size(88, 25); this.untrackButton.Size = new System.Drawing.Size(88, 25);
@@ -102,9 +102,9 @@ namespace DD2Switcher {
this.untrackButton.Text = "Untrack"; this.untrackButton.Text = "Untrack";
this.untrackButton.UseVisualStyleBackColor = true; this.untrackButton.UseVisualStyleBackColor = true;
this.untrackButton.Click += new System.EventHandler(this.untrackButton_Click); this.untrackButton.Click += new System.EventHandler(this.untrackButton_Click);
// //
// WindowPanelForm // WindowPanelForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.indexLabel); this.Controls.Add(this.indexLabel);
@@ -120,7 +120,7 @@ namespace DD2Switcher {
this.PerformLayout(); this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.Label indexLabel; private System.Windows.Forms.Label indexLabel;
private System.Windows.Forms.Label nameLabel; private System.Windows.Forms.Label nameLabel;
@@ -130,4 +130,4 @@ namespace DD2Switcher {
private System.Windows.Forms.Button pickButton; private System.Windows.Forms.Button pickButton;
private System.Windows.Forms.Button untrackButton; private System.Windows.Forms.Button untrackButton;
} }
} }

View File

@@ -23,7 +23,7 @@ namespace DD2Switcher {
nameLabel.Text = $"Name: {WindowProcess.ProcessName}"; nameLabel.Text = $"Name: {WindowProcess.ProcessName}";
pidLabel.Text = $"PID: {WindowProcess.Id}"; pidLabel.Text = $"PID: {WindowProcess.Id}";
titleLabel.Text = $"Title: {WindowProcess.MainWindowTitle}"; titleLabel.Text = $"Title: {WindowProcess.MainWindowTitle}";
if (IsFirst && IsLast) { if (IsFirst && IsLast) {
firstLastLabel.Text = "First & Last"; firstLastLabel.Text = "First & Last";
} else if (IsFirst) { } else if (IsFirst) {
@@ -44,4 +44,4 @@ namespace DD2Switcher {
UntrackClicked?.Invoke(this, WindowIndex); UntrackClicked?.Invoke(this, WindowIndex);
} }
} }
} }