Files
Wino-Mail/Wino.Core.ViewModels/AboutPageViewModel.cs

130 lines
4.8 KiB
C#
Raw Normal View History

2024-04-18 01:44:37 +02:00
using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Input;
using Serilog;
2024-04-18 01:44:37 +02:00
using Wino.Core.Domain;
2024-08-21 13:54:24 +02:00
using Wino.Core.Domain.Enums;
2024-04-18 01:44:37 +02:00
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.ViewModels;
public partial class AboutPageViewModel : CoreBaseViewModel
2024-04-18 01:44:37 +02:00
{
private readonly IStoreRatingService _storeRatingService;
private readonly IMailDialogService _dialogService;
private readonly INativeAppService _nativeAppService;
private readonly IApplicationConfiguration _appInitializerService;
private readonly IClipboardService _clipboardService;
private readonly IFileService _fileService;
private readonly IWinoLogger _logInitializer;
public string VersionName => _nativeAppService.GetFullAppVersion();
public string DiscordChannelUrl => "https://discord.gg/windows-apps-hub-714581497222398064";
public string GitHubUrl => "https://github.com/bkaankose/Wino-Mail/";
public string PrivacyPolicyUrl => "https://www.winomail.app/support/privacy";
public string PaypalUrl => "https://paypal.me/bkaankose?country.x=PL&locale.x=en_US";
public IPreferencesService PreferencesService { get; }
public AboutPageViewModel(IStoreRatingService storeRatingService,
IMailDialogService dialogService,
INativeAppService nativeAppService,
IPreferencesService preferencesService,
IApplicationConfiguration appInitializerService,
IClipboardService clipboardService,
IFileService fileService,
IWinoLogger logInitializer)
2025-02-16 11:35:43 +01:00
{
_storeRatingService = storeRatingService;
_dialogService = dialogService;
_nativeAppService = nativeAppService;
_logInitializer = logInitializer;
_appInitializerService = appInitializerService;
_clipboardService = clipboardService;
_fileService = fileService;
PreferencesService = preferencesService;
}
2024-04-18 01:44:37 +02:00
protected override void OnActivated()
{
base.OnActivated();
2024-04-18 01:44:37 +02:00
PreferencesService.PreferenceChanged -= PreferencesChanged;
PreferencesService.PreferenceChanged += PreferencesChanged;
}
2024-04-18 01:44:37 +02:00
protected override void OnDeactivated()
{
base.OnDeactivated();
PreferencesService.PreferenceChanged -= PreferencesChanged;
}
private void PreferencesChanged(object sender, string e)
{
if (e == nameof(PreferencesService.IsLoggingEnabled))
2025-02-16 11:35:43 +01:00
{
_logInitializer.RefreshLoggingLevel();
2024-04-18 01:44:37 +02:00
}
}
[RelayCommand]
private async Task CopyDiagnosticId()
{
try
2024-04-18 01:44:37 +02:00
{
await _clipboardService.CopyClipboardAsync(PreferencesService.DiagnosticId);
_dialogService.InfoBarMessage(Translator.Buttons_Copy, string.Format(Translator.ClipboardTextCopied_Message, "Id"), InfoBarMessageType.Success);
2025-02-16 11:54:23 +01:00
}
catch (Exception ex)
{
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, string.Format(Translator.ClipboardTextCopyFailed_Message, "Id"), InfoBarMessageType.Error);
Log.Error(ex, "Failed to copy diagnostic id to clipboard.");
}
}
[RelayCommand]
private async Task ShareWinoLogAsync()
{
var appDataFolder = _appInitializerService.ApplicationDataFolderPath;
var selectedFolderPath = await _dialogService.PickWindowsFolderAsync();
if (string.IsNullOrEmpty(selectedFolderPath)) return;
2025-02-16 11:54:23 +01:00
var areLogsSaved = await _fileService.SaveLogsToFolderAsync(appDataFolder, selectedFolderPath).ConfigureAwait(false);
if (areLogsSaved)
{
_dialogService.InfoBarMessage(Translator.Info_LogsSavedTitle, string.Format(Translator.Info_LogsSavedMessage, Constants.LogArchiveFileName), InfoBarMessageType.Success);
2025-02-16 11:54:23 +01:00
}
else
{
_dialogService.InfoBarMessage(Translator.Info_LogsNotFoundTitle, Translator.Info_LogsNotFoundMessage, InfoBarMessageType.Error);
}
}
2025-02-16 11:35:43 +01:00
[RelayCommand]
private async Task Navigate(object url)
{
if (url is string stringUrl)
{
if (stringUrl == "Store")
await ShowRateDialogAsync();
else
{
// Discord disclaimer message about server.
if (stringUrl == DiscordChannelUrl)
await _dialogService.ShowMessageAsync(Translator.DiscordChannelDisclaimerMessage,
Translator.DiscordChannelDisclaimerTitle,
WinoCustomMessageDialogIcon.Warning);
await _nativeAppService.LaunchUriAsync(new Uri(stringUrl));
2024-04-18 01:44:37 +02:00
}
}
}
private Task ShowRateDialogAsync() => _storeRatingService.LaunchStorePageForReviewAsync();
2024-04-18 01:44:37 +02:00
}