Skip to content

Commit 980b792

Browse files
committed
Wrap operation in one class
1 parent 950a7f5 commit 980b792

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

Flow.Launcher/Storage/TopMostRecord.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,44 @@
11
using System.Collections.Concurrent;
22
using System.Collections.Generic;
33
using System.Text.Json.Serialization;
4+
using Flow.Launcher.Infrastructure.Storage;
45
using Flow.Launcher.Plugin;
56

67
namespace Flow.Launcher.Storage
78
{
9+
public class FlowLauncherJsonStorageTopMostRecord : ISavable
10+
{
11+
private readonly FlowLauncherJsonStorage<TopMostRecord> _topMostRecordStorage;
12+
13+
private readonly TopMostRecord _topMostRecord;
14+
15+
public FlowLauncherJsonStorageTopMostRecord()
16+
{
17+
_topMostRecordStorage = new FlowLauncherJsonStorage<TopMostRecord>();
18+
_topMostRecord = _topMostRecordStorage.Load();
19+
}
20+
21+
public void Save()
22+
{
23+
_topMostRecordStorage.Save();
24+
}
25+
26+
public bool IsTopMost(Result result)
27+
{
28+
return _topMostRecord.IsTopMost(result);
29+
}
30+
31+
public void Remove(Result result)
32+
{
33+
_topMostRecord.Remove(result);
34+
}
35+
36+
public void AddOrUpdate(Result result)
37+
{
38+
_topMostRecord.AddOrUpdate(result);
39+
}
40+
}
41+
842
public class TopMostRecord
943
{
1044
[JsonInclude]

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
3737

3838
private readonly FlowLauncherJsonStorage<History> _historyItemsStorage;
3939
private readonly FlowLauncherJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
40-
private readonly FlowLauncherJsonStorage<TopMostRecord> _topMostRecordStorage;
40+
private readonly FlowLauncherJsonStorageTopMostRecord _topMostRecord;
4141
private readonly History _history;
4242
private int lastHistoryIndex = 1;
4343
private readonly UserSelectedRecord _userSelectedRecord;
44-
private readonly TopMostRecord _topMostRecord;
4544

4645
private CancellationTokenSource _updateSource;
4746
private CancellationToken _updateToken;
@@ -134,10 +133,9 @@ public MainViewModel()
134133

135134
_historyItemsStorage = new FlowLauncherJsonStorage<History>();
136135
_userSelectedRecordStorage = new FlowLauncherJsonStorage<UserSelectedRecord>();
137-
_topMostRecordStorage = new FlowLauncherJsonStorage<TopMostRecord>();
136+
_topMostRecord = new FlowLauncherJsonStorageTopMostRecord();
138137
_history = _historyItemsStorage.Load();
139138
_userSelectedRecord = _userSelectedRecordStorage.Load();
140-
_topMostRecord = _topMostRecordStorage.Load();
141139

142140
ContextMenu = new ResultsViewModel(Settings)
143141
{
@@ -1612,7 +1610,7 @@ public void Save()
16121610
{
16131611
_historyItemsStorage.Save();
16141612
_userSelectedRecordStorage.Save();
1615-
_topMostRecordStorage.Save();
1613+
_topMostRecord.Save();
16161614
}
16171615

16181616
/// <summary>

0 commit comments

Comments
 (0)