mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-26 18:24:43 +00:00
Compare commits
3 commits
f71125d8f3
...
b2feaf3ba9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2feaf3ba9 | ||
|
|
6c5011ad68 | ||
|
|
c0f8b6b84c |
6 changed files with 124 additions and 50 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
using Microsoft.Win32;
|
using System.Diagnostics;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace ServiceLib.Common
|
namespace ServiceLib.Common
|
||||||
{
|
{
|
||||||
|
|
@ -50,5 +53,24 @@ namespace ServiceLib.Common
|
||||||
regKey?.Close();
|
regKey?.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task RemoveTunDevice()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sum = MD5.HashData(Encoding.UTF8.GetBytes("wintunsingbox_tun"));
|
||||||
|
var guid = new Guid(sum);
|
||||||
|
var pnpUtilPath = @"C:\Windows\System32\pnputil.exe";
|
||||||
|
var arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """;
|
||||||
|
|
||||||
|
// Try to remove the device
|
||||||
|
await Utils.GetCliWrapOutput(pnpUtilPath, arg);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Security.Principal;
|
using System.Diagnostics;
|
||||||
|
using System.Security.Principal;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Handler
|
||||||
|
|
@ -29,7 +30,12 @@ namespace ServiceLib.Handler
|
||||||
}
|
}
|
||||||
else if (Utils.IsOSX())
|
else if (Utils.IsOSX())
|
||||||
{
|
{
|
||||||
//TODO
|
await ClearTaskOSX();
|
||||||
|
|
||||||
|
if (config.GuiItem.AutoRun)
|
||||||
|
{
|
||||||
|
await SetTaskOSX();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -161,5 +167,77 @@ namespace ServiceLib.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Linux
|
#endregion Linux
|
||||||
|
|
||||||
|
#region macOS
|
||||||
|
|
||||||
|
private static async Task ClearTaskOSX()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var launchAgentPath = GetLaunchAgentPathMacOS();
|
||||||
|
if (File.Exists(launchAgentPath))
|
||||||
|
{
|
||||||
|
var args = new[] { "-c", $"launchctl unload -w \"{launchAgentPath}\"" };
|
||||||
|
await Utils.GetCliWrapOutput("/bin/bash", args);
|
||||||
|
|
||||||
|
File.Delete(launchAgentPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task SetTaskOSX()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var plistContent = GenerateLaunchAgentPlist();
|
||||||
|
var launchAgentPath = GetLaunchAgentPathMacOS();
|
||||||
|
await File.WriteAllTextAsync(launchAgentPath, plistContent);
|
||||||
|
|
||||||
|
var args = new[] { "-c", $"launchctl load -w \"{launchAgentPath}\"" };
|
||||||
|
await Utils.GetCliWrapOutput("/bin/bash", args);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetLaunchAgentPathMacOS()
|
||||||
|
{
|
||||||
|
var homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
|
var launchAgentPath = Path.Combine(homePath, "Library", "LaunchAgents", $"{Global.AppName}-LaunchAgent.plist");
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(launchAgentPath));
|
||||||
|
return launchAgentPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GenerateLaunchAgentPlist()
|
||||||
|
{
|
||||||
|
var exePath = Utils.GetExePath();
|
||||||
|
var appName = Path.GetFileNameWithoutExtension(exePath);
|
||||||
|
return $@"<?xml version=""1.0"" encoding=""UTF-8""?>
|
||||||
|
<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
|
||||||
|
<plist version=""1.0"">
|
||||||
|
<dict>
|
||||||
|
<key>Label</key>
|
||||||
|
<string>{Global.AppName}-LaunchAgent</string>
|
||||||
|
<key>ProgramArguments</key>
|
||||||
|
<array>
|
||||||
|
<string>/bin/sh</string>
|
||||||
|
<string>-c</string>
|
||||||
|
<string>if ! pgrep -x ""{appName}"" > /dev/null; then ""{exePath}""; fi</string>
|
||||||
|
</array>
|
||||||
|
<key>RunAtLoad</key>
|
||||||
|
<true/>
|
||||||
|
<key>KeepAlive</key>
|
||||||
|
<false/>
|
||||||
|
</dict>
|
||||||
|
</plist>";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion macOS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Handler
|
||||||
|
|
@ -83,6 +83,13 @@ namespace ServiceLib.Handler
|
||||||
UpdateFunc(false, string.Format(ResUI.StartService, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
|
UpdateFunc(false, string.Format(ResUI.StartService, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
|
||||||
await CoreStop();
|
await CoreStop();
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
|
|
||||||
|
if (Utils.IsWindows() && _config.TunModeItem.EnableTun)
|
||||||
|
{
|
||||||
|
await Task.Delay(100);
|
||||||
|
await WindowsUtils.RemoveTunDevice();
|
||||||
|
}
|
||||||
|
|
||||||
await CoreStart(node);
|
await CoreStart(node);
|
||||||
await CoreStartPreService(node);
|
await CoreStartPreService(node);
|
||||||
if (_process != null)
|
if (_process != null)
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,6 @@ namespace v2rayN.Desktop.Views
|
||||||
StorageUI();
|
StorageUI();
|
||||||
|
|
||||||
await ViewModel?.MyAppExitAsync(false);
|
await ViewModel?.MyAppExitAsync(false);
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Event
|
#endregion Event
|
||||||
|
|
@ -414,6 +413,10 @@ namespace v2rayN.Desktop.Views
|
||||||
{
|
{
|
||||||
if (Utils.IsOSX() || _config.UiItem.Hide2TrayWhenClose)
|
if (Utils.IsOSX() || _config.UiItem.Hide2TrayWhenClose)
|
||||||
{
|
{
|
||||||
|
foreach (var ownedWindow in this.OwnedWindows)
|
||||||
|
{
|
||||||
|
ownedWindow.Close();
|
||||||
|
}
|
||||||
this.Hide();
|
this.Hide();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -176,13 +176,6 @@ namespace v2rayN.Desktop.Views
|
||||||
txbSettingsExceptionTip.IsVisible = false;
|
txbSettingsExceptionTip.IsVisible = false;
|
||||||
panSystemProxyAdvanced.IsVisible = false;
|
panSystemProxyAdvanced.IsVisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.IsOSX())
|
|
||||||
{
|
|
||||||
tbAutoRun.IsVisible = false;
|
|
||||||
togAutoRun.IsVisible = false;
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
@ -64,36 +64,7 @@ namespace v2rayN
|
||||||
BitmapSizeOptions.FromEmptyOptions());
|
BitmapSizeOptions.FromEmptyOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveTunDevice()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var sum = MD5.HashData(Encoding.UTF8.GetBytes("wintunsingbox_tun"));
|
|
||||||
var guid = new Guid(sum);
|
|
||||||
string pnputilPath = @"C:\Windows\System32\pnputil.exe";
|
|
||||||
string arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """;
|
|
||||||
|
|
||||||
// Try to remove the device
|
|
||||||
Process proc = new()
|
|
||||||
{
|
|
||||||
StartInfo = new()
|
|
||||||
{
|
|
||||||
FileName = pnputilPath,
|
|
||||||
Arguments = arg,
|
|
||||||
RedirectStandardOutput = true,
|
|
||||||
UseShellExecute = false,
|
|
||||||
CreateNoWindow = true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
proc.Start();
|
|
||||||
var output = proc.StandardOutput.ReadToEnd();
|
|
||||||
proc.WaitForExit();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetDarkBorder(Window window, string? theme)
|
public static void SetDarkBorder(Window window, string? theme)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue