Browse Source

提交自定义起始页

CaptB 4 months ago
parent
commit
9d5e38cf8d
3 changed files with 227 additions and 22 deletions
  1. 11 0
      EdgeVoyager.csproj
  2. 142 22
      Form1.cs
  3. 74 0
      html/index.html

+ 11 - 0
EdgeVoyager.csproj

@@ -8,6 +8,17 @@
     <ImplicitUsings>enable</ImplicitUsings>
   </PropertyGroup>
 
+  <ItemGroup>
+    <None Remove="html\index.html" />
+    <None Remove="index.html" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <Content Include="html\index.html">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
   <ItemGroup>
     <PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2903.40" />
   </ItemGroup>

+ 142 - 22
Form1.cs

@@ -1,13 +1,4 @@
 using Microsoft.Web.WebView2.Core;
-using System.Drawing.Imaging;
-using System;
-using System.Drawing;
-using System.IO;
-using System.Net.Http;
-using System.Windows.Forms;
-using Microsoft.Web.WebView2.Core;
-using Microsoft.Web.WebView2.WinForms;
-using Microsoft.Web.WebView2.Wpf;
 
 namespace EdgeVoyager
 {
@@ -36,7 +27,129 @@ namespace EdgeVoyager
             webView21.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
             if (Settings1.Default.firstwindow == true)
             {
-                webView21.CoreWebView2.Navigate("https://cn.bing.com/?mkt=zh-CN");
+                //webView21.Source = new Uri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "html", "index.html"));
+                string htmlString = @"<!DOCTYPE html>
+<html lang=""zh-CN"">
+<head>
+    <meta charset=""UTF-8"">
+    <meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
+    <title>起始页</title>
+    <style>
+        body {
+            margin: 0;
+            padding: 0;
+            background-image: url('https://bing.img.run/uhd.php');
+            background-size: cover;
+            background-repeat: no-repeat;
+            background-attachment: fixed;
+            font-family: Arial, sans-serif;
+        }
+        .header {
+            background-color: rgba(255, 255, 255, 0.8); /* 磨砂玻璃效果 */
+            backdrop-filter: blur(10px);
+            padding: 10px 20px;
+            display: flex;
+            align-items: center;
+            position: relative;
+            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
+        }
+        .logo {
+            width: auto;
+            height: auto;
+        }
+        .nav-item {
+            margin-left: 20px;
+            color: #333;
+            text-decoration: none;
+            font-size: 16px;
+        }
+        .nav-links {
+            display: flex;
+            align-items: center;
+        }
+        .welcome-text {
+            text-align: center;
+            margin: 20px 0;
+            font-size: 24px; /* 加大字体 */
+            font-weight: bold; /* 加粗字体 */
+            color: #0078D4; /* 颜色设置为0078D4 */
+        }
+        .search-container {
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            margin-top: 20px;
+            border-radius: 15px; /* 搜索条圆角 */
+            overflow: hidden; /* 隐藏溢出部分,确保圆角效果 */
+        }
+        .search-input {
+            width: 70vw; /* 搜索框宽度为视口宽度的85% */
+            max-width: 1000px; /* 搜索框最大宽度不超过1000px */
+            padding: 10px;
+            font-size: 16px;
+            border: none;
+            border-radius: 15px 0 0 15px; /* 搜索框左圆角 */
+            height: 20px; /* 设置高度 */
+        }
+        .search-button {
+            padding: 10px 20px;
+            font-size: 16px;
+            cursor: pointer;
+            border: none;
+            background-color: #0078D4;
+            color: white;
+            border-radius: 0 15px 15px 0; /* 搜索按钮右圆角 */
+            height: 40px; /* 设置高度 */
+        }
+        .acrylic-panel {
+            background-color: rgba(255, 255, 255, 0.8); /* 磨砂玻璃效果 */
+            backdrop-filter: blur(10px);
+            padding: 20px;
+            border-radius: 8px;
+            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
+            margin: 20px 0;
+            width: 90vw; /* 面板宽度为视口宽度的90% */
+            margin-left: auto;
+            margin-right: auto;
+            max-width: 1200px; /* 面板最大宽度不超过1200px */
+        }
+        @media (max-width: 600px) {
+            .search-button {
+                padding: 8px 16px; /* 在小屏幕设备上调整按钮内边距 */
+            }
+        }
+    </style>
+</head>
+<body>
+    <div class=""header"">
+        <img src=""https://www.lykns.com.cn/wp-content/uploads/2025/01/pinwheel_48px.png"" alt=""Logo"" class=""logo"">
+        <span style=""font-size: 24px; color: #333; margin-left: 0;"">LYKNS</span>
+        <div class=""nav-links"">
+            <a href=""https://www.lykns.com.cn"" class=""nav-item"">LYKNS 主站</a>
+            <a href=""https://its.lykns.com.cn"" class=""nav-item"">云服务</a>
+            <a href=""https://dev.lykns.com.cn"" class=""nav-item"">Git 服务</a>
+            <a href=""https://survey.lykns.com.cn"" class=""nav-item"">问卷考试系统</a>
+        </div>
+    </div>
+    <div class=""acrylic-panel"">
+        <div class=""welcome-text"">
+            欢迎使用LYKNS EdgeVoyager!
+        </div>
+        <div class=""search-container"">
+            <input type=""text"" id=""search-input"" class=""search-input"" placeholder=""搜索..."">
+            <button onclick=""search()"" class=""search-button"">搜索</button>
+        </div>
+    </div>
+    <script>
+        function search() {
+            var query = document.getElementById('search-input').value;
+            window.location.href = 'https://cn.bing.com/search?q=' + encodeURIComponent(query);
+        }
+    </script>
+</body>
+</html>";
+
+                webView21.CoreWebView2.NavigateToString(htmlString);
                 Settings1.Default.firstwindow = false;
                 Settings1.Default.Save();
             }
@@ -95,24 +208,31 @@ namespace EdgeVoyager
             this.Text = "LYKNS EdgeVoyager:" + title.Trim('"');
 
             string faviconUrl = await webView21.CoreWebView2.ExecuteScriptAsync("Array.from(document.querySelectorAll('link[rel=\"icon\"], link[rel=\"shortcut icon\"]')).map(link => link.href).find(url => url);");
-            faviconUrl = faviconUrl.Trim('"'); // 去掉引号
+            faviconUrl = faviconUrl.Trim('"');
 
             if (!string.IsNullOrEmpty(faviconUrl))
             {
-                using (var client = new HttpClient())
+                Uri uriResult;
+                bool isAbsoluteUri = Uri.TryCreate(faviconUrl, UriKind.Absolute, out uriResult);
+
+                if (isAbsoluteUri)
                 {
-                    var faviconData = await client.GetByteArrayAsync(faviconUrl);
-                    using (var ms = new MemoryStream(faviconData))
+                    using (var client = new HttpClient())
                     {
-                        using (var img = Image.FromStream(ms))
+
+                        var faviconData = await client.GetByteArrayAsync(uriResult);
+                        using (var ms = new MemoryStream(faviconData))
                         {
-                            if (img is Bitmap bitmap)
-                            {
-                                this.Icon = Icon.FromHandle(bitmap.GetHicon());
-                            }
-                            else
+                            using (var img = Image.FromStream(ms))
                             {
-                                this.Icon = Icon.FromHandle(((Bitmap)img.Clone()).GetHicon());
+                                if (img is Bitmap bitmap)
+                                {
+                                    this.Icon = Icon.FromHandle(bitmap.GetHicon());
+                                }
+                                else
+                                {
+                                    this.Icon = Icon.FromHandle(((Bitmap)img.Clone()).GetHicon());
+                                }
                             }
                         }
                     }
@@ -143,7 +263,7 @@ namespace EdgeVoyager
 
         private void webView21_ContentLoading(object sender, CoreWebView2ContentLoadingEventArgs e)
         {
-            progressBar.Value = 50; // 假设加载内容时进度为50%
+            progressBar.Value = 50;
             progressLabel.Text = "50%";
             StatusLabel.Text = "内容开始加载";
         }

+ 74 - 0
html/index.html

@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>自定义起始页</title>
+    <style>
+        body {
+            margin: 0;
+            padding: 0;
+            background-image: url('https://bing.img.run/uhd.php');
+            background-size: cover;
+            background-repeat: no-repeat;
+            background-attachment: fixed;
+            font-family: Arial, sans-serif;
+        }
+        .header {
+            background-color: rgba(255, 255, 255, 0.8);
+            padding: 10px 20px;
+            display: flex;
+            justify-content: space-between;
+            align-items: center;
+            position: relative;
+        }
+        .logo {
+            width: auto;
+            height: auto;
+        }
+        .nav-item {
+            margin-left: 20px;
+            color: #333;
+            text-decoration: none;
+            font-size: 16px;
+        }
+        .search-container {
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            margin-top: 50px;
+        }
+        .search-input {
+            width: 60%;
+            padding: 10px;
+            font-size: 16px;
+        }
+        .search-button {
+            padding: 10px 20px;
+            font-size: 16px;
+            cursor: pointer;
+        }
+    </style>
+</head>
+<body>
+    <div class="header">
+        <img src="https://www.lykns.com.cn/wp-content/uploads/2025/01/pinwheel_48px.png" alt="Logo" class="logo">
+        <div>
+            <a href="https://www.lykns.com.cn" class="nav-item">LYKNS 主站</a>
+            <a href="https://its.lykns.com.cn" class="nav-item">云服务</a>
+            <a href="https://dev.lykns.com.cn" class="nav-item">Git 服务</a>
+            <a href="https://survey.lykns.com.cn" class="nav-item">问卷考试系统</a>
+        </div>
+    </div>
+    <div class="search-container">
+        <input type="text" id="search-input" class="search-input" placeholder="搜索...">
+        <button onclick="search()" class="search-button">搜索</button>
+    </div>
+    <script>
+        function search() {
+            var query = document.getElementById('search-input').value;
+            window.location.href = 'https://cn.bing.com/search?q=' + encodeURIComponent(query);
+        }
+    </script>
+</body>
+</html>