From 96e96007eb5b63b8e89649f492005ca3b2055ae7 Mon Sep 17 00:00:00 2001
From: CtrAno <123796946+CtrAno@users.noreply.github.com>
Date: Sat, 28 Jan 2023 14:37:19 +0800
Subject: [PATCH] make Tun button shown when v2rayN starts without admin
permission, and ask for permission for sing_box.exe when tun button is
clicked
---
v2rayN/v2rayN/Handler/TunHandler.cs | 14 +++++++++-----
v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs | 2 +-
v2rayN/v2rayN/Views/MainWindow.xaml | 3 ++-
v2rayN/v2rayN/Views/MainWindow.xaml.cs | 3 ++-
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/v2rayN/v2rayN/Handler/TunHandler.cs b/v2rayN/v2rayN/Handler/TunHandler.cs
index 2f0746fa..4702f187 100644
--- a/v2rayN/v2rayN/Handler/TunHandler.cs
+++ b/v2rayN/v2rayN/Handler/TunHandler.cs
@@ -40,7 +40,7 @@ namespace v2rayN.Base
});
}
- public void Start()
+ public bool Start()
{
var socksPort = LazyConfig.Instance.GetLocalPort(Global.InboundSocks);
@@ -58,10 +58,11 @@ namespace v2rayN.Base
CoreStop();
if (Init() == false)
{
- return;
+ return false;
}
- CoreStart();
+ return CoreStart();
}
+ return false;
}
public void Stop()
@@ -200,14 +201,14 @@ namespace v2rayN.Base
return fileName;
}
- private void CoreStart()
+ private bool CoreStart()
{
try
{
string fileName = CoreFindexe();
if (fileName == "")
{
- return;
+ return false;
}
var showWindow = _config.tunModeItem.showWindow;
Process p = new Process
@@ -239,10 +240,13 @@ namespace v2rayN.Base
}
Global.processJob.AddProcess(p.Handle);
+ return true;
}
catch (Exception ex)
{
+ _isRunning = false;
Utils.SaveLog(ex.Message, ex);
+ return false;
}
}
diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
index 38400250..346fbbb9 100644
--- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
+++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
@@ -1481,7 +1481,7 @@ namespace v2rayN.ViewModels
{
if (EnableTun)
{
- TunHandler.Instance.Start();
+ EnableTun = TunHandler.Instance.Start();
}
else
{
diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml
index dc525929..d1f992d0 100644
--- a/v2rayN/v2rayN/Views/MainWindow.xaml
+++ b/v2rayN/v2rayN/Views/MainWindow.xaml
@@ -359,7 +359,8 @@
+ HorizontalAlignment="Left"
+ IsChecked="{Binding EnableTun}"/>
ViewModel, typeof(MainWindowViewModel));
Global.Languages.ForEach(it =>
@@ -181,7 +182,7 @@ namespace v2rayN.Views
var IsAdministrator = Utils.IsAdministrator();
this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
- spEnableTun.Visibility = IsAdministrator ? Visibility.Visible : Visibility.Collapsed;
+ //spEnableTun.Visibility = IsAdministrator ? Visibility.Visible : Visibility.Collapsed;
}
#region Event