1.1.3 -> 1.1.4 第45次更新

This commit is contained in:
Space Time 2024-12-10 21:48:50 +08:00
parent 34165391b4
commit 6ebc22c8ea
8 changed files with 66 additions and 64 deletions

View File

@ -20,9 +20,9 @@ public partial class App : Application
#region Primary Color #region Primary Color
PaletteHelper paletteHelper = new(); PaletteHelper paletteHelper = new();
Theme newTheme = paletteHelper.GetTheme(); Theme newTheme = paletteHelper.GetTheme();
System.Drawing.Color newColor = Settings.Default.PrimaryColor; System.Drawing.Color newPrimaryColor = Settings.Default.PrimaryColor;
newTheme.SetPrimaryColor(Color.FromRgb(newColor.R, newColor.G, newColor.B)); newTheme.SetPrimaryColor(Color.FromRgb(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B));
paletteHelper.SetTheme(newTheme); paletteHelper.SetTheme(newTheme);
#endregion Primary Color #endregion Primary Color
@ -30,16 +30,17 @@ public partial class App : Application
if (Environment.OSVersion.Version.Build < 22000) if (Environment.OSVersion.Version.Build < 22000)
{ {
Style newWindowStyle = new(typeof(Window), Current.Resources["CommonWindow"] as Style); Style newWindowStyle = new(typeof(Window), Current.Resources["CommonWindow"] as Style);
newWindowStyle.Setters.Add(new Setter(Window.BackgroundProperty, new DynamicResourceExtension("MaterialDesignBackground"))); newWindowStyle.Setters.Add(new Setter(Window.BackgroundProperty, new DynamicResourceExtension("MaterialDesignBackground")));
Current.Resources["CommonWindow"] = newWindowStyle; Current.Resources["CommonWindow"] = newWindowStyle;
} }
#endregion Background Color #endregion Background Color
#region Foreground Color #region Foreground Color
Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B);
Style newButtonStyle = new(typeof(Button), Current.Resources[typeof(Button)] as Style); Style newButtonStyle = new(typeof(Button), Current.Resources[typeof(Button)] as Style);
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, foregroundColor.HasValue ? new SolidColorBrush(foregroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground"))); Color? newForegroundColor = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
Current.Resources[typeof(Button)] = newButtonStyle; Current.Resources[typeof(Button)] = newButtonStyle;
#endregion Foreground Color #endregion Foreground Color

View File

@ -14,8 +14,6 @@ internal partial class MainPres : GlobalPres
internal MainPres(string[] args) internal MainPres(string[] args)
{ {
int browserPathIndex = Array.FindIndex(args, arg => arg.Equals("-b", StringComparison.OrdinalIgnoreCase)) + 1; int browserPathIndex = Array.FindIndex(args, arg => arg.Equals("-b", StringComparison.OrdinalIgnoreCase)) + 1;
int upstreamUrlIndex = Array.FindIndex(args, arg => arg.Equals("-u", StringComparison.OrdinalIgnoreCase)) + 1;
int extraArgsIndex = Array.FindIndex(args, arg => arg.Equals("-e", StringComparison.OrdinalIgnoreCase)) + 1;
BrowserPath = browserPathIndex != 0 && browserPathIndex != args.Length ? args[browserPathIndex] : BrowserPath = browserPathIndex != 0 && browserPathIndex != args.Length ? args[browserPathIndex] :
!string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath : !string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath :
@ -24,10 +22,14 @@ internal partial class MainPres : GlobalPres
Registry.LocalMachine.OpenSubKey(MainConst.BraveBrowserRegistryPath)?.GetValue(string.Empty, null) ?? Registry.LocalMachine.OpenSubKey(MainConst.BraveBrowserRegistryPath)?.GetValue(string.Empty, null) ??
string.Empty).ToString()!; string.Empty).ToString()!;
int upstreamUrlIndex = Array.FindIndex(args, arg => arg.Equals("-u", StringComparison.OrdinalIgnoreCase)) + 1;
UpstreamUrl = upstreamUrlIndex == 0 || upstreamUrlIndex == args.Length ? UpstreamUrl = upstreamUrlIndex == 0 || upstreamUrlIndex == args.Length ?
!string.IsNullOrWhiteSpace(Settings.Default.UpstreamUrl) ? Settings.Default.UpstreamUrl : MainConst.DefaultUpstreamUrl : !string.IsNullOrWhiteSpace(Settings.Default.UpstreamUrl) ? Settings.Default.UpstreamUrl : MainConst.DefaultUpstreamUrl :
args[upstreamUrlIndex]; args[upstreamUrlIndex];
int extraArgsIndex = Array.FindIndex(args, arg => arg.Equals("-e", StringComparison.OrdinalIgnoreCase)) + 1;
ExtraArgs = extraArgsIndex == 0 || extraArgsIndex == args.Length ? ExtraArgs = extraArgsIndex == 0 || extraArgsIndex == args.Length ?
!string.IsNullOrWhiteSpace(Settings.Default.ExtraArgs) ? Settings.Default.ExtraArgs : string.Empty : !string.IsNullOrWhiteSpace(Settings.Default.ExtraArgs) ? Settings.Default.ExtraArgs : string.Empty :
args[extraArgsIndex]; args[extraArgsIndex];

View File

@ -49,13 +49,14 @@ internal partial class SettingsPres : GlobalPres
private static bool? isLightWeight = null; private static bool? isLightWeight = null;
partial void OnIsLightWeightChanged(bool? value) partial void OnIsLightWeightChanged(bool? value)
{ {
Style newWindowStyle = new(typeof(Window), Application.Current.Resources["CommonWindow"] as Style);
FontWeight newWeight = value.HasValue ? value.Value ? FontWeights.Light : FontWeights.Bold : FontWeights.Regular; FontWeight newWeight = value.HasValue ? value.Value ? FontWeights.Light : FontWeights.Bold : FontWeights.Regular;
Style newWindowStyle = new(typeof(Window), Application.Current.Resources["CommonWindow"] as Style);
newWindowStyle.Setters.Add(new Setter(Window.FontWeightProperty, newWeight)); newWindowStyle.Setters.Add(new Setter(Window.FontWeightProperty, newWeight));
Application.Current.Resources["CommonWindow"] = newWindowStyle; Application.Current.Resources["CommonWindow"] = newWindowStyle;
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
newButtonStyle.Setters.Add(new Setter(Button.FontWeightProperty, newWeight)); newButtonStyle.Setters.Add(new Setter(Button.FontWeightProperty, newWeight));
Application.Current.Resources[typeof(Button)] = newButtonStyle; Application.Current.Resources[typeof(Button)] = newButtonStyle;

View File

@ -6,7 +6,7 @@ namespace Sheas_Cealer.Proces;
internal class BrowserProc : Proc internal class BrowserProc : Proc
{ {
private static bool ShutDownAppOnProcessExit; private readonly bool ShutDownAppOnProcessExit;
internal BrowserProc(string browserPath, bool shutDownAppOnProcessExit) : base(browserPath) => ShutDownAppOnProcessExit = shutDownAppOnProcessExit; internal BrowserProc(string browserPath, bool shutDownAppOnProcessExit) : base(browserPath) => ShutDownAppOnProcessExit = shutDownAppOnProcessExit;

View File

@ -5,7 +5,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:consts="clr-namespace:Sheas_Cealer.Consts" xmlns:consts="clr-namespace:Sheas_Cealer.Consts"
xmlns:convs="clr-namespace:Sheas_Cealer.Convs" xmlns:convs="clr-namespace:Sheas_Cealer.Convs"
xmlns:preses="clr-namespace:Sheas_Cealer.Preses"
mc:Ignorable="d" mc:Ignorable="d"
d:DataContext="{d:DesignInstance preses:AboutPres}"
Style="{DynamicResource CommonWindow}" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" SizeToContent="Height" Width="500" Style="{DynamicResource CommonWindow}" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" SizeToContent="Height" Width="500"
KeyDown="AboutWin_KeyDown"> KeyDown="AboutWin_KeyDown">
<Grid Margin="5"> <Grid Margin="5">

View File

@ -11,34 +11,33 @@ namespace Sheas_Cealer.Wins;
public partial class AboutWin : Window public partial class AboutWin : Window
{ {
private static AboutPres? AboutPres; private readonly AboutPres AboutPres;
internal AboutWin() internal AboutWin()
{ {
InitializeComponent(); InitializeComponent();
AboutPres = new(); DataContext = AboutPres = new();
} }
protected override void OnSourceInitialized(EventArgs e) protected override void OnSourceInitialized(EventArgs e)
{ {
IconRemover.RemoveIcon(this); IconRemover.RemoveIcon(this);
BorderThemeSetter.SetBorderTheme(this, AboutPres!.IsLightTheme); BorderThemeSetter.SetBorderTheme(this, AboutPres.IsLightTheme);
} }
private void AboutButton_Click(object sender, RoutedEventArgs e) private void AboutButton_Click(object sender, RoutedEventArgs e)
{ {
Button? senderButton = sender as Button; Button senderButton = (Button)sender;
if (senderButton == VersionButton) if (senderButton == VersionButton)
MessageBox.Show($"{AboutConst._ReleasePagePasswordLabel} 3wnj"); MessageBox.Show($"{AboutConst._ReleasePagePasswordLabel} 3wnj");
ProcessStartInfo processStartInfo = new(senderButton == EmailButton ? "mailto:" : string.Empty + senderButton!.ToolTip) { UseShellExecute = true }; ProcessStartInfo processStartInfo = new(senderButton == EmailButton ? "mailto:" : string.Empty + senderButton.ToolTip) { UseShellExecute = true };
try { Process.Start(processStartInfo); } try { Process.Start(processStartInfo); }
catch (UnauthorizedAccessException) catch (UnauthorizedAccessException)
{ {
processStartInfo.Verb = "RunAs"; processStartInfo.Verb = "RunAs";
Process.Start(processStartInfo); Process.Start(processStartInfo);
} }
} }

View File

@ -33,27 +33,27 @@ namespace Sheas_Cealer.Wins;
public partial class MainWin : Window public partial class MainWin : Window
{ {
private static MainPres? MainPres; private readonly MainPres MainPres;
private static readonly HttpClient MainClient = new(new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }); private readonly HttpClient MainClient = new(new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator });
private static DispatcherTimer? HoldButtonTimer; private DispatcherTimer? HoldButtonTimer;
private static readonly DispatcherTimer ProxyTimer = new() { Interval = TimeSpan.FromSeconds(0.1) }; private readonly DispatcherTimer ProxyTimer = new() { Interval = TimeSpan.FromSeconds(0.1) };
private static readonly FileSystemWatcher CealHostWatcher = new(Path.GetDirectoryName(MainConst.CealHostPath)!, Path.GetFileName(MainConst.CealHostPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite }; private readonly FileSystemWatcher CealHostWatcher = new(Path.GetDirectoryName(MainConst.CealHostPath)!, Path.GetFileName(MainConst.CealHostPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
private static readonly FileSystemWatcher NginxConfWatcher = new(Path.GetDirectoryName(MainConst.NginxConfPath)!, Path.GetFileName(MainConst.NginxConfPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite }; private readonly FileSystemWatcher NginxConfWatcher = new(Path.GetDirectoryName(MainConst.NginxConfPath)!, Path.GetFileName(MainConst.NginxConfPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
private static readonly FileSystemWatcher MihomoConfWatcher = new(Path.GetDirectoryName(MainConst.MihomoConfPath)!, Path.GetFileName(MainConst.MihomoConfPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite }; private readonly FileSystemWatcher MihomoConfWatcher = new(Path.GetDirectoryName(MainConst.MihomoConfPath)!, Path.GetFileName(MainConst.MihomoConfPath)) { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
private static readonly SortedDictionary<string, List<(List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, string? cealHostSni, string cealHostIp)>> CealHostRulesDict = []; private readonly SortedDictionary<string, List<(List<(string cealHostIncludeDomain, string cealHostExcludeDomain)> cealHostDomainPairs, string? cealHostSni, string cealHostIp)>> CealHostRulesDict = [];
private static string CealArgs = string.Empty; private string CealArgs = string.Empty;
private static NginxConfig? NginxConfs; private NginxConfig? NginxConfs;
private static string? ExtraNginxConfs; private string? ExtraNginxConfs;
private static string? MihomoConfs; private string? MihomoConfs;
private static string? ExtraMihomoConfs; private string? ExtraMihomoConfs;
private static int NginxHttpPort = 80; private int NginxHttpPort = 80;
private static int NginxHttpsPort = 443; private int NginxHttpsPort = 443;
private static int MihomoMixedPort = 7880; private int MihomoMixedPort = 7880;
private static int GameClickTime = 0; private int GameClickTime = 0;
private static int GameFlashInterval = 1000; private int GameFlashInterval = 1000;
internal MainWin(string[] args) internal MainWin(string[] args)
{ {
@ -64,12 +64,10 @@ public partial class MainWin : Window
protected override void OnSourceInitialized(EventArgs e) protected override void OnSourceInitialized(EventArgs e)
{ {
IconRemover.RemoveIcon(this); IconRemover.RemoveIcon(this);
BorderThemeSetter.SetBorderTheme(this, MainPres!.IsLightTheme); BorderThemeSetter.SetBorderTheme(this, MainPres.IsLightTheme);
} }
private async void MainWin_Loaded(object sender, RoutedEventArgs e) private async void MainWin_Loaded(object sender, RoutedEventArgs e)
{ {
SettingsBox.Focus();
await Task.Run(() => await Task.Run(() =>
{ {
ProxyTimer.Tick += ProxyTimer_Tick; ProxyTimer.Tick += ProxyTimer_Tick;
@ -95,12 +93,12 @@ public partial class MainWin : Window
private void MainWin_Drop(object sender, DragEventArgs e) private void MainWin_Drop(object sender, DragEventArgs e)
{ {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) if (e.Data.GetDataPresent(DataFormats.FileDrop))
MainPres!.BrowserPath = ((string[])e.Data.GetData(DataFormats.FileDrop))[0]; MainPres.BrowserPath = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
} }
private void SettingsBox_TextChanged(object sender, TextChangedEventArgs e) private void SettingsBox_TextChanged(object sender, TextChangedEventArgs e)
{ {
switch (MainPres!.SettingsMode) switch (MainPres.SettingsMode)
{ {
case MainConst.SettingsMode.BrowserPathMode: case MainConst.SettingsMode.BrowserPathMode:
MainPres.BrowserPath = SettingsBox.Text; MainPres.BrowserPath = SettingsBox.Text;
@ -115,7 +113,7 @@ public partial class MainWin : Window
} }
private void SettingsModeButton_Click(object sender, RoutedEventArgs e) private void SettingsModeButton_Click(object sender, RoutedEventArgs e)
{ {
MainPres!.SettingsMode = MainPres.SettingsMode switch MainPres.SettingsMode = MainPres.SettingsMode switch
{ {
MainConst.SettingsMode.BrowserPathMode => MainConst.SettingsMode.UpstreamUrlMode, MainConst.SettingsMode.BrowserPathMode => MainConst.SettingsMode.UpstreamUrlMode,
MainConst.SettingsMode.UpstreamUrlMode => MainConst.SettingsMode.ExtraArgsMode, MainConst.SettingsMode.UpstreamUrlMode => MainConst.SettingsMode.ExtraArgsMode,
@ -127,7 +125,7 @@ public partial class MainWin : Window
{ {
OpenFileDialog browserPathDialog = new() { Filter = $"{MainConst._BrowserPathDialogFilterFileType} (*.exe)|*.exe" }; OpenFileDialog browserPathDialog = new() { Filter = $"{MainConst._BrowserPathDialogFilterFileType} (*.exe)|*.exe" };
switch (MainPres!.SettingsMode) switch (MainPres.SettingsMode)
{ {
case MainConst.SettingsMode.BrowserPathMode when browserPathDialog.ShowDialog().GetValueOrDefault(): case MainConst.SettingsMode.BrowserPathMode when browserPathDialog.ShowDialog().GetValueOrDefault():
SettingsBox.Focus(); SettingsBox.Focus();
@ -161,7 +159,7 @@ public partial class MainWin : Window
(MessageBox.Show(MainConst._KillBrowserProcessPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)) (MessageBox.Show(MainConst._KillBrowserProcessPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes))
return; return;
foreach (Process browserProcess in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainPres!.BrowserPath))) foreach (Process browserProcess in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainPres.BrowserPath)))
{ {
browserProcess.Kill(); browserProcess.Kill();
await browserProcess.WaitForExitAsync(); await browserProcess.WaitForExitAsync();
@ -187,7 +185,7 @@ public partial class MainWin : Window
{ {
HoldButtonTimer?.Stop(); HoldButtonTimer?.Stop();
if (!MainPres!.IsNginxRunning) if (!MainPres.IsNginxRunning)
{ {
if ((CealHostRulesDict.ContainsValue(null!) && MessageBox.Show(MainConst._CealHostErrorPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) || if ((CealHostRulesDict.ContainsValue(null!) && MessageBox.Show(MainConst._CealHostErrorPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) ||
(NginxHttpsPort != 443 && MessageBox.Show(MainConst._NginxHttpsPortOccupiedPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) || (NginxHttpsPort != 443 && MessageBox.Show(MainConst._NginxHttpsPortOccupiedPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) ||
@ -311,7 +309,7 @@ public partial class MainWin : Window
{ {
HoldButtonTimer?.Stop(); HoldButtonTimer?.Stop();
if (!MainPres!.IsMihomoRunning) if (!MainPres.IsMihomoRunning)
{ {
if (string.IsNullOrWhiteSpace(MihomoConfs)) if (string.IsNullOrWhiteSpace(MihomoConfs))
throw new Exception(MainConst._MihomoConfErrorMsg); throw new Exception(MainConst._MihomoConfErrorMsg);
@ -401,7 +399,7 @@ public partial class MainWin : Window
if (!File.Exists(MainConst.UpstreamHostPath)) if (!File.Exists(MainConst.UpstreamHostPath))
File.Create(MainConst.UpstreamHostPath).Dispose(); File.Create(MainConst.UpstreamHostPath).Dispose();
string upstreamUpstreamHostUrl = (MainPres!.UpstreamUrl.StartsWith("http://") || MainPres.UpstreamUrl.StartsWith("https://") ? string.Empty : "https://") + MainPres.UpstreamUrl; string upstreamUpstreamHostUrl = (MainPres.UpstreamUrl.StartsWith("http://") || MainPres.UpstreamUrl.StartsWith("https://") ? string.Empty : "https://") + MainPres.UpstreamUrl;
string upstreamUpstreamHostString = await Http.GetAsync<string>(upstreamUpstreamHostUrl, MainClient); string upstreamUpstreamHostString = await Http.GetAsync<string>(upstreamUpstreamHostUrl, MainClient);
string localUpstreamHostString = File.ReadAllText(MainConst.UpstreamHostPath); string localUpstreamHostString = File.ReadAllText(MainConst.UpstreamHostPath);
@ -446,7 +444,7 @@ public partial class MainWin : Window
return; return;
} }
if (!MainPres!.IsFlashing) if (!MainPres.IsFlashing)
{ {
MessageBox.Show(MainConst._GameStartMsg); MessageBox.Show(MainConst._GameStartMsg);
MainPres.IsFlashing = true; MainPres.IsFlashing = true;
@ -461,20 +459,20 @@ public partial class MainWin : Window
PaletteHelper paletteHelper = new(); PaletteHelper paletteHelper = new();
Theme newTheme = paletteHelper.GetTheme(); Theme newTheme = paletteHelper.GetTheme();
Color newColor = Color.FromRgb((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256)); Color newPrimaryColor = Color.FromRgb((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
bool isLightTheme = random.Next(2) == 0; bool isLightTheme = random.Next(2) == 0;
newTheme.SetPrimaryColor(newColor); newTheme.SetPrimaryColor(newPrimaryColor);
newTheme.SetBaseTheme(isLightTheme ? BaseTheme.Light : BaseTheme.Dark); newTheme.SetBaseTheme(isLightTheme ? BaseTheme.Light : BaseTheme.Dark);
paletteHelper.SetTheme(newTheme); paletteHelper.SetTheme(newTheme);
foreach (Window currentWindow in Application.Current.Windows) foreach (Window currentWindow in Application.Current.Windows)
BorderThemeSetter.SetBorderTheme(currentWindow, isLightTheme); BorderThemeSetter.SetBorderTheme(currentWindow, isLightTheme);
Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B); Color? newForegroundColor = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, foregroundColor.HasValue ? new SolidColorBrush(foregroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground"))); newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
Application.Current.Resources[typeof(Button)] = newButtonStyle; Application.Current.Resources[typeof(Button)] = newButtonStyle;
if (GameFlashInterval > 100) if (GameFlashInterval > 100)
@ -510,7 +508,7 @@ public partial class MainWin : Window
private void ProxyTimer_Tick(object? sender, EventArgs e) private void ProxyTimer_Tick(object? sender, EventArgs e)
{ {
MainPres!.IsNginxExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, Path.GetFileName(MainConst.NginxPath))); MainPres.IsNginxExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, Path.GetFileName(MainConst.NginxPath)));
MainPres.IsNginxRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainConst.NginxPath)).Length != 0; MainPres.IsNginxRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainConst.NginxPath)).Length != 0;
MainPres.IsMihomoExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, Path.GetFileName(MainConst.MihomoPath))); MainPres.IsMihomoExist = File.Exists(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, Path.GetFileName(MainConst.MihomoPath)));
MainPres.IsMihomoRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainConst.MihomoPath)).Length != 0; MainPres.IsMihomoRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainConst.MihomoPath)).Length != 0;
@ -585,7 +583,7 @@ public partial class MainWin : Window
} }
private void NginxConfWatcher_Changed(object sender, FileSystemEventArgs e) private void NginxConfWatcher_Changed(object sender, FileSystemEventArgs e)
{ {
if (MainConst.IsAdmin && MainPres!.IsNginxExist) if (MainConst.IsAdmin && MainPres.IsNginxExist)
{ {
if (!File.Exists(MainConst.NginxConfPath)) if (!File.Exists(MainConst.NginxConfPath))
File.Create(MainConst.NginxConfPath).Dispose(); File.Create(MainConst.NginxConfPath).Dispose();
@ -661,7 +659,7 @@ public partial class MainWin : Window
} }
private void MihomoConfWatcher_Changed(object sender, FileSystemEventArgs e) private void MihomoConfWatcher_Changed(object sender, FileSystemEventArgs e)
{ {
if (MainConst.IsAdmin && MainPres!.IsMihomoExist) if (MainConst.IsAdmin && MainPres.IsMihomoExist)
{ {
try try
{ {

View File

@ -13,7 +13,7 @@ namespace Sheas_Cealer.Wins;
public partial class SettingsWin : Window public partial class SettingsWin : Window
{ {
private static SettingsPres? SettingsPres; private readonly SettingsPres SettingsPres;
internal SettingsWin() internal SettingsWin()
{ {
@ -24,37 +24,36 @@ public partial class SettingsWin : Window
protected override void OnSourceInitialized(EventArgs e) protected override void OnSourceInitialized(EventArgs e)
{ {
IconRemover.RemoveIcon(this); IconRemover.RemoveIcon(this);
BorderThemeSetter.SetBorderTheme(this, SettingsPres!.IsLightTheme); BorderThemeSetter.SetBorderTheme(this, SettingsPres.IsLightTheme);
} }
private void ThemesButton_Click(object sender, RoutedEventArgs e) => SettingsPres!.IsLightTheme = SettingsPres.IsLightTheme.HasValue ? SettingsPres.IsLightTheme.Value ? null : true : false; private void ThemesButton_Click(object sender, RoutedEventArgs e) => SettingsPres.IsLightTheme = SettingsPres.IsLightTheme.HasValue ? SettingsPres.IsLightTheme.Value ? null : true : false;
private void LangsButton_Click(object sender, RoutedEventArgs e) private void LangsButton_Click(object sender, RoutedEventArgs e)
{ {
SettingsPres!.IsEnglishLang = SettingsPres.IsEnglishLang.HasValue ? SettingsPres.IsEnglishLang.Value ? null : true : false; SettingsPres.IsEnglishLang = SettingsPres.IsEnglishLang.HasValue ? SettingsPres.IsEnglishLang.Value ? null : true : false;
MessageBox.Show(SettingsConst._ChangeLangSuccessMsg); MessageBox.Show(SettingsConst._ChangeLangSuccessMsg);
} }
private void ColorsButton_Click(object sender, RoutedEventArgs e) private void ColorsButton_Click(object sender, RoutedEventArgs e)
{ {
Random random = new(); Random random = new();
PaletteHelper paletteHelper = new(); PaletteHelper paletteHelper = new();
Theme newTheme = paletteHelper.GetTheme(); Theme newTheme = paletteHelper.GetTheme();
Color newColor = Color.FromRgb((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256)); Color newPrimaryColor = Color.FromRgb((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
newTheme.SetPrimaryColor(newColor); newTheme.SetPrimaryColor(newPrimaryColor);
paletteHelper.SetTheme(newTheme); paletteHelper.SetTheme(newTheme);
Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B);
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, foregroundColor.HasValue ? new SolidColorBrush(foregroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground"))); Color? newForegroundColor = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
Application.Current.Resources[typeof(Button)] = newButtonStyle; Application.Current.Resources[typeof(Button)] = newButtonStyle;
Settings.Default.PrimaryColor = System.Drawing.Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B); Settings.Default.PrimaryColor = System.Drawing.Color.FromArgb(newPrimaryColor.A, newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
Settings.Default.Save(); Settings.Default.Save();
} }
private void WeightsButton_Click(object sender, RoutedEventArgs e) => SettingsPres!.IsLightWeight = SettingsPres.IsLightWeight.HasValue ? SettingsPres.IsLightWeight.Value ? null : true : false; private void WeightsButton_Click(object sender, RoutedEventArgs e) => SettingsPres.IsLightWeight = SettingsPres.IsLightWeight.HasValue ? SettingsPres.IsLightWeight.Value ? null : true : false;
private void SettingsWin_KeyDown(object sender, KeyEventArgs e) private void SettingsWin_KeyDown(object sender, KeyEventArgs e)
{ {