diff --git a/Flow.Launcher/Storage/TopMostRecord.cs b/Flow.Launcher/Storage/TopMostRecord.cs index 7f35904a5..63f0a2fce 100644 --- a/Flow.Launcher/Storage/TopMostRecord.cs +++ b/Flow.Launcher/Storage/TopMostRecord.cs @@ -1,10 +1,44 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Text.Json.Serialization; +using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin; namespace Flow.Launcher.Storage { + public class FlowLauncherJsonStorageTopMostRecord : ISavable + { + private readonly FlowLauncherJsonStorage _topMostRecordStorage; + + private readonly TopMostRecord _topMostRecord; + + public FlowLauncherJsonStorageTopMostRecord() + { + _topMostRecordStorage = new FlowLauncherJsonStorage(); + _topMostRecord = _topMostRecordStorage.Load(); + } + + public void Save() + { + _topMostRecordStorage.Save(); + } + + public bool IsTopMost(Result result) + { + return _topMostRecord.IsTopMost(result); + } + + public void Remove(Result result) + { + _topMostRecord.Remove(result); + } + + public void AddOrUpdate(Result result) + { + _topMostRecord.AddOrUpdate(result); + } + } + public class TopMostRecord { [JsonInclude] diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 00675149b..54ad6c288 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -37,11 +37,10 @@ namespace Flow.Launcher.ViewModel private readonly FlowLauncherJsonStorage _historyItemsStorage; private readonly FlowLauncherJsonStorage _userSelectedRecordStorage; - private readonly FlowLauncherJsonStorage _topMostRecordStorage; + private readonly FlowLauncherJsonStorageTopMostRecord _topMostRecord; private readonly History _history; private int lastHistoryIndex = 1; private readonly UserSelectedRecord _userSelectedRecord; - private readonly TopMostRecord _topMostRecord; private CancellationTokenSource _updateSource; private CancellationToken _updateToken; @@ -134,10 +133,9 @@ namespace Flow.Launcher.ViewModel _historyItemsStorage = new FlowLauncherJsonStorage(); _userSelectedRecordStorage = new FlowLauncherJsonStorage(); - _topMostRecordStorage = new FlowLauncherJsonStorage(); + _topMostRecord = new FlowLauncherJsonStorageTopMostRecord(); _history = _historyItemsStorage.Load(); _userSelectedRecord = _userSelectedRecordStorage.Load(); - _topMostRecord = _topMostRecordStorage.Load(); ContextMenu = new ResultsViewModel(Settings) { @@ -1612,7 +1610,7 @@ namespace Flow.Launcher.ViewModel { _historyItemsStorage.Save(); _userSelectedRecordStorage.Save(); - _topMostRecordStorage.Save(); + _topMostRecord.Save(); } ///