Browse Source

修复多窗口

CaptB 4 months ago
parent
commit
ba0fdbf464
12 changed files with 275 additions and 51 deletions
  1. 3 0
      App.config
  2. 2 2
      EdgeVoyager.csproj
  3. 5 3
      Form1.Designer.cs
  4. 25 41
      Form1.cs
  5. 0 2
      Form2.cs
  6. 1 1
      Program.cs
  7. 1 1
      Readme.md
  8. 22 1
      Settings1.Designer.cs
  9. 3 0
      Settings1.settings
  10. 57 0
      main.Designer.cs
  11. 33 0
      main.cs
  12. 123 0
      main.resx

+ 3 - 0
App.config

@@ -16,6 +16,9 @@
             <setting name="firstwindow" serializeAs="String">
                 <value>True</value>
             </setting>
+            <setting name="windows_num" serializeAs="String">
+                <value>1</value>
+            </setting>
         </EdgeVoyager.Settings1>
     </userSettings>
 </configuration>

+ 2 - 2
EdgeVoyager.csproj

@@ -8,8 +8,8 @@
     <ImplicitUsings>enable</ImplicitUsings>
     <ApplicationIcon>Resources\icons8_connection_status_on.ico</ApplicationIcon>
     <PackageIcon>icons8_connection_status_on_128.png</PackageIcon>
-    <AssemblyVersion>1.1.0.0</AssemblyVersion>
-    <FileVersion>1.1.0.0</FileVersion>
+    <AssemblyVersion>1.3.2.0</AssemblyVersion>
+    <FileVersion>1.3.2.0</FileVersion>
     <Copyright>©2025 LYKNS Corp. 保留部分权利。</Copyright>
     <Company>LYKNS Corporation</Company>
     <Description>LYKNS EdgeVoyager是一个新的个性化的浏览器。访问https://dev.lykns.com.cn/EdgeVoyager_Project/EdgeVoyager获取更多信息。

+ 5 - 3
Form1.Designer.cs

@@ -484,21 +484,21 @@
             // 添加到收藏夹ToolStripMenuItem
             // 
             添加到收藏夹ToolStripMenuItem.Name = "添加到收藏夹ToolStripMenuItem";
-            添加到收藏夹ToolStripMenuItem.Size = new Size(180, 22);
+            添加到收藏夹ToolStripMenuItem.Size = new Size(148, 22);
             添加到收藏夹ToolStripMenuItem.Text = "添加到收藏夹";
             添加到收藏夹ToolStripMenuItem.Click += 添加到收藏夹ToolStripMenuItem_Click;
             // 
             // 整理收藏夹ToolStripMenuItem
             // 
             整理收藏夹ToolStripMenuItem.Name = "整理收藏夹ToolStripMenuItem";
-            整理收藏夹ToolStripMenuItem.Size = new Size(180, 22);
+            整理收藏夹ToolStripMenuItem.Size = new Size(148, 22);
             整理收藏夹ToolStripMenuItem.Text = "整理收藏夹";
             整理收藏夹ToolStripMenuItem.Click += 整理收藏夹ToolStripMenuItem_Click;
             // 
             // toolStripSeparator10
             // 
             toolStripSeparator10.Name = "toolStripSeparator10";
-            toolStripSeparator10.Size = new Size(177, 6);
+            toolStripSeparator10.Size = new Size(145, 6);
             // 
             // 工具TToolStripMenuItem
             // 
@@ -614,6 +614,8 @@
             Name = "Form1";
             Text = "LYKNS EdgeVoyager";
             Activated += Form1_Activated;
+            FormClosed += Form1_FormClosed;
+            Load += Form1_Load;
             statusStrip1.ResumeLayout(false);
             statusStrip1.PerformLayout();
             menuStrip1.ResumeLayout(false);

+ 25 - 41
Form1.cs

@@ -389,14 +389,13 @@ background-position: right top;
             if (uri.StartsWith("http://"))
             {
                 string httpsUri = "https://" + uri.Substring("http://".Length);
-                e.Cancel = true; // 取消当前的http导航
-                webView21.CoreWebView2.Navigate(httpsUri); // 尝试https导航
+                e.Cancel = true;
+                webView21.CoreWebView2.Navigate(httpsUri);
             }
             string currentUrl = webView21.Source.ToString();
             if (!comboBox1.Items.Contains(currentUrl))
-            {
                 comboBox1.Items.Add(currentUrl);
-            }
+
             comboBox1.Text = currentUrl;
             progressBar.Value = 0;
             progressLabel.Text = "0%";
