From d9c22de6b88e5591b93eff2554bde8cedc585af0 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:31:12 +0800 Subject: [PATCH] Added core update function for macos --- v2rayN/ServiceLib/Handler/AutoStartupHandler.cs | 4 ++++ v2rayN/ServiceLib/Handler/CoreHandler.cs | 4 ++-- v2rayN/ServiceLib/Handler/CoreInfoHandler.cs | 8 ++++++++ v2rayN/ServiceLib/Models/CoreInfo.cs | 2 ++ v2rayN/ServiceLib/Services/UpdateService.cs | 9 +++++++++ v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs | 2 +- v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs | 5 +++++ v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs | 5 +++++ 8 files changed, 36 insertions(+), 3 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs index 42ec0086..6708a38e 100644 --- a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs +++ b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs @@ -25,6 +25,10 @@ namespace ServiceLib.Handler await SetTaskLinux(); } } + else if(Utils.IsOSX()) + { + //TODO + } return true; } diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 57e94557..dc597167 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -23,7 +23,7 @@ namespace ServiceLib.Handler Environment.SetEnvironmentVariable("V2RAY_LOCATION_ASSET", Utils.GetBinPath(""), EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("XRAY_LOCATION_ASSET", Utils.GetBinPath(""), EnvironmentVariableTarget.Process); - if (Utils.IsLinux()) + if (Utils.IsLinux() || Utils.IsOSX()) { var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(); foreach (var it in coreInfo) @@ -258,7 +258,7 @@ namespace ServiceLib.Handler { return _config.TunModeItem.EnableTun && eCoreType == ECoreType.sing_box - && Utils.IsLinux() + && (Utils.IsLinux() || Utils.IsOSX()) //&& _config.TunModeItem.LinuxSudoPwd.IsNotEmpty() ; } diff --git a/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs b/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs index 5b8fa606..d8399b06 100644 --- a/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs @@ -42,6 +42,8 @@ DownloadUrlWinArm64 = Global.NUrl + "/download/{0}/v2rayN-windows-arm64.zip", DownloadUrlLinux64 = Global.NUrl + "/download/{0}/v2rayN-linux-64.zip", DownloadUrlLinuxArm64 = Global.NUrl + "/download/{0}/v2rayN-linux-arm64.zip", + DownloadUrlOSX64 = Global.NUrl + "/download/{0}/v2rayN-macos-64.zip", + DownloadUrlOSXArm64 = Global.NUrl + "/download/{0}/v2rayN-macos-arm64.zip", }); _coreInfo.Add(new CoreInfo @@ -79,6 +81,8 @@ DownloadUrlWinArm64 = Global.XrayCoreUrl + "/download/{0}/Xray-windows-arm64-v8a.zip", DownloadUrlLinux64 = Global.XrayCoreUrl + "/download/{0}/Xray-linux-64.zip", DownloadUrlLinuxArm64 = Global.XrayCoreUrl + "/download/{0}/Xray-linux-arm64-v8a.zip", + DownloadUrlOSX64 = Global.XrayCoreUrl + "/download/{0}/Xray-macos-64.zip", + DownloadUrlOSXArm64 = Global.XrayCoreUrl + "/download/{0}/Xray-macos-arm64-v8a.zip", Match = "Xray", VersionArg = "-version", RedirectInfo = true, @@ -95,6 +99,8 @@ DownloadUrlWinArm64 = Global.MihomoCoreUrl + "/download/{0}/mihomo-windows-arm64-{0}.zip", DownloadUrlLinux64 = Global.MihomoCoreUrl + "/download/{0}/mihomo-linux-amd64-compatible-{0}.gz", DownloadUrlLinuxArm64 = Global.MihomoCoreUrl + "/download/{0}/mihomo-linux-arm64-{0}.gz", + DownloadUrlOSX64 = Global.MihomoCoreUrl + "/download/{0}/mihomo-darwin-amd64-compatible-{0}.gz", + DownloadUrlOSXArm64 = Global.MihomoCoreUrl + "/download/{0}/mihomo-darwin-arm64-{0}.gz", Match = "Mihomo", VersionArg = "-v", RedirectInfo = true, @@ -140,6 +146,8 @@ DownloadUrlWinArm64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-windows-arm64.zip", DownloadUrlLinux64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-linux-amd64.tar.gz", DownloadUrlLinuxArm64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-linux-arm64.tar.gz", + DownloadUrlOSX64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-darwin-amd64.tar.gz", + DownloadUrlOSXArm64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-darwin-arm64.tar.gz", Match = "sing-box", VersionArg = "version", }); diff --git a/v2rayN/ServiceLib/Models/CoreInfo.cs b/v2rayN/ServiceLib/Models/CoreInfo.cs index f7e673d6..1afcd0b6 100644 --- a/v2rayN/ServiceLib/Models/CoreInfo.cs +++ b/v2rayN/ServiceLib/Models/CoreInfo.cs @@ -12,6 +12,8 @@ public string? DownloadUrlWinArm64 { get; set; } public string? DownloadUrlLinux64 { get; set; } public string? DownloadUrlLinuxArm64 { get; set; } + public string? DownloadUrlOSX64 { get; set; } + public string? DownloadUrlOSXArm64 { get; set; } public string? Match { get; set; } public string? VersionArg { get; set; } public bool RedirectInfo { get; set; } diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 6474db7c..7ce7975f 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -450,6 +450,15 @@ namespace ServiceLib.Services _ => null, }; } + else if (Utils.IsOSX()) + { + return RuntimeInformation.ProcessArchitecture switch + { + Architecture.Arm64 => coreInfo?.DownloadUrlOSXArm64, + Architecture.X64 => coreInfo?.DownloadUrlOSX64, + _ => null, + }; + } return null; } diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index 5890d614..dcfc122e 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -262,7 +262,7 @@ namespace ServiceLib.ViewModels FileManager.ZipExtractToFile(fileName, toPath, _config.GuiItem.IgnoreGeoUpdateCore ? "geo" : ""); } - if (Utils.IsLinux()) + if (Utils.IsLinux() || Utils.IsOSX()) { var filesList = (new DirectoryInfo(toPath)).GetFiles().Select(u => u.FullName).ToList(); foreach (var file in filesList) diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index 73ee0866..456524f2 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -437,6 +437,11 @@ namespace ServiceLib.ViewModels { return _config.TunModeItem.LinuxSudoPwd.IsNotEmpty(); } + else if (Utils.IsOSX()) + { + //TODO + return false; + } return false; } diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs index 4fff78f4..6b853c14 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs @@ -218,6 +218,11 @@ namespace v2rayN.Desktop.Views .ToList(); return lst; } + else if (Utils.IsOSX()) + { + //TODO + return lstFonts; + } } catch (Exception ex) {