Improve Settings management

This commit is contained in:
Jack251970 2025-01-12 18:44:52 +08:00
parent 2716c40c0b
commit 32cac76c82
3 changed files with 23 additions and 14 deletions

View file

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Text.Json.Serialization;
using System.Windows;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedModels;
using Flow.Launcher.ViewModel;
@ -13,6 +13,18 @@ namespace Flow.Launcher.Infrastructure.UserSettings
{
public class Settings : BaseModel, IHotkeySettings
{
private FlowLauncherJsonStorage<Settings> _storage;
public void Initialize(FlowLauncherJsonStorage<Settings> storage)
{
_storage = storage;
}
public void Save()
{
_storage.Save();
}
private string language = "en";
private string _theme = Constant.DefaultTheme;
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";

View file

@ -14,6 +14,7 @@ using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Image;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.ViewModel;
@ -52,6 +53,10 @@ namespace Flow.Launcher
{
await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
{
var storage = new FlowLauncherJsonStorage<Settings>();
_settings = storage.Load();
_settings.Initialize(storage);
_portable.PreStartCleanUpAfterPortabilityUpdate();
Log.Info(
@ -62,8 +67,7 @@ namespace Flow.Launcher
var imageLoadertask = ImageLoader.InitializeAsync();
_settingsVM = new SettingWindowViewModel(_updater, _portable);
_settings = _settingsVM.Settings;
_settingsVM = new SettingWindowViewModel(_settings, _updater, _portable);
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);

View file

@ -1,6 +1,5 @@
using Flow.Launcher.Core;
using Flow.Launcher.Core.Configuration;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
@ -8,21 +7,17 @@ namespace Flow.Launcher.ViewModel;
public class SettingWindowViewModel : BaseModel
{
private readonly FlowLauncherJsonStorage<Settings> _storage;
public Updater Updater { get; }
public IPortable Portable { get; }
public Settings Settings { get; }
public SettingWindowViewModel(Updater updater, IPortable portable)
public SettingWindowViewModel(Settings settings, Updater updater, IPortable portable)
{
_storage = new FlowLauncherJsonStorage<Settings>();
Settings = settings;
Updater = updater;
Portable = portable;
Settings = _storage.Load();
}
public async void UpdateApp()
@ -30,14 +25,12 @@ public class SettingWindowViewModel : BaseModel
await Updater.UpdateAppAsync(App.API, false);
}
/// <summary>
/// Save Flow settings. Plugins settings are not included.
/// </summary>
public void Save()
{
_storage.Save();
Settings.Save();
}
public double SettingWindowWidth