diff --git a/LoCyanFrpDesktop/App.xaml.cs b/LoCyanFrpDesktop/App.xaml.cs index 36609d7..458bd50 100644 --- a/LoCyanFrpDesktop/App.xaml.cs +++ b/LoCyanFrpDesktop/App.xaml.cs @@ -12,6 +12,9 @@ using System.Runtime.InteropServices; using System.Threading; using System.Security; +using CefSharp.Wpf; +using System.Runtime.ConstrainedExecution; +using CefSharp; namespace LoCyanFrpDesktop { @@ -60,8 +63,15 @@ protected override void OnStartup(StartupEventArgs e) });*/ base.OnStartup(e); //MainWindow mainWindow = new(); + var settings = new CefSettings() + { + //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data + CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"), + LogSeverity = LogSeverity.Verbose, + LogFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs\\CEF.log") + }; - + Cef.Initialize(settings); if (args.Length > 0) { int i = 0; @@ -118,6 +128,11 @@ protected override void OnStartup(StartupEventArgs e) } } + protected override void OnExit(ExitEventArgs e) + { + Cef.Shutdown(); + base.OnExit(e); + } private static void CurrentDomain_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; diff --git a/LoCyanFrpDesktop/DashBoard.xaml b/LoCyanFrpDesktop/DashBoard.xaml index 09b1510..9cb0110 100644 --- a/LoCyanFrpDesktop/DashBoard.xaml +++ b/LoCyanFrpDesktop/DashBoard.xaml @@ -55,11 +55,17 @@ SelectedPageIndex="0"> + Content="开始" + Icon="Home24" + PageTag="Home" + PageType="{x:Type Dashboard:Home}" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LoCyanFrpDesktop/Dashboard/Home.xaml.cs b/LoCyanFrpDesktop/Dashboard/Home.xaml.cs new file mode 100644 index 0000000..8ebcfea --- /dev/null +++ b/LoCyanFrpDesktop/Dashboard/Home.xaml.cs @@ -0,0 +1,189 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Net.Http; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using Wpf.Ui.Controls; +using LoCyanFrpDesktop.Utils; +using LoCyanFrpDesktop.Dashboard; +using System.Windows.Threading; +using System.Text.RegularExpressions; +using System.IO; +using LoCyanFrpDesktop.Extensions; +using System.Security.Cryptography; +using Markdig; +using System.Windows.Controls; +using CefSharp; +using CefSharp.Wpf; +using System.Text; +using HtmlAgilityPack; + + +namespace LoCyanFrpDesktop.Dashboard +{ + /// + /// Interaction logic for ProxyList.xaml + /// + public partial class Home : UiPage + { + public static ImageBrush AvatarImage; + public Home() + { + InitializeComponent(); + //Wait For Rewrite. + //InitializeAutoLaunch(); + DataContext = this; + title_username.Text += Global.Config.Username; + Resources["BorderColor"] = MainWindow.DarkThemeEnabled ? Colors.White : Colors.LightGray; + //BackgroundColor = Resources["ControlFillColorDefaultBrush"]; + //Inbound.Text += MainWindow.Inbound; + //OutBound.Text += MainWindow.Outbound; + Traffic.Text += (MainWindow.Traffic / 1024) + "GB"; + + RefreshAvatar(); + FetchAnnouncement(); + } + private async void FetchAnnouncement() + { + try + { + using (HttpClient client = new()) + { + client.BaseAddress = new Uri("https://api.locyanfrp.cn/App/GetBroadCast"); + var result = await client.GetAsync(client.BaseAddress).Await().Content.ReadAsStringAsync(); + var result2 = JObject.Parse(result); + if (result2 != null && (bool)result2["status"]) { + var html = Markdown.ToHtml(result2["broadcast"].ToString()); + var htmlDoc = new HtmlDocument(); + if (MainWindow.DarkThemeEnabled) + { + htmlDoc.LoadHtml(html); + var cssContent = "* { color: white; } a { color: aqua}"; + var styleNode = HtmlNode.CreateNode($""); + var scriptNode = HtmlNode.CreateNode(""); + var newHeadNode = htmlDoc.CreateElement("head"); + newHeadNode.AppendChild(styleNode); + newHeadNode.AppendChild(scriptNode); + htmlDoc.DocumentNode.PrependChild(newHeadNode); + } + Browser.LoadHtml(MainWindow.DarkThemeEnabled ? htmlDoc.DocumentNode.OuterHtml: html, "http://localhost",Encoding.UTF8); + Browser.LoadingStateChanged += OnLoadingStateChanged; + + } + + } + } + catch (Exception _) { + + } + } + private void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs e) + { + if (!e.IsLoading) + { + string css = @" + html { + scroll-behavior: smooth; + } + ::-webkit-scrollbar { + width: 8px; + opacity: 0; + transition: opacity 0.5s; + } + ::-webkit-scrollbar-track { + background: #555; + border-radius: 10px; /* Rounded corners for the track */ + } + ::-webkit-scrollbar-thumb { + background: #f1f1f1; + + border-radius: 10px; /* Rounded corners for the track */ + } + ::-webkit-scrollbar-thumb:hover { + background: #888; + + } + .show-scrollbar ::-webkit-scrollbar { + opacity: 1;"; + string script = $"var style = document.createElement('style'); style.innerHTML = `{css}`; document.head.appendChild(style);"; + string script2 = "let timeout; document.addEventListener('scroll', function() { document.documentElement.classList.add('show-scrollbar'); clearTimeout(timeout); timeout = setTimeout(() => { document.documentElement.classList.remove('show-scrollbar'); }, 1000); });"; + Browser.ExecuteScriptAsync(script); + Browser.ExecuteScriptAsync(script2); + + } + } + private async void RefreshAvatar() + { + try + { + using (var client = new HttpClient()) + { + + client.BaseAddress = new Uri(MainWindow.Avatar); + var Avatar = await client.GetAsync(client.BaseAddress).Await().Content.ReadAsStreamAsync(); + var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Avatar.png"); + var ApplyAvatar = () => + { + BitmapImage bitmap = new BitmapImage(); + + // 设置 BitmapImage 的 UriSource 属性为图片文件的路径 + bitmap.BeginInit(); + bitmap.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); + bitmap.EndInit(); + AvatarImage = new ImageBrush(bitmap) + { + Stretch = Stretch.UniformToFill, + + }; + + Dispatcher.Invoke(() => + { + this.Avatar.Background = AvatarImage; + }); + }; + + if (File.Exists(path)){ + MD5 md5 = MD5.Create(); + if (md5.ComputeHash(Avatar).Equals(md5.ComputeHash(File.ReadAllBytes("Avatar.png")))) + { + ApplyAvatar(); + return; + } + + File.Delete(path); + using (FileStream fileStream = new(path, FileMode.Create)) + { + byte[] bytes = new byte[Avatar.Length]; + Avatar.Read(bytes, 0, bytes.Length); + // 设置当前流的位置为流的开始 + Avatar.Seek(0, SeekOrigin.Begin); + + // 把 byte[] 写入文件 + + BinaryWriter bw = new BinaryWriter(fileStream); + bw.Write(bytes); + bw.Close(); + fileStream.Close(); + fileStream.Dispose(); + } + ApplyAvatar(); + } + + + } + + } + catch (Exception ex) + { + Logger.MsgBox("无法获取您的头像, 请稍后重试", "LocyanFrp", 0, 48, 1); + } + } + + + } +} + + +//BreakAutoCompileBecauseTheRewriteIsNOTFinished diff --git a/LoCyanFrpDesktop/Dashboard/ProxyList.xaml b/LoCyanFrpDesktop/Dashboard/ProxyList.xaml index 9c07354..426fdb6 100644 --- a/LoCyanFrpDesktop/Dashboard/ProxyList.xaml +++ b/LoCyanFrpDesktop/Dashboard/ProxyList.xaml @@ -48,7 +48,7 @@ - + @@ -78,30 +78,11 @@ - - - - - - - - - - - - - - - - - - - + diff --git a/LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs b/LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs index 048c3bb..1878116 100644 --- a/LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs +++ b/LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs @@ -23,25 +23,13 @@ using System.Text.RegularExpressions; using System.IO; using static LoCyanFrpDesktop.Utils.PNAP; -using System.Drawing.Printing; -using System.Xml.Linq; -using HandyControl.Tools.Extension; using MenuItem = Wpf.Ui.Controls.MenuItem; -using Wpf.Ui.Appearance; -using System.Reflection; -using Wpf.Ui.Styles.Controls; -using ContextMenu2 = Wpf.Ui.Styles.Controls.ContextMenu; using ContextMenu = System.Windows.Controls.ContextMenu; -using System.DirectoryServices.ActiveDirectory; -using System.Printing; -using Microsoft.Exchange.WebServices.Data; using System.Windows.Media.Animation; using System.Drawing; using System.Windows.Shapes; using Brushes = System.Windows.Media.Brushes; using Color = System.Windows.Media.Color; -using Brush = System.Windows.Media.Brush; -using System.Runtime.CompilerServices; using LoCyanFrpDesktop.Extensions; using Microsoft.Win32.SafeHandles; @@ -71,67 +59,17 @@ public ProxyList() //Wait For Rewrite. //InitializeAutoLaunch(); DataContext = this; - title_username.Text += Global.Config.Username; Resources["BorderColor"] = MainWindow.DarkThemeEnabled ? Colors.White : Colors.LightGray; //BackgroundColor = Resources["ControlFillColorDefaultBrush"]; BackgroundMenu = new(); //Inbound.Text += MainWindow.Inbound; //OutBound.Text += MainWindow.Outbound; - Traffic.Text += (MainWindow.Traffic / 1024) + "GB"; - RefreshAvatar(); - } - private async void RefreshAvatar() - { - try + if(Home.AvatarImage != null) { - using (var client = new HttpClient()) { - client.BaseAddress = new Uri(MainWindow.Avatar); - var Avatar = await client.GetAsync(client.BaseAddress).Await().Content.ReadAsStreamAsync(); - var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Avatar.png"); - - if (File.Exists(path)) - { - File.Delete(path); - } - - using(FileStream fileStream = new(path, FileMode.Create)) - { - byte[] bytes = new byte[Avatar.Length]; - Avatar.Read(bytes, 0, bytes.Length); - // 设置当前流的位置为流的开始 - Avatar.Seek(0, SeekOrigin.Begin); - - // 把 byte[] 写入文件 - - BinaryWriter bw = new BinaryWriter(fileStream); - bw.Write(bytes); - bw.Close(); - fileStream.Close(); - } - BitmapImage bitmap = new BitmapImage(); - - // 设置 BitmapImage 的 UriSource 属性为图片文件的路径 - bitmap.BeginInit(); - bitmap.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); - bitmap.EndInit(); - var a = new ImageBrush(bitmap) - { - Stretch = Stretch.UniformToFill, - - }; - - Dispatcher.Invoke(() => - { - this.Avatar.Background = a; - }); - - - } - - } - catch (Exception ex) - { - Logger.MsgBox("无法获取您的头像, 请稍后重试", "LocyanFrp", 0, 48, 1); + Dispatcher.Invoke(() => + { + this.Avatar.Background = Home.AvatarImage; + }); } } @@ -227,6 +165,11 @@ private static int ProxyStarter(string SelectedProxy,int SelectedIndex) string proxy_name = SelectedProxy; int proxy_id = 0; + if (Global.Config.FrpcPath == null) + { + Logger.MsgBox("您尚未安装Frpc,请先安装或者手动指定", "LocyanFrp", 0, 48, 1); + return 0; + } foreach (var item in Proxieslist) { if (item.ProxyName == proxy_name) @@ -241,7 +184,7 @@ private static int ProxyStarter(string SelectedProxy,int SelectedIndex) Logger.MsgBox("无法将隧道名解析为隧道ID,请检查自己的隧道配置", "LocyanFrp", 0, 48, 1); return 0; } - Access.DashBoard.Navigation.Navigate(1); + Access.DashBoard.Navigation.Navigate(2); // 运行frp try { diff --git a/LoCyanFrpDesktop/Global.cs b/LoCyanFrpDesktop/Global.cs index 5c47209..2ac83f6 100644 --- a/LoCyanFrpDesktop/Global.cs +++ b/LoCyanFrpDesktop/Global.cs @@ -17,7 +17,7 @@ internal static class Global public static bool LoginedByConsole = false; public const string Version = "2.2.0"; public const string Branch = "Alpha"; - public const int Revision = 1; + public const int Revision = 2; public static readonly BuildInfo BuildInfo = new(); public const string Developer = "Shiroiame-Kusu & Daiyangcheng"; public const string Copyright = "Copyright © 2021 - 2024 杭州樱芸网络科技有限公司 All Rights Reserved"; diff --git a/LoCyanFrpDesktop/LoCyanFrpDesktop.csproj b/LoCyanFrpDesktop/LoCyanFrpDesktop.csproj index b7e7676..32744d8 100644 --- a/LoCyanFrpDesktop/LoCyanFrpDesktop.csproj +++ b/LoCyanFrpDesktop/LoCyanFrpDesktop.csproj @@ -13,6 +13,7 @@ false true true + true true @@ -25,6 +26,7 @@ LoCyanFrpDesktop enable + app.manifest embedded @@ -39,14 +41,17 @@ + + + - + diff --git a/LoCyanFrpDesktop/app.manifest b/LoCyanFrpDesktop/app.manifest new file mode 100644 index 0000000..c998c7b --- /dev/null +++ b/LoCyanFrpDesktop/app.manifest @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LoCyanFrpDesktop/resource/net6.0/Updater.dll b/LoCyanFrpDesktop/resource/net6.0/Updater.dll index 4a23fa0..84e55a1 100644 Binary files a/LoCyanFrpDesktop/resource/net6.0/Updater.dll and b/LoCyanFrpDesktop/resource/net6.0/Updater.dll differ diff --git a/LoCyanFrpDesktop/resource/net6.0/Updater.exe b/LoCyanFrpDesktop/resource/net6.0/Updater.exe index 7d2abdd..3ab20ad 100644 Binary files a/LoCyanFrpDesktop/resource/net6.0/Updater.exe and b/LoCyanFrpDesktop/resource/net6.0/Updater.exe differ