Refactor Scan Screen Task

pull/2101/head
2dust 3 years ago
parent d42346d500
commit f6ccee1976

@ -64,9 +64,9 @@
this.menuExport2ServerConfig = new System.Windows.Forms.ToolStripMenuItem();
this.menuExport2ShareUrl = new System.Windows.Forms.ToolStripMenuItem();
this.menuExport2SubContent = new System.Windows.Forms.ToolStripMenuItem();
this.tsbServer = new System.Windows.Forms.ToolStripDropDownButton();
this.tabGroup = new System.Windows.Forms.TabControl();
this.qrCodeControl = new v2rayN.Forms.QRCodeControl();
this.tsbServer = new System.Windows.Forms.ToolStripDropDownButton();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.gbMsgTitle = new System.Windows.Forms.GroupBox();
@ -101,7 +101,6 @@
this.menuUpdateSubViaProxy = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.menuExit = new System.Windows.Forms.ToolStripMenuItem();
this.bgwScan = new System.ComponentModel.BackgroundWorker();
this.panel1 = new System.Windows.Forms.Panel();
this.tsMain = new System.Windows.Forms.ToolStrip();
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
@ -227,7 +226,6 @@
this.menuExport2ShareUrl,
this.menuExport2SubContent});
this.cmsLv.Name = "cmsLv";
this.cmsLv.OwnerItem = this.tsbServer;
resources.ApplyResources(this.cmsLv, "cmsLv");
//
// menuAddVmessServer
@ -412,13 +410,6 @@
resources.ApplyResources(this.menuExport2SubContent, "menuExport2SubContent");
this.menuExport2SubContent.Click += new System.EventHandler(this.menuExport2SubContent_Click);
//
// tsbServer
//
this.tsbServer.DropDown = this.cmsLv;
this.tsbServer.Image = global::v2rayN.Properties.Resources.server;
resources.ApplyResources(this.tsbServer, "tsbServer");
this.tsbServer.Name = "tsbServer";
//
// tabGroup
//
resources.ApplyResources(this.tabGroup, "tabGroup");
@ -431,6 +422,13 @@
resources.ApplyResources(this.qrCodeControl, "qrCodeControl");
this.qrCodeControl.Name = "qrCodeControl";
//
// tsbServer
//
this.tsbServer.DropDown = this.cmsLv;
this.tsbServer.Image = global::v2rayN.Properties.Resources.server;
resources.ApplyResources(this.tsbServer, "tsbServer");
this.tsbServer.Name = "tsbServer";
//
// splitContainer1
//
resources.ApplyResources(this.splitContainer1, "splitContainer1");
@ -677,12 +675,6 @@
resources.ApplyResources(this.menuExit, "menuExit");
this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
//
// bgwScan
//
this.bgwScan.WorkerReportsProgress = true;
this.bgwScan.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bgwScan_DoWork);
this.bgwScan.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bgwScan_ProgressChanged);
//
// panel1
//
resources.ApplyResources(this.panel1, "panel1");
@ -1027,7 +1019,6 @@
private System.Windows.Forms.ToolStripDropDownButton tsbHelp;
private System.Windows.Forms.ToolStripMenuItem tsbAbout;
private System.Windows.Forms.ToolStripMenuItem menuAddServers2;
private System.ComponentModel.BackgroundWorker bgwScan;
private System.Windows.Forms.ToolStripMenuItem menuScanScreen;
private System.Windows.Forms.ToolStripMenuItem menuScanScreen2;
private System.Windows.Forms.ToolStripDropDownButton tsbSub;

