2023-01-05 07:07:17 +00:00
|
|
|
|
using LANCommander.SDK.Models;
|
|
|
|
|
using Playnite.SDK;
|
|
|
|
|
using System;
|
2023-01-05 01:23:32 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
2023-01-08 18:09:57 +00:00
|
|
|
|
namespace LANCommander.PlaynitePlugin
|
2023-01-05 01:23:32 +00:00
|
|
|
|
{
|
2023-01-14 21:19:14 +00:00
|
|
|
|
public partial class LANCommanderSettingsView : UserControl
|
2023-01-05 01:23:32 +00:00
|
|
|
|
{
|
2023-01-14 21:15:31 +00:00
|
|
|
|
private LANCommanderLibraryPlugin Plugin;
|
2023-01-14 21:16:13 +00:00
|
|
|
|
private LANCommanderSettingsViewModel Settings;
|
2023-01-05 07:07:17 +00:00
|
|
|
|
|
2023-01-14 21:19:14 +00:00
|
|
|
|
public LANCommanderSettingsView(LANCommanderLibraryPlugin plugin)
|
2023-01-05 01:23:32 +00:00
|
|
|
|
{
|
2023-01-12 02:48:39 +00:00
|
|
|
|
this.Plugin = plugin;
|
|
|
|
|
this.Settings = plugin.Settings;
|
2023-01-05 07:07:17 +00:00
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2023-01-12 02:48:39 +00:00
|
|
|
|
DataContext = this;
|
|
|
|
|
|
2023-01-07 18:34:12 +00:00
|
|
|
|
UpdateAuthenticationButtonVisibility();
|
|
|
|
|
}
|
2023-01-05 07:07:17 +00:00
|
|
|
|
|
2023-01-07 18:34:12 +00:00
|
|
|
|
private void UpdateAuthenticationButtonVisibility()
|
|
|
|
|
{
|
2023-01-12 02:48:39 +00:00
|
|
|
|
PART_AuthenticateLabel.Content = "Checking authentication status...";
|
|
|
|
|
PART_AuthenticationButton.IsEnabled = false;
|
2023-01-26 07:11:03 +00:00
|
|
|
|
PART_InstallDirectory.Text = Settings.InstallDirectory;
|
2023-11-03 05:07:20 +00:00
|
|
|
|
PART_ServerAddress.Text = Settings.ServerAddress;
|
2023-01-14 21:51:17 +00:00
|
|
|
|
|
2023-01-12 02:48:39 +00:00
|
|
|
|
var token = new AuthToken()
|
2023-01-05 07:07:17 +00:00
|
|
|
|
{
|
2023-01-14 21:12:02 +00:00
|
|
|
|
AccessToken = Settings.AccessToken,
|
|
|
|
|
RefreshToken = Settings.RefreshToken,
|
2023-01-12 02:48:39 +00:00
|
|
|
|
};
|
2023-01-07 18:34:12 +00:00
|
|
|
|
|
2023-11-10 07:32:30 +00:00
|
|
|
|
var task = Task.Run(() => Plugin.LANCommanderClient.ValidateToken(token))
|
2023-01-12 02:48:39 +00:00
|
|
|
|
.ContinueWith(antecedent =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-01-16 17:32:47 +00:00
|
|
|
|
Dispatcher.Invoke(new System.Action(() =>
|
2023-01-12 02:48:39 +00:00
|
|
|
|
{
|
2023-01-14 21:12:02 +00:00
|
|
|
|
if (antecedent.Result == false)
|
2023-01-12 02:48:39 +00:00
|
|
|
|
{
|
|
|
|
|
PART_AuthenticateLabel.Content = "Authentication failed!";
|
|
|
|
|
PART_AuthenticationButton.IsEnabled = true;
|
2023-11-03 05:07:20 +00:00
|
|
|
|
PART_AuthenticationButton.Visibility = Visibility.Visible;
|
|
|
|
|
PART_DisconnectButton.IsEnabled = false;
|
|
|
|
|
PART_DisconnectButton.Visibility = Visibility.Hidden;
|
2023-01-12 02:48:39 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PART_AuthenticateLabel.Content = "Connection established!";
|
|
|
|
|
PART_AuthenticationButton.IsEnabled = false;
|
2023-11-03 05:07:20 +00:00
|
|
|
|
PART_AuthenticationButton.Visibility = Visibility.Hidden;
|
|
|
|
|
PART_DisconnectButton.IsEnabled = true;
|
|
|
|
|
PART_DisconnectButton.Visibility = Visibility.Visible;
|
2023-01-12 02:48:39 +00:00
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-01-05 01:23:32 +00:00
|
|
|
|
|
2023-01-12 02:48:39 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2023-01-05 07:07:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AuthenticateButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2023-11-20 23:35:11 +00:00
|
|
|
|
var authWindow = Plugin.ShowAuthenticationWindow(Settings.ServerAddress, AuthWindow_Closed);
|
2023-01-07 18:34:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-03 05:07:20 +00:00
|
|
|
|
private void DisconnectButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Plugin.Settings.AccessToken = String.Empty;
|
|
|
|
|
Plugin.Settings.RefreshToken = String.Empty;
|
2023-11-10 07:32:30 +00:00
|
|
|
|
Plugin.LANCommanderClient.UseToken(null);
|
2023-11-03 05:07:20 +00:00
|
|
|
|
|
|
|
|
|
Plugin.SavePluginSettings(Plugin.Settings);
|
|
|
|
|
|
|
|
|
|
PART_AuthenticateLabel.Content = "Not Authenticated";
|
|
|
|
|
PART_AuthenticationButton.IsEnabled = true;
|
|
|
|
|
PART_AuthenticationButton.Visibility = Visibility.Visible;
|
|
|
|
|
PART_DisconnectButton.IsEnabled = false;
|
|
|
|
|
PART_DisconnectButton.Visibility = Visibility.Hidden;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-07 18:34:12 +00:00
|
|
|
|
private void AuthWindow_Closed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateAuthenticationButtonVisibility();
|
2023-01-05 01:23:32 +00:00
|
|
|
|
}
|
2023-01-12 02:48:39 +00:00
|
|
|
|
|
|
|
|
|
private void SelectInstallDirectory_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var selectedDirectory = Plugin.PlayniteApi.Dialogs.SelectFolder();
|
|
|
|
|
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(selectedDirectory))
|
|
|
|
|
{
|
|
|
|
|
PART_InstallDirectory.Text = selectedDirectory;
|
|
|
|
|
Plugin.Settings.InstallDirectory = selectedDirectory;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-05 01:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|