Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 047d68a

Browse files
committed
remove global http proxy; reset proxy when system ends
1 parent 20340aa commit 047d68a

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

V2RayW/App.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="clr-namespace:V2RayW"
5-
StartupUri="MainWindow.xaml">
5+
StartupUri="MainWindow.xaml"
6+
SessionEnding="App_SessionEnding"
7+
>
68
<Application.Resources>
79

810
</Application.Resources>

V2RayW/App.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ namespace V2RayW
1313
/// </summary>
1414
public partial class App : Application
1515
{
16-
16+
void App_SessionEnding(object sender, SessionEndingCancelEventArgs e)
17+
{
18+
(MainWindow as V2RayW.MainWindow).QuitV2RayW(sender, null);
19+
}
1720
}
21+
1822
}

V2RayW/ConfigWindow.xaml.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,6 @@ private void VmessListBox_SelectionChanged(object sender, SelectionChangedEventA
180180

181181
#region closewindow
182182

183-
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
184-
{
185-
e.Cancel = true;
186-
this.Hide();
187-
}
188-
189-
private void CheckInputs()
190-
{
191-
}
192-
193183
private void HideWindow(object sender, RoutedEventArgs e)
194184
{
195185
if(sender == saveConfigButton)
@@ -238,9 +228,11 @@ private void HideWindow(object sender, RoutedEventArgs e)
238228
mainWindow.udpSupport = udpSupportBox.IsChecked ?? false;
239229
mainWindow.logLevel = logLevelBox.SelectedItem.ToString();
240230

231+
241232
mainWindow.OverallChanged(this, null);
233+
242234
}
243-
this.Hide();
235+
this.Close();
244236
}
245237
#endregion
246238

V2RayW/MainWindow.xaml.cs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public partial class MainWindow : Window
4040

4141
private TaskbarIcon notifyIcon;
4242

43-
private ConfigWindow configWindow;
44-
4543

4644
public bool proxyState = false;
4745
public ProxyMode proxyMode = ProxyMode.manual;
@@ -468,6 +466,10 @@ public void OverallChanged(object sender, RoutedEventArgs e)
468466
}
469467
this.UpdateStatusAndModeMenus();
470468
this.UpdatePacMenuList();
469+
if(sender.GetType().Equals(typeof(ConfigWindow)))
470+
{
471+
WriteSettings();
472+
}
471473
}
472474
#endregion
473475

@@ -506,7 +508,7 @@ public void UpdateSystemProxy()
506508
} else if (proxyMode == ProxyMode.global)
507509
{
508510
registry.SetValue("ProxyEnable", 1);
509-
var proxyServer = $"http=127.0.0.1:{httpPort};socks=127.0.0.1:{localPort}";
511+
var proxyServer = $"http://127.0.0.1:{httpPort}";
510512
var proxyOverride = "<local>;localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;172.32.*;192.168.*";
511513
registry.SetValue("ProxyServer", proxyServer);
512514
registry.SetValue("ProxyOverride", proxyOverride);
@@ -780,7 +782,11 @@ private void InitializeCoreProcess()
780782
v2rayProcess.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + @"v2ray-core\v2ray.exe";
781783
Debug.WriteLine(v2rayProcess.StartInfo.FileName);
782784
v2rayProcess.StartInfo.Arguments = @"-config http://127.0.0.1:18000/config.json";
785+
#if DEBUG
786+
v2rayProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
787+
#else
783788
v2rayProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
789+
#endif
784790
v2rayCoreWorker.DoWork += V2rayCoreWorker_DoWork;
785791
v2rayCoreWorker.RunWorkerAsync();
786792
}
@@ -820,9 +826,9 @@ void ToggleCore()
820826
this.UnloadV2ray();
821827
coreWorkerSemaphore.Release(1);
822828
}
823-
#endregion
829+
#endregion
824830

825-
#region core config management
831+
#region core config management
826832
byte[] v2rayJsonConfig = new byte[0];
827833

828834
void CoreConfigChanged(object sender)
@@ -848,9 +854,13 @@ byte[] GenerateConfigFile()
848854
Dictionary<string, object> fullConfig = Utilities.configTemplate;
849855
fullConfig["log"] = new Dictionary<string, string>
850856
{
851-
{"loglevel", logLevel },
857+
#if DEBUG
858+
{"loglevel", "debug" }
859+
#else
852860
{ "error",AppDomain.CurrentDomain.BaseDirectory + @"log\error.log" },
853-
{ "access", AppDomain.CurrentDomain.BaseDirectory + @"log\access.log"}
861+
{ "access", AppDomain.CurrentDomain.BaseDirectory + @"log\access.log"},
862+
{"loglevel", logLevel }
863+
#endif
854864
};
855865
var dnsList = dnsString.Split(',');
856866
if(dnsList.Count() > 0)
@@ -943,9 +953,9 @@ byte[] GenerateConfigFile()
943953
}
944954
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(fullConfig, Formatting.Indented));
945955
}
946-
#endregion
956+
#endregion
947957

948-
#region routingRules
958+
#region routingRules
949959
void UpdateRuleSetMenuList()
950960
{
951961
Debug.WriteLine($"rules count = {routingRuleSets.Count}");
@@ -975,12 +985,12 @@ void SwitchRoutingRuleSet(object sender, RoutedEventArgs e)
975985
this.CoreConfigChanged(sender);
976986
}
977987

978-
#endregion
988+
#endregion
979989

980990

981-
#region other main menu items
991+
#region other main menu items
982992

983-
private void QuitV2RayW(object sender, RoutedEventArgs e)
993+
public void QuitV2RayW(object sender, RoutedEventArgs e)
984994
{
985995
notifyIcon.Icon = null;
986996
this.UnloadV2ray();
@@ -1006,25 +1016,20 @@ private void ShowHelp(object sender, RoutedEventArgs e)
10061016

10071017
private void ShowConfigWindow(object sender, RoutedEventArgs e)
10081018
{
1009-
if (this.configWindow == null)
1019+
ConfigWindow configWindow = new ConfigWindow
10101020
{
1011-
this.configWindow = new ConfigWindow
1012-
{
1013-
mainWindow = this
1014-
};
1015-
1016-
}
1017-
this.configWindow.InitializeData();
1018-
this.configWindow.Show();
1019-
this.configWindow.Focus();
1021+
mainWindow = this
1022+
};
1023+
configWindow.InitializeData();
1024+
configWindow.Show();
10201025
}
10211026

10221027
private void ViewCurrentConfig(object sender, RoutedEventArgs e)
10231028
{
10241029
Process.Start("http://127.0.0.1:18000/config.json");
10251030
}
10261031

1027-
#endregion
1032+
#endregion
10281033

10291034
private void ShowLogMenuItem_Click(object sender, RoutedEventArgs e)
10301035
{

0 commit comments

Comments
 (0)