test #1
@ -14,7 +14,8 @@ namespace DualScreenDemo
|
||||
public class CommandHandler
|
||||
{
|
||||
public static bool readyForSongListInput = false;
|
||||
|
||||
private readonly int _maxHistoryLength = 6; // 最多保留 6 筆
|
||||
private readonly Queue<string> _indataHistory = new Queue<string>();
|
||||
private readonly SongListManager songListManager;
|
||||
|
||||
public CommandHandler(SongListManager songListManager)
|
||||
@ -25,13 +26,7 @@ namespace DualScreenDemo
|
||||
//關機錨點
|
||||
public async Task ProcessData(string indata)
|
||||
{
|
||||
string filePath = Path.Combine(Application.StartupPath, "dataLog.txt");
|
||||
if (CheckLogForShutdown(filePath))
|
||||
{
|
||||
Console.WriteLine("Shutdown condition met. Application will now close.");
|
||||
ShutdownComputer();
|
||||
}
|
||||
|
||||
AddToHistory(indata);
|
||||
switch (indata)
|
||||
{
|
||||
case "A261A4":
|
||||
@ -188,6 +183,29 @@ namespace DualScreenDemo
|
||||
}
|
||||
}
|
||||
|
||||
private void AddToHistory(string indata)
|
||||
{
|
||||
if (_indataHistory.Count >= _maxHistoryLength)
|
||||
{
|
||||
_indataHistory.Dequeue(); // 移除最舊的項目
|
||||
}
|
||||
_indataHistory.Enqueue(indata); // 添加新的項目
|
||||
CheckSequenceforClose(); // 每次更新完 queue 後檢查
|
||||
}
|
||||
private void CheckSequenceforClose()
|
||||
{
|
||||
string[] targetSequence = { "A262A4", "A262A4", "A262A4", "A261A4", "A261A4", "A261A4" };
|
||||
|
||||
if (_indataHistory.Count == targetSequence.Length &&
|
||||
_indataHistory.SequenceEqual(targetSequence))
|
||||
{
|
||||
// 👇 這裡就是條件符合時要做的事情
|
||||
Console.WriteLine("Shutdown condition met. Application will now close.");
|
||||
ShutdownComputer();
|
||||
// 你可以呼叫其他方法、觸發事件、改狀態等等
|
||||
}
|
||||
}
|
||||
|
||||
void InvokeAction(Action action)
|
||||
{
|
||||
if (OverlayForm.MainForm.InvokeRequired)
|
||||
@ -895,20 +913,6 @@ private static void DisplaySongHistory()
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckLogForShutdown(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
|
||||
string content = File.ReadAllText(filePath).Replace(Environment.NewLine, "");
|
||||
if (content.Length >= 6 && content.Substring(content.Length - 6) == "bbbaaa")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void ShutdownComputer()
|
||||
{
|
||||
try
|
||||
|
Reference in New Issue
Block a user