修改成即時更新
This commit is contained in:
@@ -17,16 +17,16 @@ public partial class ControlPanel : UserControl
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Init()
|
public async Task Refresh()
|
||||||
{
|
{
|
||||||
await CMMCommand.ScanMonitor();
|
await CMMCommand.ScanMonitor();
|
||||||
var monitors = await CMMCommand.ReadMonitorsData();
|
var monitors = await CMMCommand.ReadMonitorsData();
|
||||||
|
sp.Children.Clear();
|
||||||
|
|
||||||
foreach (var m in monitors)
|
foreach (var m in monitors)
|
||||||
{
|
{
|
||||||
var status = await CMMCommand.GetMonPowerStatus(m.SerialNumber);
|
var status = await CMMCommand.GetMonPowerStatus(m.SerialNumber);
|
||||||
var ctrl = CreatControl(m, status);
|
var ctrl = CreatControl(m, status);
|
||||||
|
|
||||||
sp.Children.Add(ctrl);
|
sp.Children.Add(ctrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ public partial class ControlPanel : UserControl
|
|||||||
|
|
||||||
var tb = new TextBlock
|
var tb = new TextBlock
|
||||||
{
|
{
|
||||||
Text = monitorModel.MonitorName,
|
Text = $"{monitorModel.MonitorName}({monitorModel.SerialNumber})",
|
||||||
HorizontalAlignment = HorizontalAlignment.Left,
|
HorizontalAlignment = HorizontalAlignment.Left,
|
||||||
Style = (Style)FindResource("LableStyle")
|
Style = (Style)FindResource("LableStyle")
|
||||||
};
|
};
|
||||||
@@ -78,6 +78,7 @@ public partial class ControlPanel : UserControl
|
|||||||
{
|
{
|
||||||
await CMMCommand.Sleep(tag);
|
await CMMCommand.Sleep(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
btn!.Content = await CMMCommand.GetMonPowerStatus(tag);
|
btn!.Content = await CMMCommand.GetMonPowerStatus(tag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
xmlns:tb="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification.Net6"
|
xmlns:tb="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification.Net6"
|
||||||
xmlns:local="clr-namespace:DellMonitorControl"
|
xmlns:local="clr-namespace:DellMonitorControl"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Loaded="Window_Loaded"
|
|
||||||
Title="MainWindow" Height="450" Width="800">
|
Title="MainWindow" Height="450" Width="800">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Windows;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
namespace DellMonitorControl;
|
namespace DellMonitorControl;
|
||||||
|
|
||||||
@@ -10,11 +11,12 @@ public partial class MainWindow : Window
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
this.Hide();
|
||||||
|
taskbar.TrayPopupOpen += async (s, e) => await Taskbar_TrayPopupOpen(s, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
private async Task Taskbar_TrayPopupOpen(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
this.Hide();
|
await comtrolPanel.Refresh();
|
||||||
await comtrolPanel.Init();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
using CMM.Library.Helpers;
|
using CMM.Library.Helpers;
|
||||||
using CMM.Library.ViewModel;
|
using CMM.Library.ViewModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.NetworkInformation;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace CMM.Library.Method;
|
namespace CMM.Library.Method;
|
||||||
|
|
||||||
@@ -32,7 +30,10 @@ public static class CMMCommand
|
|||||||
return ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {monitorSN} D6 4");
|
return ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {monitorSN} D6 4");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<string> GetMonitorValue(string monitorSN)
|
private static async Task<string> GetMonitorValue(string monitorSN, int? reTry = 0)
|
||||||
|
{
|
||||||
|
var value = string.Empty;
|
||||||
|
while (reTry <= 5)
|
||||||
{
|
{
|
||||||
var cmdFileName = Path.Combine(CMMTmpFolder, $"{Guid.NewGuid()}.bat");
|
var cmdFileName = Path.Combine(CMMTmpFolder, $"{Guid.NewGuid()}.bat");
|
||||||
var cmd = $"{CMMexe} /GetValue {monitorSN} D6\r\n" +
|
var cmd = $"{CMMexe} /GetValue {monitorSN} D6\r\n" +
|
||||||
@@ -40,7 +41,15 @@ public static class CMMCommand
|
|||||||
File.WriteAllText(cmdFileName, cmd);
|
File.WriteAllText(cmdFileName, cmd);
|
||||||
var values = await ConsoleHelper.ExecuteCommand(cmdFileName);
|
var values = await ConsoleHelper.ExecuteCommand(cmdFileName);
|
||||||
File.Delete(cmdFileName);
|
File.Delete(cmdFileName);
|
||||||
return values.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
|
|
||||||
|
value = values.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(value) && value != "0") return value;
|
||||||
|
await Task.Delay(500);
|
||||||
|
await GetMonitorValue(monitorSN, reTry++);
|
||||||
|
};
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string> GetMonPowerStatus(string monitorSN)
|
public static async Task<string> GetMonPowerStatus(string monitorSN)
|
||||||
|
|||||||
Reference in New Issue
Block a user