77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Markup.Xaml;
|
|
using Renci.SshNet;
|
|
using Renci.SshNet.Common;
|
|
|
|
namespace kawwa;
|
|
|
|
public partial class SshSetup : UserControl
|
|
{
|
|
public SshSetup()
|
|
{
|
|
// AvaloniaXamlLoader.Load(this);
|
|
InitializeComponent();
|
|
var user = ConfigManager.GetValue("user");
|
|
if (user != null)
|
|
userTextBox.Text = user;
|
|
}
|
|
|
|
private void OnUserTextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
var text = userTextBox.Text;
|
|
if (text != null)
|
|
{
|
|
text = text.Trim();
|
|
if (text == string.Empty)
|
|
{
|
|
connectButton.IsEnabled = false;
|
|
}
|
|
else
|
|
{
|
|
connectButton.IsEnabled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private async void OnCopyButton(object sender, RoutedEventArgs e)
|
|
{
|
|
var topLevel = TopLevel.GetTopLevel(this);
|
|
if (topLevel != null)
|
|
{
|
|
var clipboard = topLevel.Clipboard;
|
|
if (clipboard != null)
|
|
{
|
|
var setText = clipboard.SetTextAsync(SshConnection.PublicKey);
|
|
await setText;
|
|
copyButton.Content = "Copied key to clipboard!";
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnConnectButton(object sender, RoutedEventArgs e)
|
|
{
|
|
var user = userTextBox.Text;
|
|
if (user != null)
|
|
{
|
|
user = user.Trim();
|
|
SshConnection.User = user;
|
|
ConfigManager.SetValue("user", user);
|
|
try
|
|
{
|
|
SshConnection.InitializeConnection();
|
|
Bink.Initialize();
|
|
if (App.TopWindow != null)
|
|
App.TopWindow.Content = new BinkControl();
|
|
|
|
}
|
|
catch (SshAuthenticationException)
|
|
{
|
|
connectButton.Content = "Unauthorized. Try again?";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|