Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 89c922c265 | |||
| 38f5aa325c | |||
| ac53fbf80e | |||
| 139be6f779 | |||
| dfec8c07b5 | |||
| bd7a58a5fe | |||
| af8b09cfa2 | |||
| 77e9b0505a | |||
| 526974da24 | |||
| b7597fd4d0 | |||
| 260379a330 | |||
| e189731d24 | |||
| c6a2b5b22f | |||
| c394320a3e |
@@ -17,19 +17,32 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '9.0.x'
|
||||
|
||||
- name: Update version in project files
|
||||
shell: powershell
|
||||
run: |
|
||||
$version = "${{ gitea.ref_name }}".TrimStart("v")
|
||||
Write-Host "Setting version to: $version"
|
||||
|
||||
# Update csproj (preserve UTF-8 BOM encoding)
|
||||
$csprojPath = "DellMonitorControl/DellMonitorControl.csproj"
|
||||
$content = [System.IO.File]::ReadAllText($csprojPath)
|
||||
$content = $content -replace '<Version>.*</Version>', "<Version>$version</Version>"
|
||||
$content = $content -replace '<AssemblyVersion>.*</AssemblyVersion>', "<AssemblyVersion>$version.0</AssemblyVersion>"
|
||||
$content = $content -replace '<FileVersion>.*</FileVersion>', "<FileVersion>$version.0</FileVersion>"
|
||||
[System.IO.File]::WriteAllText($csprojPath, $content, [System.Text.UTF8Encoding]::new($true))
|
||||
|
||||
# Update ISS
|
||||
$issPath = "DellMonitorControl/MonitorControl.iss"
|
||||
$issContent = [System.IO.File]::ReadAllText($issPath)
|
||||
$issContent = $issContent -replace '#define MyAppVersion ".*"', "#define MyAppVersion `"$version`""
|
||||
[System.IO.File]::WriteAllText($issPath, $issContent, [System.Text.UTF8Encoding]::new($true))
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build Release
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
|
||||
- name: Update version in ISS
|
||||
shell: powershell
|
||||
run: |
|
||||
$version = "${{ gitea.ref_name }}".TrimStart("v")
|
||||
$issPath = "DellMonitorControl/MonitorControl.iss"
|
||||
(Get-Content $issPath) -replace '#define MyAppVersion ".*"', "#define MyAppVersion `"$version`"" | Set-Content $issPath
|
||||
|
||||
- name: List build output
|
||||
shell: cmd
|
||||
run: |
|
||||
@@ -69,6 +82,17 @@ jobs:
|
||||
echo Installer directory contents:
|
||||
dir installer
|
||||
|
||||
- name: Create Portable Zip
|
||||
shell: powershell
|
||||
run: |
|
||||
$version = "${{ gitea.ref_name }}".TrimStart("v")
|
||||
$buildDir = "DellMonitorControl\bin\Release\net9.0-windows"
|
||||
$zipName = "MonitorControl-Portable-$version.zip"
|
||||
|
||||
Write-Host "Creating portable zip: $zipName"
|
||||
Compress-Archive -Path "$buildDir\*" -DestinationPath $zipName -Force
|
||||
Write-Host "Zip created successfully"
|
||||
|
||||
- name: Create Release
|
||||
shell: powershell
|
||||
env:
|
||||
@@ -91,7 +115,7 @@ jobs:
|
||||
$body = @{
|
||||
tag_name = $tag
|
||||
name = "Monitor Control $tag"
|
||||
body = "## Monitor Control $tag`n`n### Installation`nDownload and run the installer.`n`n### Features`n- System tray monitor control`n- Brightness/Contrast adjustment`n- Input source switching`n- Quick-switch toolbar`n`n### Requirements`n- Windows 10/11`n- .NET 9.0 Runtime"
|
||||
body = "## Monitor Control $tag`n`n### Installation`n- **Installer**: Download and run the setup exe`n- **Portable**: Download the zip, extract anywhere, and run DellMonitorControl.exe`n`n### Features`n- System tray monitor control`n- Brightness/Contrast adjustment`n- Input source switching`n- Quick-switch toolbar`n`n### Requirements`n- Windows 10/11`n- .NET 9.0 Runtime"
|
||||
} | ConvertTo-Json
|
||||
|
||||
$release = Invoke-RestMethod -Uri "$baseUrl/repos/$repo/releases" -Method Post -Headers @{"Authorization"="token $env:GITEA_TOKEN"; "Content-Type"="application/json"} -Body $body
|
||||
@@ -100,10 +124,15 @@ jobs:
|
||||
}
|
||||
|
||||
# Upload installer
|
||||
$filePath = "C:\build\app\installer\MonitorControl-Setup-$version.exe"
|
||||
$fileName = "MonitorControl-Setup-$version.exe"
|
||||
Write-Host "Uploading $fileName..."
|
||||
$installerPath = "C:\build\app\installer\MonitorControl-Setup-$version.exe"
|
||||
$installerName = "MonitorControl-Setup-$version.exe"
|
||||
Write-Host "Uploading $installerName..."
|
||||
curl.exe -X POST -H "Authorization: token $env:GITEA_TOKEN" -F "attachment=@$installerPath" "$baseUrl/repos/$repo/releases/$releaseId/assets?name=$installerName"
|
||||
|
||||
curl.exe -X POST -H "Authorization: token $env:GITEA_TOKEN" -F "attachment=@$filePath" "$baseUrl/repos/$repo/releases/$releaseId/assets?name=$fileName"
|
||||
# Upload portable zip
|
||||
$zipPath = "MonitorControl-Portable-$version.zip"
|
||||
$zipName = "MonitorControl-Portable-$version.zip"
|
||||
Write-Host "Uploading $zipName..."
|
||||
curl.exe -X POST -H "Authorization: token $env:GITEA_TOKEN" -F "attachment=@$zipPath" "$baseUrl/repos/$repo/releases/$releaseId/assets?name=$zipName"
|
||||
|
||||
Write-Host "Installer uploaded successfully"
|
||||
Write-Host "All assets uploaded successfully"
|
||||
|
||||
@@ -7,13 +7,42 @@ namespace DellMonitorControl
|
||||
{
|
||||
private TaskbarIcon? _trayIcon;
|
||||
private MainWindow? _mainWindow;
|
||||
private UpdateInfo? _pendingUpdate;
|
||||
|
||||
private void Application_Startup(object sender, StartupEventArgs e)
|
||||
private async void Application_Startup(object sender, StartupEventArgs e)
|
||||
{
|
||||
_trayIcon = (TaskbarIcon)FindResource("TrayIcon");
|
||||
_trayIcon.TrayLeftMouseUp += TrayIcon_Click;
|
||||
_trayIcon.TrayBalloonTipClicked += TrayIcon_BalloonTipClicked;
|
||||
|
||||
_mainWindow = new MainWindow();
|
||||
|
||||
// Check for updates in background
|
||||
await CheckForUpdatesAsync();
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task CheckForUpdatesAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_pendingUpdate = await UpdateChecker.CheckForUpdateAsync();
|
||||
if (_pendingUpdate != null && _trayIcon != null)
|
||||
{
|
||||
_trayIcon.ShowBalloonTip(
|
||||
"Update Available",
|
||||
$"Monitor Control v{_pendingUpdate.LatestVersion} is available.\nClick to download.",
|
||||
BalloonIcon.Info);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void TrayIcon_BalloonTipClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_pendingUpdate != null && !string.IsNullOrEmpty(_pendingUpdate.DownloadUrl))
|
||||
{
|
||||
UpdateChecker.OpenDownloadPage(_pendingUpdate.DownloadUrl);
|
||||
}
|
||||
}
|
||||
|
||||
private async void TrayIcon_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -34,6 +34,22 @@ public partial class ConfigWindow : Window
|
||||
spPorts.Children.Clear();
|
||||
_portRows.Clear();
|
||||
|
||||
// Show unsupported message if no ports available
|
||||
if (_availablePorts == null || _availablePorts.Count == 0)
|
||||
{
|
||||
spPorts.Children.Add(new TextBlock
|
||||
{
|
||||
Text = "Unsupported",
|
||||
Foreground = Brushes.Gray,
|
||||
FontSize = 16,
|
||||
FontStyle = FontStyles.Italic,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Margin = new Thickness(0, 40, 0, 40)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var port in _availablePorts)
|
||||
{
|
||||
var existingPortConfig = config.Ports.FirstOrDefault(p => p.VcpValue == port.Value);
|
||||
|
||||
@@ -8,21 +8,16 @@
|
||||
<RootNamespace>DellMonitorControl</RootNamespace>
|
||||
<Product>ControlMyMonitorManagement</Product>
|
||||
<UseWPF>true</UseWPF>
|
||||
<Company>Dang</Company>
|
||||
<Copyright>Copyright © DangWang $([System.DateTime]::Now.ToString(yyyy))</Copyright>
|
||||
<Company>MarketAlly</Company>
|
||||
<Authors>David H. Friedel Jr</Authors>
|
||||
<Copyright>Copyright © MarketAlly $([System.DateTime]::Now.ToString(yyyy))</Copyright>
|
||||
<ApplicationIcon>MonitorIcon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<Major>1</Major>
|
||||
<Minor>0</Minor>
|
||||
<ProjectStartedDate>$([System.DateTime]::op_Subtraction($([System.DateTime]::get_Now().get_Date()),$([System.DateTime]::new(2023,7,2))).get_TotalDays())</ProjectStartedDate>
|
||||
<DaysSinceProjectStarted>$([System.DateTime]::Now.ToString(Hmm))</DaysSinceProjectStarted>
|
||||
<DateTimeSuffix>$([System.DateTime]::Now.ToString(yyyyMMdd))</DateTimeSuffix>
|
||||
<VersionSuffix>$(Major).$(Minor).$(ProjectStartedDate).$(DaysSinceProjectStarted)</VersionSuffix>
|
||||
<AssemblyVersion Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</AssemblyVersion>
|
||||
<AssemblyVersion Condition=" '$(DateTimeSuffix)' != '' ">$(VersionSuffix)</AssemblyVersion>
|
||||
<Version Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</Version>
|
||||
<Version Condition=" '$(DateTimeSuffix)' != '' ">$(DateTimeSuffix)</Version>
|
||||
<PropertyGroup>
|
||||
<Version>1.1.0</Version>
|
||||
<AssemblyVersion>1.1.0.0</AssemblyVersion>
|
||||
<FileVersion>1.1.0.0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -181,6 +181,15 @@ public partial class MainWindow : Window
|
||||
var inputOptions = await CMMCommand.GetInputSourceOptions(m.SerialNumber);
|
||||
DebugLogger.Log($" Input options count: {inputOptions.Count}");
|
||||
|
||||
// Some monitors don't report current input in their possible values list
|
||||
// Add it if missing so user can see what's currently selected
|
||||
if (inputSource.HasValue && !inputOptions.Any(o => o.Value == inputSource.Value))
|
||||
{
|
||||
var currentInputName = CMMCommand.GetInputSourceName(inputSource.Value);
|
||||
inputOptions.Insert(0, new InputSourceOption(inputSource.Value, currentInputName));
|
||||
DebugLogger.Log($" Added missing current input: {inputSource.Value} ({currentInputName})");
|
||||
}
|
||||
|
||||
DebugLogger.Log($" Getting power status...");
|
||||
var powerStatus = await CMMCommand.GetMonPowerStatus(m.SerialNumber) ?? "Unknown";
|
||||
DebugLogger.Log($" Power status: {powerStatus}");
|
||||
@@ -188,7 +197,8 @@ public partial class MainWindow : Window
|
||||
_loadedMonitors.Add((m, inputOptions));
|
||||
|
||||
// Apply config to filter hidden ports and use custom labels
|
||||
var filteredOptions = MonitorConfigManager.ApplyConfigToOptions(m.SerialNumber, inputOptions);
|
||||
// Pass currentInput so we never hide the currently active port
|
||||
var filteredOptions = MonitorConfigManager.ApplyConfigToOptions(m.SerialNumber, inputOptions, inputSource);
|
||||
DebugLogger.Log($" Filtered options count: {filteredOptions.Count}");
|
||||
|
||||
// Monitor name header with Config button
|
||||
@@ -371,6 +381,10 @@ public partial class MainWindow : Window
|
||||
|
||||
private StackPanel CreateInputRow(int? currentInput, List<InputSourceOption> options, string serialNumber)
|
||||
{
|
||||
DebugLogger.Log($" CreateInputRow: currentInput={currentInput}, optionCount={options.Count}");
|
||||
foreach (var opt in options)
|
||||
DebugLogger.Log($" Option: Value={opt.Value}, Name={opt.Name}");
|
||||
|
||||
var row = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 3, 0, 3) };
|
||||
row.Children.Add(new TextBlock { Text = "Input", Foreground = Brushes.LightGray, Width = 70, FontSize = 12, VerticalAlignment = VerticalAlignment.Center });
|
||||
|
||||
@@ -390,9 +404,14 @@ public partial class MainWindow : Window
|
||||
if (currentInput.HasValue)
|
||||
{
|
||||
var index = options.FindIndex(o => o.Value == currentInput.Value);
|
||||
DebugLogger.Log($" Selection: Looking for Value={currentInput.Value}, found at index={index}");
|
||||
if (index >= 0)
|
||||
combo.SelectedIndex = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLogger.Log($" Selection: currentInput is null, no selection");
|
||||
}
|
||||
|
||||
// Add event handler AFTER setting the initial selection
|
||||
combo.SelectionChanged += async (s, e) =>
|
||||
@@ -410,26 +429,33 @@ public partial class MainWindow : Window
|
||||
var row = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 3, 0, 3) };
|
||||
row.Children.Add(new TextBlock { Text = "Power", Foreground = Brushes.LightGray, Width = 70, FontSize = 12, VerticalAlignment = VerticalAlignment.Center });
|
||||
|
||||
var isUnsupported = string.IsNullOrEmpty(status) || status == "Unknown";
|
||||
|
||||
var btn = new Button
|
||||
{
|
||||
Content = status,
|
||||
Content = isUnsupported ? "Power Unsupported" : status,
|
||||
Width = 170,
|
||||
Tag = serialNumber,
|
||||
Style = (Style)FindResource("DarkButton")
|
||||
Style = (Style)FindResource("DarkButton"),
|
||||
IsEnabled = !isUnsupported
|
||||
};
|
||||
btn.Click += async (s, e) =>
|
||||
|
||||
if (!isUnsupported)
|
||||
{
|
||||
if (s is Button b && b.Tag is string sn)
|
||||
btn.Click += async (s, e) =>
|
||||
{
|
||||
var current = await CMMCommand.GetMonPowerStatus(sn);
|
||||
if (current == "Sleep" || current == "PowerOff")
|
||||
await CMMCommand.PowerOn(sn);
|
||||
else
|
||||
await CMMCommand.Sleep(sn);
|
||||
await Task.Delay(1000);
|
||||
b.Content = await CMMCommand.GetMonPowerStatus(sn);
|
||||
}
|
||||
};
|
||||
if (s is Button b && b.Tag is string sn)
|
||||
{
|
||||
var current = await CMMCommand.GetMonPowerStatus(sn);
|
||||
if (current == "Sleep" || current == "PowerOff")
|
||||
await CMMCommand.PowerOn(sn);
|
||||
else
|
||||
await CMMCommand.Sleep(sn);
|
||||
await Task.Delay(1000);
|
||||
b.Content = await CMMCommand.GetMonPowerStatus(sn);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
row.Children.Add(btn);
|
||||
return row;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#define MyAppName "Monitor Control"
|
||||
#define MyAppVersion "1.0.0"
|
||||
#define MyAppPublisher "Dang"
|
||||
#define MyAppVersion "1.1.0"
|
||||
#define MyAppPublisher "MarketAlly"
|
||||
#define MyAppExeName "DellMonitorControl.exe"
|
||||
#define MyAppIcon "MonitorIcon.ico"
|
||||
#define SourcePath "bin\Release\net9.0-windows"
|
||||
|
||||
[Setup]
|
||||
@@ -19,6 +20,7 @@ Compression=lzma
|
||||
SolidCompression=yes
|
||||
WizardStyle=modern
|
||||
PrivilegesRequired=admin
|
||||
SetupIconFile={#MyAppIcon}
|
||||
UninstallDisplayIcon={app}\{#MyAppExeName}
|
||||
|
||||
[Languages]
|
||||
@@ -30,12 +32,13 @@ Name: "startupicon"; Description: "Start with Windows"; GroupDescription: "Start
|
||||
|
||||
[Files]
|
||||
Source: "bin\Release\net9.0-windows\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||
Source: "{#MyAppIcon}"; DestDir: "{app}"; Flags: ignoreversion
|
||||
|
||||
[Icons]
|
||||
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
|
||||
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\{#MyAppIcon}"
|
||||
Name: "{group}\Uninstall {#MyAppName}"; Filename: "{uninstallexe}"
|
||||
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
|
||||
Name: "{userstartup}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: startupicon
|
||||
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\{#MyAppIcon}"; Tasks: desktopicon
|
||||
Name: "{userstartup}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\{#MyAppIcon}"; Tasks: startupicon
|
||||
|
||||
[Run]
|
||||
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
|
||||
|
||||
119
DellMonitorControl/UpdateChecker.cs
Normal file
119
DellMonitorControl/UpdateChecker.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DellMonitorControl;
|
||||
|
||||
public class UpdateChecker
|
||||
{
|
||||
private const string ReleasesApiUrl = "https://git.marketally.com/api/v1/repos/misc/ControlMyMonitorManagement/releases/latest";
|
||||
private static readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromSeconds(10) };
|
||||
|
||||
public static Version CurrentVersion => Assembly.GetExecutingAssembly().GetName().Version ?? new Version(1, 0, 0);
|
||||
|
||||
public static async Task<UpdateInfo?> CheckForUpdateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
DebugLogger.Log($"Checking for updates... Current version: {CurrentVersion}");
|
||||
|
||||
var response = await _httpClient.GetStringAsync(ReleasesApiUrl);
|
||||
var release = JsonSerializer.Deserialize<GiteaRelease>(response);
|
||||
|
||||
if (release == null || string.IsNullOrEmpty(release.tag_name))
|
||||
{
|
||||
DebugLogger.Log("No release info found");
|
||||
return null;
|
||||
}
|
||||
|
||||
var latestVersionStr = release.tag_name.TrimStart('v', 'V');
|
||||
if (!Version.TryParse(latestVersionStr, out var latestVersion))
|
||||
{
|
||||
DebugLogger.Log($"Could not parse version: {release.tag_name}");
|
||||
return null;
|
||||
}
|
||||
|
||||
DebugLogger.Log($"Latest version: {latestVersion}");
|
||||
|
||||
if (latestVersion > CurrentVersion)
|
||||
{
|
||||
// Find the installer asset
|
||||
string? downloadUrl = null;
|
||||
if (release.assets != null)
|
||||
{
|
||||
foreach (var asset in release.assets)
|
||||
{
|
||||
if (asset.name?.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) == true)
|
||||
{
|
||||
downloadUrl = asset.browser_download_url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to release page if no direct download
|
||||
downloadUrl ??= release.html_url;
|
||||
|
||||
DebugLogger.Log($"Update available: {latestVersion}, URL: {downloadUrl}");
|
||||
|
||||
return new UpdateInfo
|
||||
{
|
||||
CurrentVersion = CurrentVersion,
|
||||
LatestVersion = latestVersion,
|
||||
DownloadUrl = downloadUrl ?? "",
|
||||
ReleaseNotes = release.body ?? ""
|
||||
};
|
||||
}
|
||||
|
||||
DebugLogger.Log("No update available");
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DebugLogger.LogError("Update check failed", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenDownloadPage(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = url,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DebugLogger.LogError("Failed to open download page", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateInfo
|
||||
{
|
||||
public Version CurrentVersion { get; set; } = new(1, 0, 0);
|
||||
public Version LatestVersion { get; set; } = new(1, 0, 0);
|
||||
public string DownloadUrl { get; set; } = "";
|
||||
public string ReleaseNotes { get; set; } = "";
|
||||
}
|
||||
|
||||
public class GiteaRelease
|
||||
{
|
||||
public string? tag_name { get; set; }
|
||||
public string? name { get; set; }
|
||||
public string? body { get; set; }
|
||||
public string? html_url { get; set; }
|
||||
public GiteaAsset[]? assets { get; set; }
|
||||
}
|
||||
|
||||
public class GiteaAsset
|
||||
{
|
||||
public string? name { get; set; }
|
||||
public string? browser_download_url { get; set; }
|
||||
}
|
||||
@@ -86,7 +86,8 @@ public static class MonitorConfigManager
|
||||
|
||||
public static List<InputSourceOption> ApplyConfigToOptions(
|
||||
string serialNumber,
|
||||
List<InputSourceOption> options)
|
||||
List<InputSourceOption> options,
|
||||
int? currentInput = null)
|
||||
{
|
||||
var monitorConfig = GetMonitorConfig(serialNumber);
|
||||
|
||||
@@ -101,8 +102,11 @@ public static class MonitorConfigManager
|
||||
|
||||
if (portConfig != null)
|
||||
{
|
||||
// Respect hidden setting - don't show hidden ports
|
||||
if (portConfig.IsHidden)
|
||||
// Never hide the currently active input - user needs to see what's selected
|
||||
bool isCurrentInput = currentInput.HasValue && option.Value == currentInput.Value;
|
||||
|
||||
// Respect hidden setting - don't show hidden ports (unless it's the current input)
|
||||
if (portConfig.IsHidden && !isCurrentInput)
|
||||
continue;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(portConfig.CustomLabel))
|
||||
|
||||
@@ -19,7 +19,7 @@ internal class ConsoleHelper
|
||||
}
|
||||
};
|
||||
|
||||
public static async Task<string> ExecuteCommand(string command)
|
||||
public static async Task<string> ExecuteCommand(string command, int timeoutMs = 5000)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
@@ -27,10 +27,18 @@ internal class ConsoleHelper
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.FileName = command;
|
||||
p.Start();
|
||||
var output = await p.StandardOutput.ReadToEndAsync();
|
||||
await p.WaitForExitAsync();
|
||||
|
||||
return output;
|
||||
var readTask = p.StandardOutput.ReadToEndAsync();
|
||||
var completedTask = await Task.WhenAny(readTask, Task.Delay(timeoutMs));
|
||||
|
||||
if (completedTask != readTask)
|
||||
{
|
||||
// Timeout - kill the process
|
||||
try { p.Kill(true); } catch { }
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return await readTask;
|
||||
}
|
||||
|
||||
public static async Task<string> CmdCommandAsync(params string[] cmds) =>
|
||||
@@ -40,6 +48,11 @@ internal class ConsoleHelper
|
||||
Command(cmdFileName, cmds);
|
||||
|
||||
public static async Task<string> CommandAsync(string fileName, params string[] cmds)
|
||||
{
|
||||
return await CommandAsync(fileName, 5000, cmds);
|
||||
}
|
||||
|
||||
public static async Task<string> CommandAsync(string fileName, int timeoutMs, params string[] cmds)
|
||||
{
|
||||
var p = CreatProcess(fileName);
|
||||
p.Start();
|
||||
@@ -48,14 +61,29 @@ internal class ConsoleHelper
|
||||
p.StandardInput.WriteLine(cmd);
|
||||
}
|
||||
p.StandardInput.WriteLine("exit");
|
||||
var result = await p.StandardOutput.ReadToEndAsync();
|
||||
var error = await p.StandardError.ReadToEndAsync();
|
||||
if (!string.IsNullOrWhiteSpace(error))
|
||||
result = result + "\r\n<Error Message>:\r\n" + error;
|
||||
await p.WaitForExitAsync();
|
||||
|
||||
var readTask = Task.Run(async () =>
|
||||
{
|
||||
var result = await p.StandardOutput.ReadToEndAsync();
|
||||
var error = await p.StandardError.ReadToEndAsync();
|
||||
if (!string.IsNullOrWhiteSpace(error))
|
||||
result = result + "\r\n<Error Message>:\r\n" + error;
|
||||
return result;
|
||||
});
|
||||
|
||||
var completedTask = await Task.WhenAny(readTask, Task.Delay(timeoutMs));
|
||||
|
||||
if (completedTask != readTask)
|
||||
{
|
||||
// Timeout - kill the process
|
||||
try { p.Kill(true); } catch { }
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var output = await readTask;
|
||||
p.Close();
|
||||
Debug.WriteLine(result);
|
||||
return result;
|
||||
Debug.WriteLine(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
public static string Command(string fileName, params string[] cmds)
|
||||
|
||||
@@ -30,26 +30,32 @@ public static class CMMCommand
|
||||
return ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {monitorSN} D6 4");
|
||||
}
|
||||
|
||||
private static async Task<string> GetMonitorValue(string monitorSN, string vcpCode = "D6", int? reTry = 0)
|
||||
private static async Task<string> GetMonitorValue(string monitorSN, string vcpCode = "D6", int maxRetries = 2)
|
||||
{
|
||||
var value = string.Empty;
|
||||
while (reTry <= 5)
|
||||
for (int attempt = 0; attempt <= maxRetries; attempt++)
|
||||
{
|
||||
var cmdFileName = Path.Combine(CMMTmpFolder, $"{Guid.NewGuid()}.bat");
|
||||
var cmd = $"{CMMexe} /GetValue {monitorSN} {vcpCode}\r\n" +
|
||||
$"echo %errorlevel%";
|
||||
File.WriteAllText(cmdFileName, cmd);
|
||||
var values = await ConsoleHelper.ExecuteCommand(cmdFileName);
|
||||
File.Delete(cmdFileName);
|
||||
try { File.Delete(cmdFileName); } catch { }
|
||||
|
||||
value = values.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
|
||||
// Empty result means timeout - don't retry, monitor is unresponsive
|
||||
if (string.IsNullOrEmpty(values))
|
||||
return string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(value) && value != "0") return value;
|
||||
await Task.Delay(500);
|
||||
await GetMonitorValue(monitorSN, vcpCode, reTry++);
|
||||
};
|
||||
var value = values.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
|
||||
|
||||
return value;
|
||||
if (!string.IsNullOrEmpty(value) && value != "0")
|
||||
return value;
|
||||
|
||||
// Only retry on non-timeout failures
|
||||
if (attempt < maxRetries)
|
||||
await Task.Delay(300);
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
#region Brightness (VCP Code 10)
|
||||
@@ -124,7 +130,7 @@ public static class CMMCommand
|
||||
return options;
|
||||
}
|
||||
|
||||
private static string GetInputSourceName(int vcpValue)
|
||||
public static string GetInputSourceName(int vcpValue)
|
||||
{
|
||||
return vcpValue switch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user