diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs
index 56c63c23..921168cf 100644
--- a/v2rayN/v2rayN/Forms/MainForm.cs
+++ b/v2rayN/v2rayN/Forms/MainForm.cs
@@ -1313,12 +1313,54 @@ namespace v2rayN.Forms
RefreshServers();
}
}
-
+ ///
+ /// Reset to the previous selected.
+ ///
+ private int FindIndexByRemarks(string remarks)
+ {
+ for (int k = 0; k < config.vmess.Count; k++)
+ {
+ VmessItem item = config.vmess[k];
+ if (item.remarks.Equals(remarks))
+ {
+ return k;
+ }
+ }
+ for (int k = 0; k < config.vmess.Count; k++)
+ {
+ VmessItem item = config.vmess[k];
+ if (item.remarks.Contains(remarks.Substring(0, 2)))
+ {
+ // 汉字也是占一个, 台湾 CHT [06]
+ return k;
+ }
+ }
+ return 0;
+ }
private void tsbSubUpdate_Click(object sender, EventArgs e)
{
- UpdateSubscriptionProcess();
+ VmessItem item = config.vmess[config.index];
+ var remarks = item.remarks;
+ var handle = new UpdateHandle();
+ void _updateUIAndReselect(bool success, string msg)
+ {
+ AppendText(false, msg);
+ if (success)
+ {
+ RefreshServers();
+ }
+ if (handle.updateSubscriptionProcessCompleted)
+ {
+ // wait for above fxcking async program to complete
+ int index = FindIndexByRemarks(remarks);
+ SetDefaultServer(index);
+ AppendText(false, $"{UIRes.I18N("MsgUpdateSubscriptionEndReslectLast")}");
+ RefreshServers();
+ handle.updateSubscriptionProcessCompleted = false;
+ }
+ };
+ handle.UpdateSubscriptionProcess(config, _updateUIAndReselect);
}
-
///
/// the subscription update process
///
diff --git a/v2rayN/v2rayN/Handler/UpdateHandle.cs b/v2rayN/v2rayN/Handler/UpdateHandle.cs
index 2a35d676..28633104 100644
--- a/v2rayN/v2rayN/Handler/UpdateHandle.cs
+++ b/v2rayN/v2rayN/Handler/UpdateHandle.cs
@@ -14,7 +14,7 @@ namespace v2rayN.Handler
{
Action _updateFunc;
private Config _config;
-
+ public bool updateSubscriptionProcessCompleted = false;
public event EventHandler AbsoluteCompleted;
public class ResultEventArgs : EventArgs
@@ -212,6 +212,7 @@ namespace v2rayN.Handler
{
_updateFunc(false, $"{hashCode}{UIRes.I18N("MsgFailedImportSubscription")}");
}
+ updateSubscriptionProcessCompleted = true;
_updateFunc(true, $"{hashCode}{UIRes.I18N("MsgUpdateSubscriptionEnd")}");
}
else
diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj
index 3d925fa0..b658fc9f 100644
--- a/v2rayN/v2rayN/v2rayN.csproj
+++ b/v2rayN/v2rayN/v2rayN.csproj
@@ -498,6 +498,10 @@ del $(TargetDir)*.xml $(TargetDir)*.so $(TargetDir)*.dylib
if not "$(ConfigurationName)" == "Debug" del $(TargetDir)*.pdb
+
+ TASKKILL /F /IM v2rayN.exe /T
+set errolevel=0
+