blob: 7b646d161e032ab4006b398592f9ba3374544c01 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
@page "/Dev/Options"
@using ArcaneLibs.Extensions
@using System.Text
@using System.Text.Json
@using Microsoft.JSInterop
@inject NavigationManager NavigationManager
@inject IJSRuntime JSRuntime
@inject TieredStorageService TieredStorage
<PageTitle>Developer options</PageTitle>
<h3>Rory&::MatrixUtils - Developer options</h3>
<hr/>
<p>
<span>Import local storage: </span>
<InputFile OnChange="ImportLocalStorage"></InputFile>
</p>
<p>
<span>Export local storage: </span>
<button @onclick="@ExportLocalStorage">Export</button>
</p>
@if (userSettings is not null) {
<InputCheckbox @bind-Value="@userSettings.DeveloperSettings.EnableLogViewers" @oninput="@LogStuff"></InputCheckbox>
<label> Enable log views</label>
<br/>
<InputCheckbox @bind-Value="@userSettings.DeveloperSettings.EnableConsoleLogging" @oninput="@LogStuff"></InputCheckbox>
<label> Enable console logging</label>
<br/>
<InputCheckbox @bind-Value="@userSettings.DeveloperSettings.EnablePortableDevtools" @oninput="@LogStuff"></InputCheckbox>
<label> Enable portable devtools</label>
<br/>
}
<br/>
@code {
private RMUStorageWrapper.Settings? userSettings { get; set; }
protected override async Task OnInitializedAsync() {
// userSettings = await TieredStorage.DataStorageProvider.LoadObjectAsync<RMUStorageWrapper.Settings>("rmu.settings");
await base.OnInitializedAsync();
}
private async Task LogStuff() {
await Task.Delay(100);
Console.WriteLine($"Settings: {userSettings.ToJson()}");
await TieredStorage.DataStorageProvider.SaveObjectAsync("rmu.settings", userSettings);
}
private async Task ExportLocalStorage() {
var keys = await TieredStorage.DataStorageProvider.GetAllKeysAsync();
var data = new Dictionary<string, object>();
foreach (var key in keys) {
data.Add(key, await TieredStorage.DataStorageProvider.LoadObjectAsync<object>(key));
}
var dataUri = "data:application/json;base64,";
dataUri += Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(data)));
await JSRuntime.InvokeVoidAsync("window.open", dataUri, "_blank");
}
private async Task ImportLocalStorage(InputFileChangeEventArgs obj) {
if (obj.FileCount != 1) return;
var data = await JsonSerializer.DeserializeAsync<Dictionary<string, object>>(obj.File.OpenReadStream());
foreach (var (key, value) in data) {
await TieredStorage.DataStorageProvider.SaveObjectAsync(key, value);
}
NavigationManager.NavigateTo(NavigationManager.Uri, true, true);
}
}
|