Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
Ver 2.2.0-Alpha.3: Now You Can Change the Themes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiroiame-Kusu committed Aug 7, 2024
1 parent 6ed1bf0 commit 1f3d9b9
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 138 deletions.
28 changes: 3 additions & 25 deletions LoCyanFrpDesktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace LoCyanFrpDesktop

public partial class App : Application
{
public static string? Username = null;
public static string? Password = null;
private static string? Username = null;
private static string? Password = null;
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
Expand All @@ -38,7 +38,6 @@ public partial class App : Application

protected override void OnStartup(StartupEventArgs e)
{
//bool openConsole = false;
CrashInterception.Init();
ConfigManager.Init();

Expand All @@ -47,34 +46,13 @@ protected override void OnStartup(StartupEventArgs e)
int UsernameNum = 0;
int PasswordNum = 0;
bool DebugMode = Global.Config.DebugMode;
//string Username;
//string Password;
// 处理启动参数

string[] args = e.Args;
/*Task.Run(() =>
{
while (true) {
using(ConfigManager ConfigManager = new(FileMode.Create))
{
Console.WriteLine("Saving...");
}
Thread.Sleep(1000);
}
});*/
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;
for (int j = 0; j < args.Count(); j++) {
if (args[j] == "--user" || args[j] == "--User" || args[j] == "--Username" || args[j] == "--username")
{
Expand Down
39 changes: 22 additions & 17 deletions LoCyanFrpDesktop/DashBoard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Microsoft.VisualBasic;
using System.Threading;
using System.Windows.Shapes;
using Wpf.Ui.Appearance;

namespace LoCyanFrpDesktop
{
Expand All @@ -36,9 +37,8 @@ namespace LoCyanFrpDesktop
public partial class DashBoard : UiWindow
{
public static bool isFrpcInstalled;
//public static Snackbar Snackbar = new Snackbar();
public double originalCenterX;
public double originalCenterY;
private static SolidColorBrush DarkBrush = new SolidColorBrush(Color.FromRgb(32, 32, 32));
private static SolidColorBrush LightBrush = new SolidColorBrush(Color.FromRgb(250, 250, 250));
/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -85,14 +85,6 @@ public bool CheckIfFrpcInstalled()
}
public void DownloadFrpc()
{
//double screenWidth = SystemParameters.WorkArea.Width;
//double screenHeight = SystemParameters.WorkArea.Height;

// 获取原窗口的中心点
//originalCenterX = Owner.Left + Owner.Width / 2;
//originalCenterY = Owner.Top + Owner.Height / 2;
//Left = originalCenterX - Width / 2;
//Top = originalCenterY - Height / 2;
Download downloader = new Download();
downloader.Owner = this;
downloader.Show();
Expand All @@ -111,9 +103,7 @@ private void UiWindow_Closing(object sender, CancelEventArgs e)
Hide();
}
public void UiWindow_StateChanged(object sender, EventArgs e)
{/*
MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth; */
{
}
public void UiWindow_ContentRendered(object sender, EventArgs e)
{
Expand All @@ -133,10 +123,25 @@ public void Exit_Click(object sender, RoutedEventArgs e)
}
public void UiWindow_Loaded(object sender, EventArgs e)
{
Resources["ShadowColor"] = MainWindow.DarkThemeEnabled ? Colors.White : Colors.LightGray; ;
Resources["MainBackgroundColor"] = new SolidColorBrush(MainWindow.DarkThemeEnabled ? Colors.LightGray : Colors.WhiteSmoke);
ChangeColor();
}
public void ChangeColor()
{
Resources["ShadowColor"] = Global.isDarkThemeEnabled ? Colors.White : Colors.LightGray;
SolidColorBrush solidColorBrush = new SolidColorBrush(Global.isDarkThemeEnabled ? Colors.LightGray : Colors.WhiteSmoke);
Resources["MainBackgroundColor"] = solidColorBrush;
if (Global.isDarkThemeEnabled)
{
this.Background = DarkBrush;
Theme.Apply(ThemeType.Dark);
}
else {
this.Background = LightBrush;
Theme.Apply(ThemeType.Light);
}
//Theme.Apply(Global.isDarkThemeEnabled ? ThemeType.Dark : ThemeType.Light);
//this.Background = solidColorBrush;
}


}
}
7 changes: 6 additions & 1 deletion LoCyanFrpDesktop/Dashboard/Home.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ui:Card Grid.Column="1" Padding="10" Margin="10,10,0,15" VerticalAlignment="Bottom">
<ui:Card Height="40" Grid.Column="0" Padding="10" Margin="10,10,0,15" VerticalAlignment="Center">
<StackPanel>
<TextBlock Name="BandWidth" Margin="0,0,0,20" Text="上行/下行带宽: "/>
</StackPanel>
</ui:Card>
<ui:Card Height="40" Grid.Column="1" Padding="10" Margin="10,10,0,15" VerticalAlignment="Center">
<StackPanel>
<!--<TextBlock Name="Inbound" Margin="0,0,0,20" Text="上行流量:"/>
<TextBlock Name="OutBound" Text="下行流量:"/>-->
Expand Down
35 changes: 24 additions & 11 deletions LoCyanFrpDesktop/Dashboard/Home.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,33 @@ public partial class Home : UiPage
public static ImageBrush AvatarImage;
public Home()
{
InitializeComponent();
InitializeCustomComponents();
//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();
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
}

private void InitializeCustomComponents()
{
Cef.Initialize(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")
});
InitializeComponent();
DataContext = this;
title_username.Text += Global.Config.Username;
Resources["BorderColor"] = Global.isDarkThemeEnabled ? Colors.White : Colors.LightGray;
Traffic.Text += $"{(MainWindow.Traffic / 1024)}GB";
BandWidth.Text += $"{MainWindow.Inbound}/{MainWindow.Outbound}Mbps";
}
private async void FetchAnnouncement()
{
try
Expand All @@ -57,7 +70,7 @@ private async void FetchAnnouncement()
if (result2 != null && (bool)result2["status"]) {

Check warning on line 70 in LoCyanFrpDesktop/Dashboard/Home.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows

Possible null reference argument for parameter 'value' in 'JToken.explicit operator bool(JToken value)'.
var html = Markdown.ToHtml(result2["broadcast"].ToString());

Check warning on line 71 in LoCyanFrpDesktop/Dashboard/Home.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows

Dereference of a possibly null reference.
var htmlDoc = new HtmlDocument();
if (MainWindow.DarkThemeEnabled)
if (Global.isDarkThemeEnabled)
{
htmlDoc.LoadHtml(html);
var cssContent = "* { color: white; } a { color: aqua}";
Expand All @@ -68,7 +81,7 @@ private async void FetchAnnouncement()
newHeadNode.AppendChild(scriptNode);
htmlDoc.DocumentNode.PrependChild(newHeadNode);
}
Browser.LoadHtml(MainWindow.DarkThemeEnabled ? htmlDoc.DocumentNode.OuterHtml: html, "http://localhost",Encoding.UTF8);
Browser.LoadHtml(Global.isDarkThemeEnabled ? htmlDoc.DocumentNode.OuterHtml: html, "http://localhost",Encoding.UTF8);
Browser.LoadingStateChanged += OnLoadingStateChanged;

}
Expand Down
38 changes: 6 additions & 32 deletions LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ProxyList()
//Wait For Rewrite.
//InitializeAutoLaunch();
DataContext = this;
Resources["BorderColor"] = MainWindow.DarkThemeEnabled ? Colors.White : Colors.LightGray;
Resources["BorderColor"] = Global.isDarkThemeEnabled ? Colors.White : Colors.LightGray;
//BackgroundColor = Resources["ControlFillColorDefaultBrush"];
BackgroundMenu = new();
//Inbound.Text += MainWindow.Inbound;
Expand Down Expand Up @@ -138,16 +138,6 @@ private async Task<ObservableCollection<string>> GetProxiesListAsync()
Dispatcher.Invoke(() =>
{
ListPanel.Children.Add(new ProxyCard(responseObject.Proxies[i], i));
/*ListPanel.Children.Add(new Card()
{
//Background = new SolidColorBrush(Colors.White),
Padding = new Thickness(10),
Margin = new Thickness(0, 0, 10, 0),
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
MinHeight = 50,
MinWidth = 100
});*/

});

Expand Down Expand Up @@ -367,7 +357,7 @@ public ProxyCard(Proxy ProxyInfo, int CardIndex)
//this.OverridesDefaultStyle = true;
//this.Style = ProxyList.card.Style;
//Theme.Apply(ThemeType.Light);
this.Background = new SolidColorBrush(MainWindow.DarkThemeEnabled ? Color.FromRgb(53, 53, 53) : Color.FromRgb(210, 210, 210));
this.Background = new SolidColorBrush(Global.isDarkThemeEnabled ? Color.FromRgb(53, 53, 53) : Color.FromRgb(210, 210, 210));
//this.Background = new SolidColorBrush(!string.IsNullOrEmpty((string)ProxyList.BackgroundColor) ? (Color)ProxyList.BackgroundColor : Colors.Gray);
//this.Background = new SolidColorBrush((Color)ProxyList.BackgroundColor);
this.BorderThickness = new Thickness(2);
Expand Down Expand Up @@ -470,10 +460,10 @@ public ProxyMenu(string proxyName,int IndexID, ProxyCard card)
// 定义样式的模板
ControlTemplate template = new ControlTemplate(typeof(ContextMenu));
FrameworkElementFactory borderFactory = new FrameworkElementFactory(typeof(Border));
borderFactory.SetValue(Border.BackgroundProperty, new SolidColorBrush(MainWindow.DarkThemeEnabled ? Color.FromRgb(53, 53, 53) : Color.FromRgb(210, 210, 210)));
borderFactory.SetValue(Border.BackgroundProperty, new SolidColorBrush(Global.isDarkThemeEnabled ? Color.FromRgb(53, 53, 53) : Color.FromRgb(210, 210, 210)));
borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(1));
borderFactory.SetValue(Border.CornerRadiusProperty, new CornerRadius(5));
this.Foreground = new SolidColorBrush(MainWindow.DarkThemeEnabled ? Colors.White : Colors.Black);
this.Foreground = new SolidColorBrush(Global.isDarkThemeEnabled ? Colors.White : Colors.Black);
FrameworkElementFactory stackPanelFactory = new FrameworkElementFactory(typeof(StackPanel));
stackPanelFactory.SetValue(StackPanel.IsItemsHostProperty, true);

Expand All @@ -484,22 +474,6 @@ public ProxyMenu(string proxyName,int IndexID, ProxyCard card)

// 应用样式
this.Style = roundedContextMenuStyle;
//this.Style = ProxyList.DefaultStyleKeyProperty;
//this.OverridesDefaultStyle = true;
/*
<ContextMenu Name="ListMenu">
<ui:MenuItem Header="刷新" Click="Refresh_Click"/>
<Separator/>
<ui:MenuItem Header="新建隧道" Click="CreateNewProxy_Click"/>
<ui:MenuItem Header="删除隧道" Click="DeleteProxy_Click"/>
<Separator/>
<ui:MenuItem Header="启动隧道" Click="StartProxy_Click"/>
<ui:MenuItem Header="停止隧道" Click="StopProxy_Click"/>
</ContextMenu>
*/
//this.Background = new SolidColorBrush(Color.FromRgb(45,45,45));

MenuItem Refresh = new MenuItem()
{
Header = "刷新",
Expand Down Expand Up @@ -653,10 +627,10 @@ public class Proxy
public string RemotePort { get; set; }

Check warning on line 627 in LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows

Non-nullable property 'RemotePort' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[JsonProperty("use_compression")]
public int UseCompression { get; set; }
public string UseCompression { get; set; }

Check warning on line 630 in LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows

Non-nullable property 'UseCompression' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[JsonProperty("use_encryption")]
public int UseEncryption { get; set; }
public string UseEncryption { get; set; }

Check warning on line 633 in LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows

Non-nullable property 'UseEncryption' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[JsonProperty("domain")]
public string Domain { get; set; }

Check warning on line 635 in LoCyanFrpDesktop/Dashboard/ProxyList.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows

Non-nullable property 'Domain' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public int Node { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions LoCyanFrpDesktop/Dashboard/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@
Content="选择文件"
Icon="OpenFolder24"/>
</Grid>
<DockPanel HorizontalAlignment="Left" Width="100" >
<TextBlock DockPanel.Dock="Top" Text="主题设置" FontSize="12"/>
<ComboBox Name="AppliedTheme" DockPanel.Dock="Bottom" SelectionChanged="AppliedTheme_SelectionChanged">
<ComboBoxItem Content="跟随系统"></ComboBoxItem>
<ComboBoxItem Content="深色"/>
<ComboBoxItem Content="浅色"/>
</ComboBox>
</DockPanel>
<ui:Button Name="SignOut" Margin="0,10" Icon="ArrowExit20" Content="退出登录" Click="SignOut_Click"/>

</StackPanel>

</Grid>
Expand Down
36 changes: 35 additions & 1 deletion LoCyanFrpDesktop/Dashboard/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;
using TextBox = System.Windows.Controls.TextBox;

Expand All @@ -25,15 +26,18 @@ namespace LoCyanFrpDesktop.Dashboard
/// </summary>
public partial class Settings : UiPage
{
private static int i = 0;
public Settings()
{
{

InitializeComponent();
Access.Settings = this;
_Version.Text = $"版本: Ver {Global.Version}-{Global.Branch}{Global.Revision}";
_BuildInfo.Text = Global.BuildInfo.ToString();
_Developer.Text = $"开发者: {Global.Developer}";
_Copyright.Text = Global.Copyright;
FrpcPath.Text = Global.Config.FrpcPath;
AppliedTheme.SelectedIndex = Global.Config.AppliedTheme;
}
public void Select_Click(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -67,5 +71,35 @@ private void SignOut_Click(object sender, RoutedEventArgs e)
Access.MainWindow.Width = double.NaN;
Access.MainWindow.Show();
}


private void AppliedTheme_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

if(i > 0)
{
Global.Config.AppliedTheme = AppliedTheme.SelectedIndex;
switch (AppliedTheme.SelectedIndex)
{
case 0:
MainWindow.IsDarkThemeEnabled();

break;
case 1:
Global.isDarkThemeEnabled = true;
Theme.Apply(ThemeType.Dark);
break;
case 2:
Global.isDarkThemeEnabled = false;
Theme.Apply(ThemeType.Light);
break;
default:
throw new IndexOutOfRangeException();

}
Access.DashBoard.ChangeColor();
}
i++;
}
}
}
1 change: 1 addition & 0 deletions LoCyanFrpDesktop/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal static class Global
public const string Developer = "Shiroiame-Kusu & Daiyangcheng";
public const string Copyright = "Copyright © 2021 - 2024 杭州樱芸网络科技有限公司 All Rights Reserved";
public static Config Config = new();
public static bool isDarkThemeEnabled;
public static SecureString Password = new();
public static List<string> Tips = new() {
"Tips:他们说下载的时候把电脑抱起来摇匀, 下载速度会更快哦",
Expand Down
Loading

0 comments on commit 1f3d9b9

Please sign in to comment.