feels support
This commit is contained in:
parent
c516ad2b86
commit
cb4f70de6e
14
Bink.cs
14
Bink.cs
@ -1,6 +1,4 @@
|
||||
using Microsoft.VisualBasic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@ -21,24 +19,24 @@ namespace wakka
|
||||
{
|
||||
private static SshConnection Ssh { get; set; } = new SshConnection();
|
||||
|
||||
public string RunBinkCommand(string command)
|
||||
public void PostBink(string message)
|
||||
{
|
||||
return Ssh.RunCommand($"town bink --{command}");
|
||||
Ssh.RunCommandWithInput("town bink --pipe", message);
|
||||
}
|
||||
|
||||
public List<BinkPost>? AllBinks()
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<BinkPost>>(RunBinkCommand("dump"));
|
||||
return JsonSerializer.Deserialize<List<BinkPost>>(Ssh.RunCommand("town bink --dump"));
|
||||
}
|
||||
|
||||
public List<BinkPost>? BinksBefore(long TimeStamp)
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<BinkPost>>(RunBinkCommand("dump-before"));
|
||||
return JsonSerializer.Deserialize<List<BinkPost>>(Ssh.RunCommand($"town bink --dump-before {TimeStamp}"));
|
||||
}
|
||||
|
||||
public List<BinkPost>? BinksAfter(long TimeStamp)
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<BinkPost>>(RunBinkCommand("dump-after"));
|
||||
return JsonSerializer.Deserialize<List<BinkPost>>(Ssh.RunCommand($"town bink --dump-after {TimeStamp}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@ -14,52 +15,39 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<CommandBar DefaultLabelPosition="Right" Grid.Row="0">
|
||||
<AppBarButton Icon="Add" Label="Post" />
|
||||
<AppBarButton Icon="Refresh" Label="Update" Click="GetNewBinksButton" />
|
||||
<AppBarButton Icon="Add" Label="Post" Click="OnBinkCreate" />
|
||||
</CommandBar>
|
||||
|
||||
<ContentDialog
|
||||
x:Name="binkComposeDialog"
|
||||
Title="New Bink"
|
||||
PrimaryButtonText="Bink!"
|
||||
CloseButtonText="Cancel"
|
||||
PrimaryButtonClick="BinkSubmit">
|
||||
<TextBox
|
||||
PlaceholderText="Your bink here..."
|
||||
Width="300"
|
||||
Height="150"
|
||||
TextWrapping="Wrap"
|
||||
AcceptsReturn="True"
|
||||
TextChanged="OnTextChanged"
|
||||
x:Name="binkComposeBox"/>
|
||||
</ContentDialog>
|
||||
|
||||
<ListView x:Name="binksListView" SelectionMode="None" Padding="5,10,5,10" Grid.Row="1">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="local:BinkPost">
|
||||
<StackPanel MaxWidth="1000" CornerRadius="8" Padding="10,10,10,10" Background="{ThemeResource CardBackgroundFillColorSecondaryBrush}" Margin="0,0,0,20">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="~"/>
|
||||
<TextBlock Text="{x:Bind User}"/>
|
||||
<TextBlock IsTextSelectionEnabled="True" Text="{x:Bind User}"/>
|
||||
<TextBlock Margin="10,0,0,0" Foreground="{ThemeResource TextFillColorTertiaryBrush}" Text="{x:Bind TimeString}"/>
|
||||
</StackPanel>
|
||||
<TextBlock Margin="5,5,0,0" Text="{x:Bind Body}" />
|
||||
<TextBlock TextWrapping="WrapWholeWords" IsTextSelectionEnabled="True" Margin="5,5,0,0" Text="{x:Bind Body}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
<!--<Page
|
||||
x:Class="wakka.BinkPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:wakka"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<StackPanel>
|
||||
<CommandBar Background="Transparent" IsOpen="False" DefaultLabelPosition="Right">
|
||||
<AppBarButton Icon="Add" Label="Post"/>
|
||||
</CommandBar>
|
||||
<ListView x:Name="binksListView" SelectionMode="None" Padding="5,10,5,10">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="local:BinkPost">
|
||||
<StackPanel Padding="10,10,10,10" Background="{ThemeResource CardBackgroundFillColorSecondaryBrush}" Margin="0,0,0,20">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="~"/>
|
||||
<TextBlock Text="{x:Bind User}"/>
|
||||
<TextBlock Margin="10,0,0,0" Foreground="{ThemeResource TextFillColorTertiaryBrush}" Text="{x:Bind TimeString}"/>
|
||||
</StackPanel>
|
||||
<TextBlock Margin="5,5,0,0" Text="{x:Bind Body}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackPanel>
|
||||
</Page>-->
|
||||
|
@ -1,18 +1,12 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Org.BouncyCastle.Tls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
@ -24,24 +18,88 @@ namespace wakka
|
||||
/// </summary>
|
||||
public sealed partial class BinkPage : Page
|
||||
{
|
||||
private DispatcherTimer timer;
|
||||
|
||||
private readonly ObservableCollection<BinkPost> Binks = [];
|
||||
private static SshConnection Ssh { get; set; } = new SshConnection();
|
||||
private static Bink Bink { get; set; } = new Bink();
|
||||
|
||||
public BinkPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
var Bink = new Bink();
|
||||
StartTimer();
|
||||
var BinkList = Bink.AllBinks();
|
||||
if (BinkList != null)
|
||||
{
|
||||
foreach (var bink in BinkList)
|
||||
{
|
||||
var date = DateTimeOffset.FromUnixTimeSeconds(bink.Time / 1000000000).DateTime.ToLocalTime();
|
||||
bink.TimeString = date.ToString("HH:mm (dddd, MMMM dd, yyyy)");
|
||||
SetBinkDateString(bink);
|
||||
Binks.Add(bink);
|
||||
}
|
||||
}
|
||||
binksListView.ItemsSource = Binks;
|
||||
}
|
||||
public void SetBinkDateString (BinkPost bink)
|
||||
{
|
||||
var date = DateTimeOffset.FromUnixTimeSeconds(bink.Time / 1000000000).DateTime.ToLocalTime();
|
||||
bink.TimeString = date.ToString("HH:mm (dddd, MMMM dd, yyyy)");
|
||||
}
|
||||
public void GetNewBinks()
|
||||
{
|
||||
var BinkList = Bink.BinksAfter(Binks[0].Time);
|
||||
if (BinkList != null)
|
||||
{
|
||||
BinkList.Reverse();
|
||||
foreach (var bink in BinkList)
|
||||
{
|
||||
SetBinkDateString(bink);
|
||||
Binks.Insert(0, bink);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void BinkSubmit(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||
{
|
||||
var message = binkComposeBox.Text;
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
{
|
||||
Bink.PostBink(message);
|
||||
binkComposeBox.Text = string.Empty;
|
||||
GetNewBinks();
|
||||
}
|
||||
|
||||
}
|
||||
private void OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(binkComposeBox.Text))
|
||||
{
|
||||
binkComposeDialog.IsPrimaryButtonEnabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
binkComposeDialog.IsPrimaryButtonEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnBinkCreate(object sender, RoutedEventArgs e)
|
||||
{
|
||||
binkComposeDialog.IsPrimaryButtonEnabled = false;
|
||||
await binkComposeDialog.ShowAsync();
|
||||
}
|
||||
public void GetNewBinksButton(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||
{
|
||||
GetNewBinks();
|
||||
}
|
||||
|
||||
private void StartTimer()
|
||||
{
|
||||
timer = new DispatcherTimer();
|
||||
timer.Interval = TimeSpan.FromSeconds(20);
|
||||
timer.Tick += Timer_Tick;
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
private void Timer_Tick(object? sender, object? e)
|
||||
{
|
||||
GetNewBinks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
44
Feels.cs
Normal file
44
Feels.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace wakka
|
||||
{
|
||||
public class FeelsPost
|
||||
{
|
||||
[JsonPropertyName("user")]
|
||||
public string? User { get; set; }
|
||||
[JsonPropertyName("path")]
|
||||
public string? Path { get; set; }
|
||||
[JsonPropertyName("m_time")]
|
||||
public long M_Time { get; set; }
|
||||
public string TimeString { get; set; } = string.Empty;
|
||||
public string Body { get; set; } = string.Empty;
|
||||
public int WordCount { get; set; } = 0;
|
||||
}
|
||||
|
||||
internal class Feels
|
||||
{
|
||||
private static SshConnection Ssh { get; set; } = new SshConnection();
|
||||
|
||||
public List<FeelsPost>? AllFeels()
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<FeelsPost>>(Ssh.RunCommand("~nebula/bin/dumpfeels"));
|
||||
}
|
||||
|
||||
public List<FeelsPost>? FeelsAfter(long TimeStamp)
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<FeelsPost>>(Ssh.RunCommand($"~nebula/bin/dumpfeels --after {TimeStamp}"));
|
||||
}
|
||||
|
||||
public List<FeelsPost>? FeelsFromUser(string User, List<FeelsPost> Feels)
|
||||
{
|
||||
return Feels.FindAll(i => i.User == User);
|
||||
}
|
||||
|
||||
public string GetFeelsBody(FeelsPost Post)
|
||||
{
|
||||
return Ssh.RunCommand($"cat {Post.Path}");
|
||||
}
|
||||
}
|
||||
}
|
36
FeelsFeedPage.xaml
Normal file
36
FeelsFeedPage.xaml
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Page
|
||||
x:Class="wakka.FeelsFeedPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:wakka"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
<Grid>
|
||||
<ScrollViewer x:Name="scrollViewer" ViewChanged="ViewChanged">
|
||||
<ListView Grid.Row="0" x:Name="feelsListView" SelectionMode="None">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="local:FeelsPost">
|
||||
<Expander Width="600" Margin="0,10,0,10" IsExpanded="True" CornerRadius="8">
|
||||
<Expander.Header>
|
||||
<StackPanel Margin="10,10,10,10" HorizontalAlignment="Left">
|
||||
<StackPanel Padding="0,0,0,5" Orientation="Horizontal">
|
||||
<TextBlock Text="~"/>
|
||||
<TextBlock IsTextSelectionEnabled="True" Text="{x:Bind User}"/>
|
||||
<TextBlock Margin="7,0,0,0" Foreground="{ThemeResource TextFillColorTertiaryBrush}" Text="{x:Bind TimeString}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Expander.Header>
|
||||
<Expander.Content>
|
||||
<TextBlock IsTextSelectionEnabled="True" TextWrapping="WrapWholeWords" Grid.Row="1" Text="{x:Bind Body}" />
|
||||
</Expander.Content>
|
||||
</Expander>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Page>
|
59
FeelsFeedPage.xaml.cs
Normal file
59
FeelsFeedPage.xaml.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
|
||||
namespace wakka
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class FeelsFeedPage : Page
|
||||
{
|
||||
private readonly Feels Feels = new Feels();
|
||||
private readonly ObservableCollection<FeelsPost> LiveFeelsPosts = [];
|
||||
private readonly List<List<FeelsPost>> AllFeels;
|
||||
private int CurrentChunk = 0;
|
||||
|
||||
public FeelsFeedPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
var feels = Feels.AllFeels();
|
||||
AllFeels = (List<List<FeelsPost>>)feels.Chunk(4).Select(chunk => chunk.ToList()).ToList();
|
||||
LoadFeelsChunk();
|
||||
feelsListView.ItemsSource = LiveFeelsPosts;
|
||||
}
|
||||
|
||||
private void LoadFeelsChunk()
|
||||
{
|
||||
var chunk = AllFeels[CurrentChunk];
|
||||
foreach (var feel in chunk)
|
||||
{
|
||||
var date = DateTimeOffset.FromUnixTimeSeconds(feel.M_Time).DateTime.ToLocalTime();
|
||||
feel.TimeString = date.ToString("HH:mm (dddd, MMMM dd, yyyy)");
|
||||
var body = Feels.GetFeelsBody(feel);
|
||||
char[] delimiters = new char[] { ' ', '\n' };
|
||||
feel.WordCount = body.Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Length;
|
||||
feel.Body = body;
|
||||
LiveFeelsPosts.Add(feel);
|
||||
}
|
||||
CurrentChunk++;
|
||||
}
|
||||
|
||||
private void ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
|
||||
{
|
||||
var scrollViewer = sender as ScrollViewer;
|
||||
if (scrollViewer != null)
|
||||
{
|
||||
if (scrollViewer.VerticalOffset >= scrollViewer.ScrollableHeight)
|
||||
{
|
||||
LoadFeelsChunk();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
FeelsNavigationPage.xaml
Normal file
24
FeelsNavigationPage.xaml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Page
|
||||
x:Class="wakka.FeelsNavigationPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:wakka"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<SelectorBar Grid.Row="0" x:Name="feelsSelectorBar" SelectionChanged="SelectorChanged">
|
||||
<SelectorBarItem x:Name="feedSelectorBarItem" Text="Feed" IsSelected="True" />
|
||||
<!--<SelectorBarItem x:Name="usersSelectorBarItem" Text="Users" />-->
|
||||
</SelectorBar>
|
||||
|
||||
<Frame Grid.Row="1" x:Name="FeelsNavigationFrame" IsNavigationStackEnabled="False" />
|
||||
</Grid>
|
||||
</Page>
|
37
FeelsNavigationPage.xaml.cs
Normal file
37
FeelsNavigationPage.xaml.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
|
||||
namespace wakka
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class FeelsNavigationPage : Page
|
||||
{
|
||||
public FeelsNavigationPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void SelectorChanged(SelectorBar sender, SelectorBarSelectionChangedEventArgs args)
|
||||
{
|
||||
FeelsNavigationFrame.Navigate(typeof(FeelsFeedPage));
|
||||
}
|
||||
}
|
||||
}
|
15
FeelsUserPage.xaml
Normal file
15
FeelsUserPage.xaml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Page
|
||||
x:Class="wakka.FeelsUserPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:wakka"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</Page>
|
31
FeelsUserPage.xaml.cs
Normal file
31
FeelsUserPage.xaml.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
|
||||
namespace wakka
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class FeelsUserPage : Page
|
||||
{
|
||||
public FeelsUserPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
@ -28,28 +15,27 @@ namespace wakka
|
||||
{
|
||||
private static SshConnection Ssh { get; set; } = new SshConnection();
|
||||
public Frame RootFrame;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.AppWindow.MoveAndResize(new Windows.Graphics.RectInt32(100, 100, 854, 480));
|
||||
Ssh.DeleteSshKey();
|
||||
RootFrame = rootFrame;
|
||||
Ssh.DeleteSshKey();
|
||||
if (Ssh.KeyExists() & (string)App.LocalSettingsData.Values["username"] != null)
|
||||
{
|
||||
Ssh.InitializeConnection((string)App.LocalSettingsData.Values["username"]);
|
||||
RootFrame.Content = new NavigationPage();
|
||||
try
|
||||
{
|
||||
Ssh.InitializeConnection((string)App.LocalSettingsData.Values["username"]);
|
||||
RootFrame.Content = new NavigationPage();
|
||||
}
|
||||
catch (Renci.SshNet.Common.SshAuthenticationException)
|
||||
{
|
||||
RootFrame.Content = new StartupSshPage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RootFrame.Content = new StartupSshPage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//private void myButton_Click(object sender, RoutedEventArgs e)
|
||||
//{
|
||||
// myButton.Content = "Clicked";
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@
|
||||
xmlns:local="using:wakka"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource SolidBackgroundFillColorSecondaryBrush}">
|
||||
|
||||
<NavigationView x:Name="navigationView" OpenPaneLength="200" IsPaneOpen="False">
|
||||
<NavigationView x:Name="navigationView" OpenPaneLength="200" IsPaneOpen="False" SelectionChanged="navigationView_SelectionChanged">
|
||||
<NavigationView.MenuItems>
|
||||
<NavigationViewItem Icon="World" IsSelected="True" Content="Bink" x:Name="binkPageNav" />
|
||||
<NavigationViewItem Icon="Comment" IsSelected="False" Content="BBJ" />
|
||||
<NavigationViewItem Icon="Library" IsSelected="False" Content="Feels" />
|
||||
<NavigationViewItem Icon="Library" IsSelected="False" Content="Feels" x:Name="feelsPageNav"/>
|
||||
</NavigationView.MenuItems>
|
||||
<Frame x:Name="navigationFrame"/>
|
||||
</NavigationView>
|
||||
|
@ -26,7 +26,21 @@ namespace wakka
|
||||
public NavigationPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
navigationFrame.Content = new BinkPage();
|
||||
}
|
||||
|
||||
private void navigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
|
||||
{
|
||||
if (args.SelectedItem is NavigationViewItem selectedItem)
|
||||
{
|
||||
if (selectedItem == binkPageNav)
|
||||
{
|
||||
navigationFrame.Navigate(typeof(BinkPage));
|
||||
}
|
||||
else if (selectedItem == feelsPageNav)
|
||||
{
|
||||
navigationFrame.Navigate(typeof(FeelsNavigationPage));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,10 @@ using Renci.SshNet;
|
||||
using Renci.SshNet.Common;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Media.Protection.PlayReady;
|
||||
|
||||
namespace wakka
|
||||
{
|
||||
@ -56,6 +60,25 @@ namespace wakka
|
||||
return rc.Result;
|
||||
}
|
||||
|
||||
public async void RunCommandWithInput(string command, string input)
|
||||
{
|
||||
if (Client == null || !Client.IsConnected)
|
||||
{
|
||||
throw new InvalidOperationException("SSH client is not connected.");
|
||||
}
|
||||
using (SshCommand task = Client.CreateCommand(command))
|
||||
{
|
||||
Task executeTask = task.ExecuteAsync(CancellationToken.None);
|
||||
|
||||
using (Stream inputStream = task.CreateInputStream())
|
||||
{
|
||||
inputStream.Write(Encoding.UTF8.GetBytes(input));
|
||||
}
|
||||
|
||||
await executeTask;
|
||||
}
|
||||
}
|
||||
|
||||
public string CreateSshKey()
|
||||
{
|
||||
var keygen = new SshKeyGenerator.SshKeyGenerator(2048);
|
||||
|
@ -7,7 +7,11 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
<Grid MaxWidth="400" HorizontalAlignment="Center" CornerRadius="8" VerticalAlignment="Center" Background="{ThemeResource CardBackgroundFillColorSecondaryBrush}">
|
||||
<Grid MaxWidth="400"
|
||||
HorizontalAlignment="Center"
|
||||
CornerRadius="8"
|
||||
VerticalAlignment="Center"
|
||||
Background="{ThemeResource CardBackgroundFillColorDefault}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="60"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@ -18,9 +22,9 @@
|
||||
</Grid.RowDefinitions>
|
||||
<Image Grid.Row="0" Margin="20,20,20,0" Source="/Assets/StoreLogo.png" />
|
||||
<TextBlock FontSize="20" Grid.Row="1" Margin="20,5,20,0" VerticalAlignment="Center" HorizontalAlignment="Center" Text="wakka"/>
|
||||
<TextBox Width="200" Grid.Row="2" Margin="20,20,20,20" x:Name="usernameTextBox" TextChanged="OnTextChanged" PlaceholderText="Username..."/>
|
||||
<Button Width="200" Grid.Row="3" Margin="20,0,20,20" x:Name="sshKeySelectButton" Content="Select Private Key File" Click="SelectPrivateKey"/>
|
||||
<Button Width="200" Grid.Row="4" Margin="20,0,20,20" x:Name="sshKeyCreateButton" Content="Create New Key" Click="CreateSshKey"/>
|
||||
<TextBox Width="200" Grid.Row="2" Margin="20,20,20,10" x:Name="usernameTextBox" TextChanged="OnTextChanged" PlaceholderText="Username..."/>
|
||||
<Button Width="200" Grid.Row="3" Margin="20,0,20,10" x:Name="sshKeySelectButton" Content="Select Private Key File" Click="SelectPrivateKey"/>
|
||||
<Button Width="200" Grid.Row="4" Margin="20,0,20,10" x:Name="sshKeyCreateButton" Content="Create New Key" Click="CreateSshKey"/>
|
||||
<Button Width="200" Grid.Row="5" Margin="20,0,20,20" x:Name="sshConnectButton" Click="AttemptConnection" Content="Connect"/>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
@ -33,11 +33,6 @@ namespace wakka
|
||||
{
|
||||
usernameTextBox.Text = (string)App.LocalSettingsData.Values["username"];
|
||||
}
|
||||
if (Ssh.KeyExists())
|
||||
{
|
||||
sshKeySelectButton.Content = "SSH Key Set!";
|
||||
//sshKeySelectButton.Click = Sele
|
||||
}
|
||||
}
|
||||
|
||||
private async void SelectPrivateKey(object sender, RoutedEventArgs e)
|
||||
|
18
wakka.csproj
18
wakka.csproj
@ -14,6 +14,9 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="BinkPage.xaml" />
|
||||
<None Remove="FeelsFeedPage.xaml" />
|
||||
<None Remove="FeelsNavigationPage.xaml" />
|
||||
<None Remove="FeelsUserPage.xaml" />
|
||||
<None Remove="NavigationPage.xaml" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -45,6 +48,21 @@
|
||||
<PackageReference Include="SshKeyGenerator" Version="1.1.51" />
|
||||
<PackageReference Include="WinUIEx" Version="2.5.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="FeelsUserPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="FeelsFeedPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="FeelsNavigationPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="NavigationPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
Loading…
x
Reference in New Issue
Block a user