| | |
| | | using System.Text.Json.Serialization; |
| | | using Moli.Desktop.Diagnostics; |
| | | using Moli.Desktop.Host; |
| | | using Moli.Desktop.Hotkeys; |
| | | |
| | | namespace Moli.Desktop.Configuration; |
| | | |
| | |
| | | public Task SaveLayoutAsync(LayoutDocument document, CancellationToken cancellationToken = default) |
| | | => SaveDocumentAsync("layout.json", document, cancellationToken); |
| | | |
| | | public async Task<HotkeysDocument> LoadHotkeysAsync(CancellationToken cancellationToken = default) |
| | | { |
| | | var document = await LoadDocumentAsync("hotkeys.json", HotkeysDocument.CreateDefault, cancellationToken).ConfigureAwait(false); |
| | | if (document.Bindings.All(binding => |
| | | !string.Equals(binding.Id, HotkeysDocument.BuiltinPaletteToggleId, StringComparison.OrdinalIgnoreCase))) |
| | | { |
| | | document.Bindings.Insert(0, HotkeysDocument.CreateBuiltinPaletteBinding()); |
| | | } |
| | | |
| | | return document; |
| | | } |
| | | |
| | | public Task SaveHotkeysAsync(HotkeysDocument document, CancellationToken cancellationToken = default) |
| | | => SaveDocumentAsync("hotkeys.json", document, cancellationToken); |
| | | |
| | | public async Task<ConfigurationSnapshot> LoadAllAsync(CancellationToken cancellationToken = default) |
| | | { |
| | | return new ConfigurationSnapshot |
| | | { |
| | | AppSettings = await LoadAppSettingsAsync(cancellationToken).ConfigureAwait(false), |
| | | Plugins = await LoadPluginRegistryAsync(cancellationToken).ConfigureAwait(false), |
| | | Layout = await LoadLayoutAsync(cancellationToken).ConfigureAwait(false) |
| | | Layout = await LoadLayoutAsync(cancellationToken).ConfigureAwait(false), |
| | | Hotkeys = await LoadHotkeysAsync(cancellationToken).ConfigureAwait(false) |
| | | }; |
| | | } |
| | | |
| | |
| | | await SaveAppSettingsAsync(snapshot.AppSettings, cancellationToken).ConfigureAwait(false); |
| | | await SavePluginRegistryAsync(snapshot.Plugins, cancellationToken).ConfigureAwait(false); |
| | | await SaveLayoutAsync(snapshot.Layout, cancellationToken).ConfigureAwait(false); |
| | | await SaveHotkeysAsync(snapshot.Hotkeys, cancellationToken).ConfigureAwait(false); |
| | | } |
| | | |
| | | private async Task<T> LoadDocumentAsync<T>(string fileName, Func<T> createDefault, CancellationToken cancellationToken) |