@@ -407,19 +406,15 @@ background-position: right top;
         {
             if (!e.IsSuccess && isHttpsFallback)
             {
-                isHttpsFallback = false; // 重置标志
+                isHttpsFallback = false;
                 string originalUri = webView21.CoreWebView2.Source.Replace("https://", "http://");
-                webView21.CoreWebView2.Navigate(originalUri); // 重新导航到http地址
+                webView21.CoreWebView2.Navigate(originalUri);
             }
             else if (e.IsSuccess && webView21.CoreWebView2.Source.StartsWith("https://"))
-            {
-                isHttpsFallback = false; // 如果https导航成功,重置标志
-            }
+                isHttpsFallback = false;
             string currentUrl = webView21.Source.ToString();
             if (!comboBox1.Items.Contains(currentUrl))
-            {
                 comboBox1.Items.Add(currentUrl);
-            }
             comboBox1.Text = currentUrl;
             progressBar.Value = 100;
             progressLabel.Text = "100%";
@@ -447,13 +442,9 @@ background-position: right top;
                                 using (var img = Image.FromStream(ms))
                                 {
                                     if (img is Bitmap bitmap)
-                                    {
-                                        this.Icon = Icon.FromHandle(bitmap.GetHicon());
-                                    }
+                                        Icon = Icon.FromHandle(bitmap.GetHicon());
                                     else
-                                    {
-                                        this.Icon = Icon.FromHandle(((Bitmap)img.Clone()).GetHicon());
-                                    }
+                                        Icon = Icon.FromHandle(((Bitmap)img.Clone()).GetHicon());
                                 }
                             }
                         }
@@ -477,18 +468,14 @@ background-position: right top;
                 }
                 string url = comboBox1.Text;
                 if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
-                {
                     webView21.CoreWebView2.Navigate(url);
-                }
             }
         }
 
         private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
         {
-            if(MessageBox.Show("确认关闭 LYKNS EdgeVoyager 所有窗口?", "退出确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
-            {
+            if (MessageBox.Show("确认关闭 LYKNS EdgeVoyager 所有窗口?", "退出确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                 Environment.Exit(0);
-            }
         }
 
         private void webView21_ContentLoading(object sender, CoreWebView2ContentLoadingEventArgs e)
@@ -606,17 +593,11 @@ background-position: right top;
             {
                 CoreWebView2PrintStatus printStatus = await webView21.CoreWebView2.PrintAsync(null);
                 if (printStatus == CoreWebView2PrintStatus.Succeeded)
-                {
                     MessageBox.Show(this, "打印 " + title + " 文档到打印机成功", "打印到默认打印机");
-                }
                 else if (printStatus == CoreWebView2PrintStatus.PrinterUnavailable)
-                {
                     MessageBox.Show(this, "打印机不可用,离线或错误状态", "打印到默认打印机");
-                }
                 else
-                {
                     MessageBox.Show(this, "打印 " + title + " 文档到打印机失败", "打印到默认打印机");
-                }
             }
             catch (Exception)
             {
@@ -736,9 +717,7 @@ background-position: right top;
                 {
                     var headers = response.Headers;
                     if (headers.Contains("Strict-Transport-Security"))
-                    {
                         return "HSTS已开启";
-                    }
                 }
                 return "无HSTS";
             }
@@ -774,16 +753,12 @@ background-position: right top;
             if (comboBox1.Focused)
             {
                 if (comboBox1.SelectedText != "")
-                {
                     Clipboard.SetText(comboBox1.SelectedText);
-                }
             }
             else if (textBox1.Focused)
             {
                 if (textBox1.SelectedText != "")
-                {
                     Clipboard.SetText(textBox1.SelectedText);
-                }
             }
             else if (isWebView2Focused)
             {
@@ -870,11 +845,7 @@ background-position: right top;
                     resources.Add(entry.Key, entry.Value);
                 }
                 reader.Close();
-
-                // 添加新的资源项
                 resources.Add(pageTitle, pageUrl);
-
-                // 写入到资源文件
                 using (ResXResourceWriter writer = new ResXResourceWriter(resxFilePath))
                 {
                     foreach (DictionaryEntry entry in resources)
@@ -885,16 +856,14 @@ background-position: right top;
                 }
                 for (int i = 0; i < 收藏夹AToolStripMenuItem.DropDownItems.Count; i++)
                 {
-                    // 如果找到了toolStripSeparator10
                     if (收藏夹AToolStripMenuItem.DropDownItems[i] is ToolStripSeparator &&
                         收藏夹AToolStripMenuItem.DropDownItems[i].Name == "toolStripSeparator10")
                     {
-                        // 从toolStripSeparator10下方开始,删除所有按钮
                         for (int j = 收藏夹AToolStripMenuItem.DropDownItems.Count - 1; j > i; j--)
                         {
                             收藏夹AToolStripMenuItem.DropDownItems.RemoveAt(j);
                         }
-                        break; // 找到并处理完毕后退出循环
+                        break;
                     }
                 }
                 using (ResXResourceReader reader1 = new ResXResourceReader(resxFilePath))
@@ -989,5 +958,20 @@ background-position: right top;
                 }
             }
         }
+
+        private void Form1_Load(object sender, EventArgs e)
+        {
+            if (Settings1.Default.windows_num != 1)
+            {
+                Settings1.Default.windows_num++;
+                Settings1.Default.Save();
+            }
+        }
+
+        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
+        {
+            Settings1.Default.windows_num--;
+            Settings1.Default.Save();
+        }
     }
 }

