This repository has been archived by the owner on Dec 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ver 2.2.0-Alpha.2: Show Announcement.
- Loading branch information
1 parent
5655ebe
commit 16ac3e0
Showing
11 changed files
with
385 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<ui:UiPage xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
x:Class="LoCyanFrpDesktop.Dashboard.Home" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:LoCyanFrpDesktop.Dashboard" | ||
xmlns:cefSharpCore="clr-namespace:CefSharp;assembly=CefSharp.Core" | ||
xmlns:cefSharpWpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" | ||
Title="Home"> | ||
<Grid Margin="0,0,20,0"> | ||
<Grid.Resources> | ||
<SolidColorBrush x:Key="BorderColor"/> | ||
</Grid.Resources> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="60"/> | ||
<RowDefinition Height="*"/> | ||
</Grid.RowDefinitions> | ||
<Grid Grid.Row="0" HorizontalAlignment="Left"> | ||
<DockPanel VerticalAlignment="Stretch"> | ||
<Border CornerRadius="20" Height="40" Width="40" BorderThickness="1" BorderBrush="LightBlue" Margin="10,0,10,0" Name="Avatar"> | ||
<Border.Background> | ||
<ImageBrush Stretch="UniformToFill" ImageSource="/Resource/favicon.ico"/> | ||
</Border.Background> | ||
</Border> | ||
<TextBlock VerticalAlignment="Center" Name="title_username" Text="欢迎回来," FontSize="25" Margin="0,0,10,0" /> | ||
|
||
</DockPanel> | ||
|
||
</Grid> | ||
<Grid Grid.Row="1"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="70"/> | ||
</Grid.RowDefinitions> | ||
<Grid Grid.Row="0" Margin="2"> | ||
|
||
<Border | ||
Grid.Column="1" | ||
Margin="10,0" | ||
Padding="10,5" | ||
CornerRadius="8" | ||
Background="{DynamicResource ControlFillColorDefaultBrush}" | ||
> | ||
<cefSharpWpf:ChromiumWebBrowser x:Name="Browser"> | ||
|
||
</cefSharpWpf:ChromiumWebBrowser> | ||
</Border> | ||
</Grid> | ||
<Grid Grid.Row="1"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="auto"/> | ||
<ColumnDefinition Width="auto"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
<ui:Card Grid.Column="1" Padding="10" Margin="10,10,0,15" VerticalAlignment="Bottom"> | ||
<StackPanel> | ||
<!--<TextBlock Name="Inbound" Margin="0,0,0,20" Text="上行流量:"/> | ||
<TextBlock Name="OutBound" Text="下行流量:"/>--> | ||
<TextBlock Name="Traffic" Text="剩余流量: "/> | ||
</StackPanel> | ||
</ui:Card> | ||
|
||
|
||
</Grid> | ||
</Grid> | ||
|
||
</Grid> | ||
</ui:UiPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Interaction logic for ProxyList.xaml | ||
/// </summary> | ||
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($"<style>{cssContent}</style>"); | ||
var scriptNode = HtmlNode.CreateNode("<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/smooth-scrollbar.js'></script>"); | ||
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; | ||
Check warning on line 72 in LoCyanFrpDesktop/Dashboard/Home.xaml.cs GitHub Actions / BuildForWindows
|
||
|
||
} | ||
|
||
} | ||
} | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.