2025-04-02 03:44:23 +00:00
|
|
|
namespace ServiceLib.Handler.SysProxy;
|
|
|
|
|
|
2026-05-14 11:25:07 +00:00
|
|
|
[SupportedOSPlatform("macos")]
|
2025-08-17 08:52:51 +00:00
|
|
|
public static class ProxySettingOSX
|
2024-09-28 02:41:30 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
private static readonly string _proxySetFileName = $"{Global.ProxySetOSXShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
2024-11-08 01:21:43 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
public static async Task SetProxy(string host, int port, string exceptions)
|
|
|
|
|
{
|
|
|
|
|
List<string> args = ["set", host, port.ToString()];
|
|
|
|
|
if (exceptions.IsNotEmpty())
|
2024-09-28 02:41:30 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
args.AddRange(exceptions.Split(','));
|
2024-11-08 01:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
await ExecCmd(args);
|
|
|
|
|
}
|
2025-01-01 06:24:23 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
public static async Task UnsetProxy()
|
|
|
|
|
{
|
|
|
|
|
List<string> args = ["clear"];
|
|
|
|
|
await ExecCmd(args);
|
|
|
|
|
}
|
2025-01-05 04:24:14 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private static async Task ExecCmd(List<string> args)
|
|
|
|
|
{
|
2025-11-07 11:28:16 +00:00
|
|
|
var customSystemProxyScriptPath = AppManager.Instance.Config.SystemProxyItem?.CustomSystemProxyScriptPath;
|
|
|
|
|
var fileName = (customSystemProxyScriptPath.IsNotEmpty() && File.Exists(customSystemProxyScriptPath))
|
|
|
|
|
? customSystemProxyScriptPath
|
|
|
|
|
: await FileUtils.CreateLinuxShellFile(_proxySetFileName, EmbedUtils.GetEmbedText(Global.ProxySetOSXShellFileName), false);
|
|
|
|
|
|
|
|
|
|
// TODO: temporarily notify which script is being used
|
|
|
|
|
NoticeManager.Instance.SendMessage(fileName);
|
2025-04-02 03:44:23 +00:00
|
|
|
|
|
|
|
|
await Utils.GetCliWrapOutput(fileName, args);
|
2024-09-28 02:41:30 +00:00
|
|
|
}
|
2025-02-23 11:52:13 +00:00
|
|
|
}
|