+ 0 - 2
Form2.cs

@@ -54,9 +54,7 @@ namespace EdgeVoyager
                 foreach (DictionaryEntry d in rsxr)
                 {
                     if (d.Key.ToString() != key)
-                    {
                         resources.Add(d.Key.ToString(), d.Value);
-                    }
                 }
                 rsxr.Close();
                 ResXResourceWriter rsxw = new ResXResourceWriter(resxFilePath);

+ 1 - 1
Program.cs

@@ -8,7 +8,7 @@ namespace EdgeVoyager
             ApplicationConfiguration.Initialize();
             Settings1.Default.firstwindow = true;
             Settings1.Default.Save();
-            Application.Run(new Form1());
+            Application.Run(new main());
         }
     }
 }

+ 1 - 1
Readme.md

@@ -1,4 +1,4 @@
-![](https://www.lykns.com.cn/wp-content/uploads/2025/01/%E6%97%A0%E6%A0%87%E9%A2%98.png)
+![](https://www.lykns.com.cn/wp-content/uploads/2025/01/connection_status_on.svg)
 # **下一步的任务:**
 1. 发现bug
 2. 制作安装程序

+ 22 - 1
Settings1.Designer.cs

@@ -1,4 +1,13 @@
-
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     此代码由工具生成。
+//     运行时版本:4.0.30319.42000
+//
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
 namespace EdgeVoyager {
     
     
@@ -25,5 +34,17 @@ namespace EdgeVoyager {
                 this["firstwindow"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("1")]
+        public int windows_num {
+            get {
+                return ((int)(this["windows_num"]));
+            }
+            set {
+                this["windows_num"] = value;
+            }
+        }
     }
 }

+ 3 - 0
Settings1.settings

@@ -5,5 +5,8 @@
     <Setting Name="firstwindow" Type="System.Boolean" Scope="User">
       <Value Profile="(Default)">True</Value>
     </Setting>
+    <Setting Name="windows_num" Type="System.Int32" Scope="User">
+      <Value Profile="(Default)">1</Value>
+    </Setting>
   </Settings>
 </SettingsFile>

+ 57 - 0
main.Designer.cs

@@ -0,0 +1,57 @@
+namespace EdgeVoyager
+{
+    partial class main
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            components = new System.ComponentModel.Container();
+            timer1 = new System.Windows.Forms.Timer(components);
+            SuspendLayout();
+            // 
+            // timer1
+            // 
+            timer1.Enabled = true;
+            timer1.Interval = 1000;
+            timer1.Tick += timer1_Tick;
+            // 
+            // main
+            // 
+            AutoScaleDimensions = new SizeF(7F, 17F);
+            AutoScaleMode = AutoScaleMode.Font;
+            ClientSize = new Size(0, 0);
+            FormBorderStyle = FormBorderStyle.None;
+            Name = "main";
+            Text = "main";
+            Shown += main_Shown;
+            ResumeLayout(false);
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Timer timer1;
+    }
+}

+ 33 - 0
main.cs

@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace EdgeVoyager
+{
+    public partial class main : Form
+    {
+        public main()
+        {
+            InitializeComponent();
+        }
+
+        private void main_Shown(object sender, EventArgs e)
+        {
+            Form1 form1 = new Form1();
+            this.Hide();
+            form1.Show();
+        }
+
+        private void timer1_Tick(object sender, EventArgs e)
+        {
+            if(Settings1.Default.windows_num==0)
+                Environment.Exit(0);
+        }
+    }
+}

+ 123 - 0
main.resx

@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!--
+    Microsoft ResX Schema
+
+    Version 2.0
+
+    The primary goals of this format is to allow a simple XML format
+    that is mostly human readable. The generation and parsing of the
+    various data types are done through the TypeConverter classes
+    associated with the data types.
+
+    Example:
+
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+
+    There are any number of "resheader" rows that contain simple
+    name/value pairs.
+
+    Each data row contains a name, and value. The row also contains a
+    type or mimetype. Type corresponds to a .NET class that support
+    text/value conversion through the TypeConverter architecture.
+    Classes that don't support this are serialized and stored with the
+    mimetype set.
+
+    The mimetype is used for serialized objects, and tells the
+    ResXResourceReader how to depersist the object. This is currently not
+    extensible. For a given mimetype the value must be set accordingly:
+
+    Note - application/x-microsoft.net.object.binary.base64 is the format
+    that the ResXResourceWriter will generate, however the reader can
+    read any of the formats listed below.
+
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+</root>