mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-05-01 02:02:22 +00:00
Fix settings getting corrupted
This commit is contained in:
@@ -20,6 +20,8 @@ namespace DiscordChatExporter.Gui;
|
|||||||
public class App : Application, IDisposable
|
public class App : Application, IDisposable
|
||||||
{
|
{
|
||||||
private readonly ServiceProvider _services;
|
private readonly ServiceProvider _services;
|
||||||
|
private readonly SettingsService _settingsService;
|
||||||
|
|
||||||
private readonly DisposableCollector _eventRoot = new();
|
private readonly DisposableCollector _eventRoot = new();
|
||||||
|
|
||||||
private bool _isDisposed;
|
private bool _isDisposed;
|
||||||
@@ -49,25 +51,24 @@ public class App : Application, IDisposable
|
|||||||
services.AddTransient<SettingsViewModel>();
|
services.AddTransient<SettingsViewModel>();
|
||||||
|
|
||||||
_services = services.BuildServiceProvider(true);
|
_services = services.BuildServiceProvider(true);
|
||||||
|
_settingsService = _services.GetRequiredService<SettingsService>();
|
||||||
|
|
||||||
// Re-initialize the theme when the user changes it
|
// Re-initialize the theme when the user changes it
|
||||||
_eventRoot.Add(
|
_eventRoot.Add(
|
||||||
_services
|
_settingsService.WatchProperty(
|
||||||
.GetRequiredService<SettingsService>()
|
o => o.Theme,
|
||||||
.WatchProperty(
|
v =>
|
||||||
o => o.Theme,
|
{
|
||||||
v =>
|
RequestedThemeVariant = v switch
|
||||||
{
|
{
|
||||||
RequestedThemeVariant = v switch
|
ThemeVariant.Light => Avalonia.Styling.ThemeVariant.Light,
|
||||||
{
|
ThemeVariant.Dark => Avalonia.Styling.ThemeVariant.Dark,
|
||||||
ThemeVariant.Light => Avalonia.Styling.ThemeVariant.Light,
|
_ => Avalonia.Styling.ThemeVariant.Default,
|
||||||
ThemeVariant.Dark => Avalonia.Styling.ThemeVariant.Dark,
|
};
|
||||||
_ => Avalonia.Styling.ThemeVariant.Default,
|
|
||||||
};
|
|
||||||
|
|
||||||
InitializeTheme();
|
InitializeTheme();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +96,13 @@ public class App : Application, IDisposable
|
|||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
{
|
{
|
||||||
|
// Initialize the default theme, before a custom one (if any) is applied by loading settings
|
||||||
|
InitializeTheme();
|
||||||
|
|
||||||
|
// Load settings
|
||||||
|
_settingsService.Load();
|
||||||
|
|
||||||
|
// Initialize and configure the main window
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
{
|
{
|
||||||
var viewManager = _services.GetRequiredService<ViewManager>();
|
var viewManager = _services.GetRequiredService<ViewManager>();
|
||||||
@@ -110,12 +118,6 @@ public class App : Application, IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
|
|
||||||
// Set up custom theme colors
|
|
||||||
InitializeTheme();
|
|
||||||
|
|
||||||
// Load settings
|
|
||||||
_services.GetRequiredService<SettingsService>().Load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Application_OnActualThemeVariantChanged(object? sender, EventArgs args) =>
|
private void Application_OnActualThemeVariantChanged(object? sender, EventArgs args) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user