2024-08-05 00:36:26 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
using Wino.Core.Domain;
|
|
|
|
|
using Wino.Core.Domain.Enums;
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
using Wino.Core.Domain.Models.Navigation;
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
namespace Wino.Mail.ViewModels;
|
|
|
|
|
|
|
|
|
|
public partial class AppPreferencesPageViewModel : MailBaseViewModel
|
2024-08-05 00:36:26 +02:00
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
public IPreferencesService PreferencesService { get; }
|
2024-08-05 00:36:26 +02:00
|
|
|
|
2025-02-22 00:22:00 +01:00
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial List<string> SearchModes { get; set; }
|
|
|
|
|
|
2026-02-22 17:55:57 +01:00
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial List<string> ApplicationModes { get; set; }
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
[ObservableProperty]
|
|
|
|
|
[NotifyPropertyChangedFor(nameof(IsStartupBehaviorDisabled))]
|
|
|
|
|
[NotifyPropertyChangedFor(nameof(IsStartupBehaviorEnabled))]
|
|
|
|
|
private StartupBehaviorResult startupBehaviorResult;
|
2024-08-05 00:36:26 +02:00
|
|
|
|
2025-07-24 09:45:35 +02:00
|
|
|
private int _emailSyncIntervalMinutes;
|
|
|
|
|
public int EmailSyncIntervalMinutes
|
|
|
|
|
{
|
|
|
|
|
get => _emailSyncIntervalMinutes;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _emailSyncIntervalMinutes, value);
|
|
|
|
|
|
|
|
|
|
PreferencesService.EmailSyncIntervalMinutes = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public bool IsStartupBehaviorDisabled => !IsStartupBehaviorEnabled;
|
|
|
|
|
public bool IsStartupBehaviorEnabled => StartupBehaviorResult == StartupBehaviorResult.Enabled;
|
2024-08-05 00:36:26 +02:00
|
|
|
|
2025-02-22 00:22:00 +01:00
|
|
|
private string _selectedDefaultSearchMode;
|
|
|
|
|
public string SelectedDefaultSearchMode
|
|
|
|
|
{
|
|
|
|
|
get => _selectedDefaultSearchMode;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _selectedDefaultSearchMode, value);
|
|
|
|
|
|
|
|
|
|
PreferencesService.DefaultSearchMode = (SearchMode)SearchModes.IndexOf(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 17:55:57 +01:00
|
|
|
private string _selectedDefaultApplicationMode;
|
|
|
|
|
public string SelectedDefaultApplicationMode
|
|
|
|
|
{
|
|
|
|
|
get => _selectedDefaultApplicationMode;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _selectedDefaultApplicationMode, value);
|
|
|
|
|
|
|
|
|
|
PreferencesService.DefaultApplicationMode = (WinoApplicationMode)ApplicationModes.IndexOf(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
private readonly IMailDialogService _dialogService;
|
|
|
|
|
private readonly IStartupBehaviorService _startupBehaviorService;
|
2024-08-05 00:36:26 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public AppPreferencesPageViewModel(IMailDialogService dialogService,
|
|
|
|
|
IPreferencesService preferencesService,
|
|
|
|
|
IStartupBehaviorService startupBehaviorService)
|
|
|
|
|
{
|
|
|
|
|
_dialogService = dialogService;
|
|
|
|
|
PreferencesService = preferencesService;
|
|
|
|
|
_startupBehaviorService = startupBehaviorService;
|
2025-02-16 11:35:43 +01:00
|
|
|
|
2025-02-22 00:22:00 +01:00
|
|
|
SearchModes =
|
|
|
|
|
[
|
|
|
|
|
Translator.SettingsAppPreferences_SearchMode_Local,
|
|
|
|
|
Translator.SettingsAppPreferences_SearchMode_Online
|
|
|
|
|
];
|
|
|
|
|
|
2026-02-22 17:55:57 +01:00
|
|
|
ApplicationModes =
|
|
|
|
|
[
|
|
|
|
|
Translator.SettingsAppPreferences_ApplicationMode_Mail,
|
2026-03-10 16:50:16 +01:00
|
|
|
Translator.SettingsAppPreferences_ApplicationMode_Calendar,
|
|
|
|
|
Translator.ContactsPage_Title
|
2026-02-22 17:55:57 +01:00
|
|
|
];
|
|
|
|
|
|
2025-02-22 00:22:00 +01:00
|
|
|
SelectedDefaultSearchMode = SearchModes[(int)PreferencesService.DefaultSearchMode];
|
2026-02-22 17:55:57 +01:00
|
|
|
SelectedDefaultApplicationMode = ApplicationModes[(int)PreferencesService.DefaultApplicationMode];
|
2025-07-24 09:45:35 +02:00
|
|
|
EmailSyncIntervalMinutes = PreferencesService.EmailSyncIntervalMinutes;
|
2025-02-16 11:54:23 +01:00
|
|
|
}
|
2025-02-16 11:43:30 +01:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
[RelayCommand]
|
|
|
|
|
private async Task ToggleStartupBehaviorAsync()
|
|
|
|
|
{
|
|
|
|
|
if (IsStartupBehaviorEnabled)
|
2025-02-16 11:35:43 +01:00
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
await DisableStartupAsync();
|
2025-02-16 11:35:43 +01:00
|
|
|
}
|
2025-02-16 11:54:23 +01:00
|
|
|
else
|
2025-02-16 11:35:43 +01:00
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
await EnableStartupAsync();
|
2025-02-16 11:35:43 +01:00
|
|
|
}
|
2025-02-16 11:43:30 +01:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
OnPropertyChanged(nameof(IsStartupBehaviorEnabled));
|
|
|
|
|
}
|
2025-02-16 11:43:30 +01:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
private async Task EnableStartupAsync()
|
|
|
|
|
{
|
|
|
|
|
StartupBehaviorResult = await _startupBehaviorService.ToggleStartupBehavior(true);
|
|
|
|
|
|
|
|
|
|
NotifyCurrentStartupState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task DisableStartupAsync()
|
|
|
|
|
{
|
|
|
|
|
StartupBehaviorResult = await _startupBehaviorService.ToggleStartupBehavior(false);
|
|
|
|
|
|
|
|
|
|
NotifyCurrentStartupState();
|
|
|
|
|
}
|
2025-02-16 11:43:30 +01:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
private void NotifyCurrentStartupState()
|
|
|
|
|
{
|
|
|
|
|
if (StartupBehaviorResult == StartupBehaviorResult.Enabled)
|
2025-02-16 11:35:43 +01:00
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_Enabled, InfoBarMessageType.Success);
|
2025-02-16 11:35:43 +01:00
|
|
|
}
|
2025-02-16 11:54:23 +01:00
|
|
|
else if (StartupBehaviorResult == StartupBehaviorResult.Disabled)
|
|
|
|
|
{
|
|
|
|
|
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_Disabled, InfoBarMessageType.Warning);
|
|
|
|
|
}
|
|
|
|
|
else if (StartupBehaviorResult == StartupBehaviorResult.DisabledByPolicy)
|
|
|
|
|
{
|
|
|
|
|
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_DisabledByPolicy, InfoBarMessageType.Warning);
|
|
|
|
|
}
|
|
|
|
|
else if (StartupBehaviorResult == StartupBehaviorResult.DisabledByUser)
|
|
|
|
|
{
|
|
|
|
|
_dialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_DisabledByUser, InfoBarMessageType.Warning);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, Translator.SettingsAppPreferences_StartupBehavior_FatalError, InfoBarMessageType.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-05 00:36:26 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
2024-08-05 00:36:26 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
public override async void OnNavigatedTo(NavigationMode mode, object parameters)
|
|
|
|
|
{
|
|
|
|
|
base.OnNavigatedTo(mode, parameters);
|
2024-08-05 00:36:26 +02:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
StartupBehaviorResult = await _startupBehaviorService.GetCurrentStartupBehaviorAsync();
|
2024-08-05 00:36:26 +02:00
|
|
|
}
|
|
|
|
|
}
|