Skip to content

Commit 32cac76

Browse files
committed
Improve Settings management
1 parent 2716c40 commit 32cac76

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Collections.ObjectModel;
43
using System.Drawing;
54
using System.Text.Json.Serialization;
65
using System.Windows;
76
using Flow.Launcher.Infrastructure.Hotkey;
7+
using Flow.Launcher.Infrastructure.Storage;
88
using Flow.Launcher.Plugin;
99
using Flow.Launcher.Plugin.SharedModels;
1010
using Flow.Launcher.ViewModel;
@@ -13,6 +13,18 @@ namespace Flow.Launcher.Infrastructure.UserSettings
1313
{
1414
public class Settings : BaseModel, IHotkeySettings
1515
{
16+
private FlowLauncherJsonStorage<Settings> _storage;
17+
18+
public void Initialize(FlowLauncherJsonStorage<Settings> storage)
19+
{
20+
_storage = storage;
21+
}
22+
23+
public void Save()
24+
{
25+
_storage.Save();
26+
}
27+
1628
private string language = "en";
1729
private string _theme = Constant.DefaultTheme;
1830
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";

Flow.Launcher/App.xaml.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Flow.Launcher.Infrastructure.Http;
1515
using Flow.Launcher.Infrastructure.Image;
1616
using Flow.Launcher.Infrastructure.Logger;
17+
using Flow.Launcher.Infrastructure.Storage;
1718
using Flow.Launcher.Infrastructure.UserSettings;
1819
using Flow.Launcher.Plugin;
1920
using Flow.Launcher.ViewModel;
@@ -52,6 +53,10 @@ private async void OnStartupAsync(object sender, StartupEventArgs e)
5253
{
5354
await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
5455
{
56+
var storage = new FlowLauncherJsonStorage<Settings>();
57+
_settings = storage.Load();
58+
_settings.Initialize(storage);
59+
5560
_portable.PreStartCleanUpAfterPortabilityUpdate();
5661

5762
Log.Info(
@@ -62,8 +67,7 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
6267

6368
var imageLoadertask = ImageLoader.InitializeAsync();
6469

65-
_settingsVM = new SettingWindowViewModel(_updater, _portable);
66-
_settings = _settingsVM.Settings;
70+
_settingsVM = new SettingWindowViewModel(_settings, _updater, _portable);
6771
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
6872

6973
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
11
using Flow.Launcher.Core;
22
using Flow.Launcher.Core.Configuration;
3-
using Flow.Launcher.Infrastructure.Storage;
43
using Flow.Launcher.Infrastructure.UserSettings;
54
using Flow.Launcher.Plugin;
65

76
namespace Flow.Launcher.ViewModel;
87

98
public class SettingWindowViewModel : BaseModel
109
{
11-
private readonly FlowLauncherJsonStorage<Settings> _storage;
12-
1310
public Updater Updater { get; }
1411

1512
public IPortable Portable { get; }
1613

1714
public Settings Settings { get; }
1815

19-
public SettingWindowViewModel(Updater updater, IPortable portable)
16+
public SettingWindowViewModel(Settings settings, Updater updater, IPortable portable)
2017
{
21-
_storage = new FlowLauncherJsonStorage<Settings>();
22-
18+
Settings = settings;
2319
Updater = updater;
2420
Portable = portable;
25-
Settings = _storage.Load();
2621
}
2722

2823
public async void UpdateApp()
2924
{
3025
await Updater.UpdateAppAsync(App.API, false);
3126
}
3227

33-
34-
3528
/// <summary>
3629
/// Save Flow settings. Plugins settings are not included.
3730
/// </summary>
3831
public void Save()
3932
{
40-
_storage.Save();
33+
Settings.Save();
4134
}
4235

4336
public double SettingWindowWidth

0 commit comments

Comments
 (0)