148 lines
4.3 KiB
C#
148 lines
4.3 KiB
C#
using System.Diagnostics;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using Livia.Models;
|
|
using Livia.Models.Data;
|
|
using Livia.Properties;
|
|
using Livia.Utility.DependencyInjection;
|
|
using Livia.ViewModels;
|
|
using Livia.Views.Utility;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Livia.Views;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for SettingsWindow.xaml
|
|
/// </summary>
|
|
public partial class SettingsWindow
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IIdleTimer _idleTimer;
|
|
private readonly SettingsWindowViewModel _viewModel;
|
|
|
|
public SettingsWindow()
|
|
{
|
|
InitializeComponent();
|
|
_logger = ActivatorUtilities.GetServiceOrCreateInstance<ILogger>(ServiceProviderFactory.ServiceProvider);
|
|
_idleTimer = ActivatorUtilities.GetServiceOrCreateInstance<IIdleTimer>(ServiceProviderFactory.ServiceProvider);
|
|
_viewModel = ActivatorUtilities.GetServiceOrCreateInstance<SettingsWindowViewModel>(ServiceProviderFactory.ServiceProvider);
|
|
InitializeComponent();
|
|
DataContext = _viewModel;
|
|
|
|
//TODO:: this is a temp solution
|
|
if (SettingsWindowViewModel.GeneralTabEnabled == false)
|
|
{
|
|
TabControl.SelectedIndex = 2;
|
|
}
|
|
}
|
|
|
|
private void TitleBarMouseLeftButtonDown(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DragMove();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
_logger.LogError(exception, "Error dragging window, sender = {sender}, event = {event}", sender, e);
|
|
}
|
|
}
|
|
|
|
private async void CheckUpdateButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
await _viewModel.CheckUpdate();
|
|
}
|
|
|
|
private async void InstallUpdateButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
await _viewModel.InstallUpdate();
|
|
}
|
|
|
|
private void UserCloudServerButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
Settings.Default.ServerAddress = "astroke.cereflow.cn";
|
|
Settings.Default.ServerPort = 443;
|
|
}
|
|
|
|
private void UserTestServerButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
Settings.Default.ServerAddress = "develop.cereflow.cn";
|
|
Settings.Default.ServerPort = 443;
|
|
}
|
|
|
|
private void UserLocalhostButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
Settings.Default.ServerAddress = "127.0.0.1";
|
|
Settings.Default.ServerPort = 8080;
|
|
}
|
|
|
|
private void OpenLogDirectoryButtonClick(object sender, RoutedEventArgs _)
|
|
{
|
|
try
|
|
{
|
|
Process.Start("explorer.exe", ServiceProviderFactory.LogFolder);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, "Error opening {folder}", ServiceProviderFactory.LogFolder);
|
|
}
|
|
}
|
|
|
|
private void OpenTempDirectoryButtonClick(object sender, RoutedEventArgs _)
|
|
{
|
|
try
|
|
{
|
|
Process.Start("explorer.exe", ServiceConfigurations.TempFolder);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, "Error opening {folder}", ServiceConfigurations.TempFolder);
|
|
}
|
|
}
|
|
|
|
private async void EditPasswordButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
bool success = await _viewModel.EditPassword(OldPasswordBox.Password, NewPasswordBox.Password, ConfirmPasswordBox.Password).ConfigureAwait(true);
|
|
if (success)
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
|
|
private void LanguageSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (e.Source is not ComboBox comboBox)
|
|
return;
|
|
|
|
//This is also fired when open settings window.ignore those calls.
|
|
if (!comboBox.IsLoaded)
|
|
return;
|
|
|
|
if (comboBox.SelectedValue is not string languageId)
|
|
return;
|
|
|
|
ViewUtility.SetDefaultFont(languageId);
|
|
}
|
|
|
|
private void ClearAuthenticationKeyButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
Settings.Default.AuthenticationKey = string.Empty;
|
|
}
|
|
|
|
private void SettingsWindowOnPreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
_idleTimer.ResetTimer();
|
|
}
|
|
|
|
private void SettingsWindowOnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
|
{
|
|
_idleTimer.ResetTimer();
|
|
}
|
|
|
|
private void SettingsWindowOnPreviewMouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
_idleTimer.ResetTimer();
|
|
}
|
|
} |