using FoxTube.Services;
using System;
using Windows.ApplicationModel.Core;
using Windows.Security.Credentials;
using Windows.UI;
using Windows.UI.ViewManagement;
namespace FoxTube.Utils
{
public static class Utils
{
///
/// Terminates current application session
///
public static void CloseApp() =>
CoreApplication.Exit();
///
/// Restarts application
///
public static void RestartApp() =>
RestartApp(null);
///
/// Restarts application with specified parameters
///
/// Parameters which will be provided to new application instance
public static async void RestartApp(string args) =>
await CoreApplication.RequestRestartAsync(args ?? "");
public static async void InitializeFailsafeProtocol()
{
Metrics.AddEvent("Failsafe protocol initiated");
await StorageService.ClearStorage();
PasswordVault passwordVault = new PasswordVault();
foreach (PasswordCredential credential in passwordVault.RetrieveAll())
passwordVault.Remove(credential);
RestartApp();
}
public static void UpdateTitleBarTheme(bool isDark)
{
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
titleBar.ButtonInactiveForegroundColor = Colors.Gray;
if (isDark)
{
titleBar.ButtonForegroundColor =
titleBar.ButtonHoverForegroundColor =
titleBar.ButtonPressedForegroundColor = Colors.White;
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(50, 255, 255, 255);
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(30, 255, 255, 255);
}
else
{
titleBar.ButtonForegroundColor =
titleBar.ButtonHoverForegroundColor =
titleBar.ButtonPressedForegroundColor = Colors.Black;
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(50, 0, 0, 0);
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(70, 0, 0, 0);
}
}
}
}