Add local JSON account import and export

This commit is contained in:
Burak Kaan Köse
2026-04-18 15:55:15 +02:00
parent 2a93600ede
commit 00437bae4e
14 changed files with 443 additions and 48 deletions
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -27,6 +30,7 @@ public partial class WelcomePageV2ViewModel : MailBaseViewModel
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(GetStartedCommand))]
[NotifyCanExecuteChangedFor(nameof(ImportFromWinoAccountCommand))]
[NotifyCanExecuteChangedFor(nameof(ImportFromJsonCommand))]
public partial bool IsImportInProgress { get; set; }
[ObservableProperty]
@@ -101,6 +105,49 @@ public partial class WelcomePageV2ViewModel : MailBaseViewModel
}
}
[RelayCommand(CanExecute = nameof(CanOpenWelcomeActions))]
private async Task ImportFromJsonAsync()
{
await ExecuteUIThread(() => ImportStatusMessage = string.Empty);
try
{
var fileContent = await _dialogService.PickWindowsFileContentAsync(".json");
if (fileContent.Length == 0)
{
return;
}
await ExecuteUIThread(() => IsImportInProgress = true);
var jsonContent = Encoding.UTF8.GetString(fileContent);
var result = await _syncService.ImportFromJsonAsync(jsonContent);
if (result.ImportedMailboxCount > 0)
{
ReportUIChange(new WelcomeImportCompletedMessage(result.ImportedMailboxCount));
return;
}
await ExecuteUIThread(() => ImportStatusMessage = BuildInlineImportMessage(result));
}
catch (JsonException ex)
{
Debug.WriteLine(ex.Message);
await _dialogService.ShowMessageAsync(
Translator.WinoAccount_Management_LocalDataInvalidFile,
Translator.GeneralTitle_Error,
WinoCustomMessageDialogIcon.Error);
}
catch (Exception ex)
{
await _dialogService.ShowMessageAsync(ex.Message, Translator.GeneralTitle_Error, WinoCustomMessageDialogIcon.Error);
}
finally
{
await ExecuteUIThread(() => IsImportInProgress = false);
}
}
private bool CanOpenWelcomeActions() => !IsImportInProgress;
private static string BuildInlineImportMessage(WinoAccountSyncImportResult result)