Files
tyx_AI_xhs/supervisor/Dada.Supervisor/SupportedBrowserLauncher.cs
T
suyx e9fd15e7b6
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run
fix(POSTV1-runtime): 改善后台启动与状态窗口可见性
2026-08-05 23:12:31 +08:00

45 lines
1.5 KiB
C#

using System.ComponentModel;
using System.Diagnostics;
using Microsoft.Win32;
namespace Dada.Supervisor;
internal static class SupportedBrowserLauncher
{
internal static bool OpenDefaultSupported(Uri uri) => Open("chrome.exe", uri) || Open("msedge.exe", uri);
internal static bool OpenChrome(Uri uri) => Open("chrome.exe", uri);
internal static bool OpenEdge(Uri uri) => Open("msedge.exe", uri);
private static bool Open(string executableName, Uri uri)
{
var executable = FindExecutable(executableName);
if (executable is null) return false;
try
{
var startInfo = new ProcessStartInfo(executable) { UseShellExecute = false };
startInfo.ArgumentList.Add(uri.AbsoluteUri);
return Process.Start(startInfo) is not null;
}
catch (Win32Exception)
{
return false;
}
catch (InvalidOperationException)
{
return false;
}
}
private static string? FindExecutable(string executableName)
{
foreach (var hive in new[] { RegistryHive.CurrentUser, RegistryHive.LocalMachine })
foreach (var view in new[] { RegistryView.Registry64, RegistryView.Registry32 })
{
using var baseKey = RegistryKey.OpenBaseKey(hive, view);
using var key = baseKey.OpenSubKey($"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\{executableName}");
if (key?.GetValue(null) is string path && File.Exists(path)) return path;
}
return null;
}
}