@ -1008,9 +1008,34 @@ namespace v2rayN.Forms
}
private void menuScanScreen_Click(object sender, EventArgs e)
{
_ = ScanScreenTaskAsync();
}
public async Task ScanScreenTaskAsync()
{
HideForm();
bgwScan.RunWorkerAsync();
string result = await Task.Run(() =>
{
return Utils.ScanScreen();
});
ShowForm();
if (Utils.IsNullOrEmpty(result))
{
UI.ShowWarning(UIRes.I18N("NoValidQRcodeFound"));
}
else
{
int ret = MainFormHandler.Instance.AddBatchServers(config, result, "", groupId);
if (ret > 0)
{
RefreshServers();
UI.Show(UIRes.I18N("SuccessfullyImportedServerViaScan"));
}
}
}
private void menuUpdateSubscriptions_Click(object sender, EventArgs e)
@ -1422,37 +1447,6 @@ namespace v2rayN.Forms
}
#endregion
#region ScanScreen
private void bgwScan_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
string ret = Utils.ScanScreen();
bgwScan.ReportProgress(0, ret);
}
private void bgwScan_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
ShowForm();
string result = Convert.ToString(e.UserState);
if (Utils.IsNullOrEmpty(result))
{
UI.ShowWarning(UIRes.I18N("NoValidQRcodeFound"));
}
else
{
int ret = MainFormHandler.Instance.AddBatchServers(config, result, "", groupId);
if (ret > 0)
{
RefreshServers();
UI.Show(UIRes.I18N("SuccessfullyImportedServerViaScan"));
}
}
}
#endregion
#region 订阅
private void tsbSubSetting_Click(object sender, EventArgs e)
{

@ -302,18 +302,6 @@
<data name="menuExport2SubContent.Text" xml:space="preserve">
<value>Export subscription (base64) share to clipboard</value>
</data>
<data name="tsbServer.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
</data>
<data name="tsbServer.Size" type="System.Drawing.Size, System.Drawing">
<value>64, 53</value>
</data>
<data name="tsbServer.Text" xml:space="preserve">
<value>Servers</value>
</data>
<data name="tsbServer.TextImageRelation" type="System.Windows.Forms.TextImageRelation, System.Windows.Forms">
<value>ImageAboveText</value>
</data>
<data name="cmsLv.Size" type="System.Drawing.Size, System.Drawing">
<value>356, 622</value>
</data>
@ -464,6 +452,18 @@
<data name="&gt;&gt;scMain.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="tsbServer.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
</data>
<data name="tsbServer.Size" type="System.Drawing.Size, System.Drawing">
<value>64, 53</value>
</data>
<data name="tsbServer.Text" xml:space="preserve">
<value>Servers</value>
</data>
<data name="tsbServer.TextImageRelation" type="System.Windows.Forms.TextImageRelation, System.Windows.Forms">
<value>ImageAboveText</value>
</data>
<data name="splitContainer1.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
@ -510,7 +510,7 @@
<value>0</value>
</data>
<metadata name="cmsMsgBox.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>603, 17</value>
<value>493, 20</value>
</metadata>
<data name="menuMsgBoxSelectAll.Size" type="System.Drawing.Size, System.Drawing">
<value>227, 22</value>
@ -549,7 +549,7 @@
<value>Set message filters</value>
</data>
<data name="cmsMsgBox.Size" type="System.Drawing.Size, System.Drawing">
<value>228, 136</value>
<value>228, 158</value>
</data>
<data name="&gt;&gt;cmsMsgBox.Name" xml:space="preserve">
<value>cmsMsgBox</value>
@ -824,9 +824,6 @@
<data name="notifyMain.Visible" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<metadata name="bgwScan.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>498, 17</value>
</metadata>
<data name="panel1.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Top</value>
</data>
@ -1478,12 +1475,6 @@
<data name="&gt;&gt;menuExit.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;bgwScan.Name" xml:space="preserve">
<value>bgwScan</value>
</data>
<data name="&gt;&gt;bgwScan.Type" xml:space="preserve">
<value>System.ComponentModel.BackgroundWorker, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripSeparator4.Name" xml:space="preserve">
<value>toolStripSeparator4</value>
</data>

Loading…
Cancel
Save