make Tun button shown when v2rayN starts without admin permission, and ask for permission for sing_box.exe when tun button is clicked

This commit is contained in:
CtrAno 2023-01-28 14:37:19 +08:00
parent 5ceb638edf
commit 96e96007eb
4 changed files with 14 additions and 8 deletions

View file

@ -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;
}
}

View file

@ -1481,7 +1481,7 @@ namespace v2rayN.ViewModels
{
if (EnableTun)
{
TunHandler.Instance.Start();
EnableTun = TunHandler.Instance.Start();
}
else
{

View file

@ -359,7 +359,8 @@
<ToggleButton
x:Name="togEnableTun"
Margin="4"
HorizontalAlignment="Left" />
HorizontalAlignment="Left"
IsChecked="{Binding EnableTun}"/>
</StackPanel>
<StackPanel

View file

@ -43,6 +43,7 @@ namespace v2rayN.Views
}
ViewModel = new MainWindowViewModel(MainSnackbar.MessageQueue!, UpdateViewHandler);
this.DataContext = ViewModel;
Locator.CurrentMutable.RegisterLazySingleton(() => 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