/*
* Copyright (c) 2023 Proton AG
*
* This file is part of ProtonVPN.
*
* ProtonVPN is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProtonVPN is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProtonVPN. If not, see .
*/
using Microsoft.UI.Xaml.Navigation;
using ProtonVPN.Client.Common.Dispatching;
using ProtonVPN.Client.Core.Enums;
using ProtonVPN.Client.Core.Services.Mapping;
using ProtonVPN.Client.Core.Services.Navigation;
using ProtonVPN.Client.Core.Services.Navigation.Bases;
using ProtonVPN.Client.EventMessaging.Contracts;
using ProtonVPN.Client.Logic.Auth.Contracts.Enums;
using ProtonVPN.Client.Logic.Auth.Contracts.Messages;
using ProtonVPN.Client.UI.Main.Settings.Connection;
using ProtonVPN.Client.UI.Main.Settings.Pages;
using ProtonVPN.Client.UI.Main.Settings.Pages.About;
using ProtonVPN.Client.UI.Main.Settings.Pages.Advanced;
using ProtonVPN.Client.UI.Main.Settings.Pages.Connection;
using ProtonVPN.Client.UI.Main.Settings.Pages.ConnectionPreferences;
using ProtonVPN.Logging.Contracts;
namespace ProtonVPN.Client.Services.Navigation;
public class SettingsViewNavigator : ViewNavigatorBase, ISettingsViewNavigator,
IEventMessageReceiver
{
public override bool IsNavigationStackEnabled => true;
public SettingsViewNavigator(
ILogger logger,
IPageViewMapper pageViewMapper,
IUIThreadDispatcher uiThreadDispatcher)
: base(logger, pageViewMapper, uiThreadDispatcher)
{ }
protected override void OnFrameNavigated(NavigationEventArgs e)
{
base.OnFrameNavigated(e);
if (GetCurrentPageContext() is CommonSettingsPageViewModel)
{
ClearBackStack();
}
}
public override FrameLoadedBehavior LoadBehavior { get; protected set; } = FrameLoadedBehavior.NavigateToDefaultViewIfEmpty;
public Task NavigateToFeatureViewAsync(ConnectionFeature feature, bool isDirectNavigation = false)
{
return feature switch
{
ConnectionFeature.NetShield => NavigateToNetShieldSettingsViewAsync(isDirectNavigation),
ConnectionFeature.KillSwitch => NavigateToKillSwitchSettingsViewAsync(isDirectNavigation),
ConnectionFeature.PortForwarding => NavigateToPortForwardingSettingsViewAsync(isDirectNavigation),
ConnectionFeature.SplitTunneling => NavigateToSplitTunnelingSettingsViewAsync(isDirectNavigation),
_ => Task.FromResult(false),
};
}
public Task NavigateToAdvancedSettingsViewAsync()
{
return NavigateToAsync();
}
public Task NavigateToCommonSettingsViewAsync(bool forceNavigation = false)
{
return NavigateToAsync(forceNavigation: forceNavigation);
}
public Task NavigateToConnectionPreferencesSettingsViewAsync(bool isDirectNavigation = false)
{
return NavigateToAsync(parameter: isDirectNavigation);
}
public Task NavigateToProtocolSettingsViewAsync(bool isDirectNavigation = false)
{
return NavigateToAsync(parameter: isDirectNavigation);
}
public Task NavigateToNetShieldSettingsViewAsync(bool isDirectNavigation = false)
{
return NavigateToAsync(parameter: isDirectNavigation);
}
public Task NavigateToKillSwitchSettingsViewAsync(bool isDirectNavigation = false)
{
return NavigateToAsync(parameter: isDirectNavigation);
}
public Task NavigateToPortForwardingSettingsViewAsync(bool isDirectNavigation = false)
{
return NavigateToAsync(parameter: isDirectNavigation);
}
public Task NavigateToSplitTunnelingSettingsViewAsync(bool isDirectNavigation = false)
{
return NavigateToAsync(parameter: isDirectNavigation);
}
public Task NavigateToVpnAcceleratorSettingsViewAsync()
{
return NavigateToAsync();
}
public Task NavigateToCustomDnsSettingsViewAsync()
{
return NavigateToAsync();
}
public Task NavigateToAutoStartupSettingsViewAsync()
{
return NavigateToAsync();
}
public Task NavigateToDebugLogsSettingsViewAsync()
{
return NavigateToAsync();
}
public Task NavigateToAboutViewAsync()
{
return NavigateToAsync();
}
public Task NavigateToLicensingViewAsync()
{
return NavigateToAsync();
}
public Task NavigateToCensorshipViewAsync()
{
return NavigateToAsync();
}
public override Task NavigateToDefaultAsync()
{
return NavigateToCommonSettingsViewAsync();
}
public void Receive(AuthenticationStatusChanged message)
{
switch (message.AuthenticationStatus)
{
case AuthenticationStatus.LoggingOut:
case AuthenticationStatus.LoggedIn:
// Force navigation to automatically discard any unsaved changes
UIThreadDispatcher.TryEnqueue(async () => await NavigateToCommonSettingsViewAsync(forceNavigation: true));
break;
default:
break;
}
}
}