優化code+註記
This commit is contained in:
parent
d57de0b616
commit
780d851647
@ -16,32 +16,19 @@ namespace DualScreenDemo
|
||||
{
|
||||
this.songListManager = songListManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 遙控器接收資料
|
||||
/// </summary>
|
||||
public async Task ProcessData(string indata)
|
||||
{ //關機錨點
|
||||
/*string filePath = Path.Combine(Application.StartupPath, "dataLog.txt");
|
||||
// 使用 Path.Combine 方法安全地將應用程式的啟動路徑與 "dataLog.txt" 檔案名結合,
|
||||
// 建立完整的檔案路徑。Application.StartupPath 通常指向應用程式的可執行檔所在的目錄。
|
||||
|
||||
if (CheckLogForShutdown(filePath))
|
||||
// 呼叫 CheckLogForShutdown 方法,並將建立的檔案路徑 (filePath) 作為參數傳遞。
|
||||
// 這個方法預期會檢查指定的日誌檔案內容,以判斷是否符合關機的條件。
|
||||
// 如果該方法回傳 true (表示符合關機條件),則執行 if 區塊內的程式碼。
|
||||
{
|
||||
Console.WriteLine("Shutdown condition met. Application will now close.");
|
||||
// 在控制台輸出訊息,告知使用者已滿足關機條件,應用程式即將關閉。
|
||||
ShutdownComputer();
|
||||
// 呼叫 ShutdownComputer 方法,這個方法預期會執行關閉電腦的操作。
|
||||
}*/
|
||||
|
||||
{
|
||||
AddToHistory(indata);
|
||||
|
||||
switch (indata)
|
||||
{
|
||||
case "A261A4":
|
||||
case "A261A4": // 輸入
|
||||
HandleInputA();
|
||||
break;
|
||||
case "A262A4":
|
||||
case "A262A4": // 插播
|
||||
HandleInputB();
|
||||
break;
|
||||
case "A263A4":
|
||||
@ -442,97 +429,79 @@ namespace DualScreenDemo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除 OverlayForm 上除特定保留控制項外的所有控制項,並重設顯示狀態
|
||||
/// </summary>
|
||||
private static void ClearDisplay()
|
||||
{
|
||||
|
||||
// 停止顯示用的計時器
|
||||
OverlayForm.displayTimer.Stop();
|
||||
|
||||
|
||||
|
||||
// 判斷是否需要透過 Invoke 回 UI 執行緒執行
|
||||
if (OverlayForm.MainForm.InvokeRequired)
|
||||
{
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() =>
|
||||
{
|
||||
|
||||
foreach (var control in OverlayForm.MainForm.Controls.OfType<Control>().ToArray())
|
||||
{
|
||||
if (control != OverlayForm.MainForm.displayLabel &&
|
||||
control != OverlayForm.MainForm.pauseLabel &&
|
||||
control != OverlayForm.MainForm.muteLabel &&
|
||||
control != OverlayForm.MainForm.volumeUpLabel &&
|
||||
control != OverlayForm.MainForm.volumeDownLabel &&
|
||||
control != OverlayForm.MainForm.micUpLabel &&
|
||||
control != OverlayForm.MainForm.micDownLabel &&
|
||||
control != OverlayForm.MainForm.standardKeyLabel &&
|
||||
control != OverlayForm.MainForm.keyUpLabel &&
|
||||
control != OverlayForm.MainForm.keyDownLabel &&
|
||||
control != OverlayForm.MainForm.maleKeyLabel &&
|
||||
control != OverlayForm.MainForm.femaleKeyLabel &&
|
||||
control != OverlayForm.MainForm.squareLabel &&
|
||||
control != OverlayForm.MainForm.professionalLabel &&
|
||||
control != OverlayForm.MainForm.standardLabel &&
|
||||
control != OverlayForm.MainForm.singDownLabel &&
|
||||
control != OverlayForm.MainForm.brightLabel &&
|
||||
control != OverlayForm.MainForm.softLabel &&
|
||||
control != OverlayForm.MainForm.autoLabel &&
|
||||
control != OverlayForm.MainForm.romanticLabel &&
|
||||
control != OverlayForm.MainForm.dynamicLabel &&
|
||||
control != OverlayForm.MainForm.tintLabel &&
|
||||
control != OverlayForm.MainForm.blackBackgroundPanel &&
|
||||
control != OverlayForm.MainForm.nextSongLabel)
|
||||
{
|
||||
OverlayForm.MainForm.Controls.Remove(control);
|
||||
control.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
OverlayForm.MainForm.displayLabel.Text = "";
|
||||
readyForSongListInput = false;
|
||||
OverlayForm.SetUIState(OverlayForm.UIState.Initial);
|
||||
Console.WriteLine(OverlayForm.MainForm.displayLabel.Text);
|
||||
}));
|
||||
OverlayForm.MainForm.Invoke(new Action(ClearControlsAndReset));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
foreach (var control in OverlayForm.MainForm.Controls.OfType<Control>().ToArray())
|
||||
{
|
||||
if (control != OverlayForm.MainForm.displayLabel &&
|
||||
control != OverlayForm.MainForm.pauseLabel &&
|
||||
control != OverlayForm.MainForm.muteLabel &&
|
||||
control != OverlayForm.MainForm.volumeUpLabel &&
|
||||
control != OverlayForm.MainForm.volumeDownLabel &&
|
||||
control != OverlayForm.MainForm.micUpLabel &&
|
||||
control != OverlayForm.MainForm.micDownLabel &&
|
||||
control != OverlayForm.MainForm.standardKeyLabel &&
|
||||
control != OverlayForm.MainForm.keyUpLabel &&
|
||||
control != OverlayForm.MainForm.keyDownLabel &&
|
||||
control != OverlayForm.MainForm.maleKeyLabel &&
|
||||
control != OverlayForm.MainForm.femaleKeyLabel &&
|
||||
control != OverlayForm.MainForm.squareLabel &&
|
||||
control != OverlayForm.MainForm.professionalLabel &&
|
||||
control != OverlayForm.MainForm.standardLabel &&
|
||||
control != OverlayForm.MainForm.singDownLabel &&
|
||||
control != OverlayForm.MainForm.brightLabel &&
|
||||
control != OverlayForm.MainForm.softLabel &&
|
||||
control != OverlayForm.MainForm.autoLabel &&
|
||||
control != OverlayForm.MainForm.romanticLabel &&
|
||||
control != OverlayForm.MainForm.dynamicLabel &&
|
||||
control != OverlayForm.MainForm.tintLabel &&
|
||||
control != OverlayForm.MainForm.blackBackgroundPanel &&
|
||||
control != OverlayForm.MainForm.nextSongLabel)
|
||||
{
|
||||
OverlayForm.MainForm.Controls.Remove(control);
|
||||
control.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
OverlayForm.MainForm.displayLabel.Text = "";
|
||||
Console.WriteLine("ClearDisplay called.");
|
||||
readyForSongListInput = false;
|
||||
OverlayForm.SetUIState(OverlayForm.UIState.Initial);
|
||||
Console.WriteLine(OverlayForm.MainForm.displayLabel.Text);
|
||||
ClearControlsAndReset();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 實際執行移除不需要的控制項並重設 UI 狀態
|
||||
/// </summary>
|
||||
private static void ClearControlsAndReset()
|
||||
{
|
||||
// 保留不刪除的控制項列表
|
||||
var preservedControls = new HashSet<Control>
|
||||
{
|
||||
OverlayForm.MainForm.displayLabel,
|
||||
OverlayForm.MainForm.pauseLabel,
|
||||
OverlayForm.MainForm.muteLabel,
|
||||
OverlayForm.MainForm.volumeUpLabel,
|
||||
OverlayForm.MainForm.volumeDownLabel,
|
||||
OverlayForm.MainForm.micUpLabel,
|
||||
OverlayForm.MainForm.micDownLabel,
|
||||
OverlayForm.MainForm.standardKeyLabel,
|
||||
OverlayForm.MainForm.keyUpLabel,
|
||||
OverlayForm.MainForm.keyDownLabel,
|
||||
OverlayForm.MainForm.maleKeyLabel,
|
||||
OverlayForm.MainForm.femaleKeyLabel,
|
||||
OverlayForm.MainForm.squareLabel,
|
||||
OverlayForm.MainForm.professionalLabel,
|
||||
OverlayForm.MainForm.standardLabel,
|
||||
OverlayForm.MainForm.singDownLabel,
|
||||
OverlayForm.MainForm.brightLabel,
|
||||
OverlayForm.MainForm.softLabel,
|
||||
OverlayForm.MainForm.autoLabel,
|
||||
OverlayForm.MainForm.romanticLabel,
|
||||
OverlayForm.MainForm.dynamicLabel,
|
||||
OverlayForm.MainForm.tintLabel,
|
||||
OverlayForm.MainForm.blackBackgroundPanel,
|
||||
OverlayForm.MainForm.nextSongLabel
|
||||
};
|
||||
|
||||
// 將所有不在保留清單內的控制項移除並釋放資源
|
||||
foreach (var control in OverlayForm.MainForm.Controls.OfType<Control>().ToArray())
|
||||
{
|
||||
if (!preservedControls.Contains(control))
|
||||
{
|
||||
OverlayForm.MainForm.Controls.Remove(control);
|
||||
control.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// 清空主顯示區的文字
|
||||
OverlayForm.MainForm.displayLabel.Text = "";
|
||||
Console.WriteLine("ClearDisplay called.");
|
||||
|
||||
// 重設狀態標記與 UI 狀態
|
||||
readyForSongListInput = false;
|
||||
OverlayForm.SetUIState(OverlayForm.UIState.Initial);
|
||||
Console.WriteLine("Display cleared.");
|
||||
}
|
||||
|
||||
private static void DisplaySongHistory()
|
||||
{
|
||||
ClearDisplay();
|
||||
|
Loading…
x
Reference in New Issue
Block a user