about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/Dev
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/Dev')
-rw-r--r--MatrixRoomUtils.Web/Pages/Dev/DevOptions.razor55
1 files changed, 48 insertions, 7 deletions
diff --git a/MatrixRoomUtils.Web/Pages/Dev/DevOptions.razor b/MatrixRoomUtils.Web/Pages/Dev/DevOptions.razor
index 9b0f61c..a1e928f 100644
--- a/MatrixRoomUtils.Web/Pages/Dev/DevOptions.razor
+++ b/MatrixRoomUtils.Web/Pages/Dev/DevOptions.razor
@@ -1,5 +1,8 @@
 @page "/Dev/Options"
 @using ArcaneLibs.Extensions
+@using System.Text.Unicode
+@using System.Text
+@using System.Text.Json
 @inject NavigationManager NavigationManager
 @inject ILocalStorageService LocalStorage
 
@@ -8,23 +11,61 @@
 <h3>Rory&::MatrixUtils - Developer options</h3>
 <hr/>
 
-<InputCheckbox @bind-Value="@settings.DeveloperSettings.EnableLogViewers" @oninput="@LogStuff"></InputCheckbox><label> Enable log views</label><br/>
-<InputCheckbox @bind-Value="@settings.DeveloperSettings.EnableConsoleLogging" @oninput="@LogStuff"></InputCheckbox><label> Enable console logging</label><br/>
-<InputCheckbox @bind-Value="@settings.DeveloperSettings.EnablePortableDevtools" @oninput="@LogStuff"></InputCheckbox><label> Enable portable devtools</label><br/>
+<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 {
 
-    MRUStorageWrapper.Settings settings { get; set; } = new();
+    private MRUStorageWrapper.Settings? userSettings { get; set; }
     protected override async Task OnInitializedAsync() {
-        settings = await TieredStorage.DataStorageProvider.LoadObjectAsync<MRUStorageWrapper.Settings>("mru.settings");
+        // userSettings = await TieredStorage.DataStorageProvider.LoadObjectAsync<MRUStorageWrapper.Settings>("mru.settings");
+        
         await base.OnInitializedAsync();
     }
 
     private async Task LogStuff() {
         await Task.Delay(100);
-        Console.WriteLine($"Settings: {settings.ToJson()}");
-        await TieredStorage.DataStorageProvider.SaveObjectAsync("mru.settings", settings);
+        Console.WriteLine($"Settings: {userSettings.ToJson()}");
+        await TieredStorage.DataStorageProvider.SaveObjectAsync("mru.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);
     }
 
 }