Skip to content

Commit

Permalink
add logs view
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 8, 2022
1 parent c8a9330 commit 47a21cb
Show file tree
Hide file tree
Showing 19 changed files with 266 additions and 30 deletions.
2 changes: 1 addition & 1 deletion clashN/clashN/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
x:Key="ListItemSubTitle2"
BasedOn="{StaticResource MaterialDesignTextBlock}"
TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="9" />
<Setter Property="FontSize" Value="10" />
</Style>
<Style
x:Key="ToolbarItem"
Expand Down
4 changes: 1 addition & 3 deletions clashN/clashN/Global.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Windows.Controls;

namespace clashN
namespace clashN
{
class Global
{
Expand Down
2 changes: 2 additions & 0 deletions clashN/clashN/Handler/UpdateHandle.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using clashN.Base;
using clashN.Mode;
using clashN.Resx;
using Splat;
using System.Diagnostics;
using System.IO;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -146,6 +147,7 @@ public void CheckUpdateCore(ECoreType type, Config config, Action<bool, string>
}
else
{
Locator.Current.GetService<NoticeHandler>()?.Enqueue(args.Msg);
_updateFunc(false, args.Msg);
}
};
Expand Down
27 changes: 27 additions & 0 deletions clashN/clashN/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions clashN/clashN/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,13 @@
<data name="menuProfileQrcode" xml:space="preserve">
<value>Share Qrcode</value>
</data>
<data name="TbLogs" xml:space="preserve">
<value>Logs</value>
</data>
<data name="TbFilter" xml:space="preserve">
<value>Filter</value>
</data>
<data name="TbLineCount" xml:space="preserve">
<value>Max Line</value>
</data>
</root>
9 changes: 9 additions & 0 deletions clashN/clashN/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,13 @@
<data name="menuProfileQrcode" xml:space="preserve">
<value>分享二维码</value>
</data>
<data name="TbLogs" xml:space="preserve">
<value>日志信息</value>
</data>
<data name="TbFilter" xml:space="preserve">
<value>过滤器</value>
</data>
<data name="TbLineCount" xml:space="preserve">
<value>最大行数</value>
</data>
</root>
24 changes: 24 additions & 0 deletions clashN/clashN/ViewModels/LogsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace clashN.ViewModels
{
public class LogsViewModel : ReactiveObject
{
[Reactive]
public int SortingSelected { get; set; }
[Reactive]
public bool AutoRefresh { get; set; }
[Reactive]
public string MsgFilter { get; set; }
[Reactive]
public int LineCount { get; set; }

public LogsViewModel()
{
AutoRefresh = true;
MsgFilter = string.Empty;
LineCount = 1000;
}
}
}
2 changes: 2 additions & 0 deletions clashN/clashN/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class MainWindowViewModel : ReactiveObject
//public DashboardView GetDashboardView { get; }
public ProxiesView GetProxyView { get; }
public ProfilesView GetProfilesView { get; }
public LogsView GetLogsView { get; }
public ConnectionsView GetConnectionsView { get; }
public SettingsView GetSettingsView { get; }
public HelpView GetHelpView { get; }
Expand Down Expand Up @@ -95,6 +96,7 @@ public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue)
//GetDashboardView = new();
GetProxyView = new();
GetProfilesView = new();
GetLogsView = new();
GetConnectionsView = new();
GetSettingsView = new();
GetHelpView = new();
Expand Down
5 changes: 1 addition & 4 deletions clashN/clashN/Views/ConnectionsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
d:DesignWidth="800"
x:TypeArguments="vms:ConnectionsViewModel"
mc:Ignorable="d">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
</UserControl.Resources>
<DockPanel Margin="16">
<DockPanel Margin="8">
<StackPanel
Margin="8,0,8,8"
HorizontalAlignment="Left"
Expand Down
4 changes: 2 additions & 2 deletions clashN/clashN/Views/HelpView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
d:DesignWidth="800"
x:TypeArguments="vms:HelpViewModel"
mc:Ignorable="d">
<DockPanel Grid.Row="0" Margin="16">
<DockPanel Margin="8">
<TextBlock
Margin="8,0,8,8"
DockPanel.Dock="Top"
Style="{StaticResource ModuleTitle}"
Text="{x:Static resx:ResUI.TbHelp}" />
<ScrollViewer VerticalScrollBarVisibility="Auto">
<WrapPanel Margin="16">
<WrapPanel>
<materialDesign:Card
Width="300"
Margin="8"
Expand Down
78 changes: 78 additions & 0 deletions clashN/clashN/Views/LogsView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<reactiveui:ReactiveUserControl
x:Class="clashN.Views.LogsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:clashN.Views"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net"
xmlns:resx="clr-namespace:clashN.Resx"
xmlns:vms="clr-namespace:clashN.ViewModels"
d:DesignHeight="450"
d:DesignWidth="800"
x:TypeArguments="vms:LogsViewModel"
mc:Ignorable="d">
<DockPanel Margin="8">
<StackPanel
Margin="8,0,8,8"
HorizontalAlignment="Left"
DockPanel.Dock="Top"
Orientation="Horizontal">
<TextBlock Style="{StaticResource ModuleTitle}" Text="{x:Static resx:ResUI.TbLogs}" />
</StackPanel>
<ToolBarTray Margin="0,8,0,8" DockPanel.Dock="Top">
<ToolBar ClipToBounds="True" Style="{StaticResource MaterialDesignToolBar}">
<Button Width="1" Visibility="Hidden">
<materialDesign:PackIcon Kind="ContentSave" />
</Button>
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource ToolbarItem}"
Text="{x:Static resx:ResUI.TbFilter}" />
<TextBox
x:Name="txtFilter"
Width="200"
Margin="8" />
<Separator />
<Button x:Name="btnDelete" Click="btnDelete_Click">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Delete" />
</StackPanel>
</Button>
<Separator />
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource ToolbarItem}"
Text="{x:Static resx:ResUI.TbAutoRefresh}" />
<ToggleButton
x:Name="togAutoRefresh"
Margin="8"
HorizontalAlignment="Left" />
<Separator />
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource ToolbarItem}"
Text="{x:Static resx:ResUI.TbLineCount}" />
<ComboBox
x:Name="cmbLineCount"
Width="80"
Margin="8"
Style="{StaticResource DefComboBox}">
<ComboBoxItem Content="1000" />
<ComboBoxItem Content="2000" />
<ComboBoxItem Content="3000" />
</ComboBox>
</ToolBar>
</ToolBarTray>
<TextBox
Name="txtMsg"
BorderThickness="0"
FontSize="11"
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Visible" />
</DockPanel>

</reactiveui:ReactiveUserControl>
82 changes: 82 additions & 0 deletions clashN/clashN/Views/LogsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using clashN.ViewModels;
using ReactiveUI;
using System.Reactive.Disposables;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Threading;

namespace clashN.Views
{
/// <summary>
/// Interaction logic for LogsView.xaml
/// </summary>
public partial class LogsView
{

public LogsView()
{
InitializeComponent();
ViewModel = new LogsViewModel();

MessageBus.Current.Listen<string>("MsgView").Subscribe(x => DelegateAppendText(x));

this.WhenActivated(disposables =>
{
this.Bind(ViewModel, vm => vm.MsgFilter, v => v.txtFilter.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.LineCount, v => v.cmbLineCount.Text).DisposeWith(disposables);
});
}


void DelegateAppendText(string msg)
{
Dispatcher.BeginInvoke(new Action<string>(AppendText), DispatcherPriority.Send, msg);
}

public void AppendText(string msg)
{
if (ViewModel?.AutoRefresh == false)
{
return;
}
string? msgFilter = ViewModel?.MsgFilter;
if (!Utils.IsNullOrEmpty(msgFilter))
{
if (!Regex.IsMatch(msg, msgFilter))
{
return;
}
}

ShowMsg(msg);
}

private void ShowMsg(string msg)
{
if (txtMsg.LineCount > ViewModel?.LineCount)
{
ClearMsg();
}
this.txtMsg.AppendText(msg);
if (!msg.EndsWith(Environment.NewLine))
{
this.txtMsg.AppendText(Environment.NewLine);
}
txtMsg.ScrollToEnd();
}

public void ClearMsg()
{
Dispatcher.Invoke((Action)(() =>
{
txtMsg.Clear();
}));
}

private void btnDelete_Click(object sender, RoutedEventArgs e)
{
ClearMsg();
}
}
}
29 changes: 18 additions & 11 deletions clashN/clashN/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@
SnackbarMessageQueue="{Binding ElementName=MainSnackbar, Path=MessageQueue}"
Style="{StaticResource MaterialDesignEmbeddedDialogHost}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" MinWidth="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<TabControl Style="{StaticResource MaterialDesignNavigatilRailTabControl}">
<materialDesign:NavigationRailAssist.FloatingContent>
<StackPanel
Width="auto"
Height="auto"
Margin="16">
<Grid Width="70" Margin="0,16,0,16">
Margin="4">
<Grid Width="80" Margin="0,8,0,8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -74,7 +70,7 @@
<Button
x:Name="btnReload"
Content="{materialDesign:PackIcon Kind=Reload}"
Style="{StaticResource MaterialDesignFloatingActionButton}"
Style="{StaticResource MaterialDesignFloatingActionMiniButton}"
ToolTip="Reload profile" />
</StackPanel>
</materialDesign:NavigationRailAssist.FloatingContent>
Expand Down Expand Up @@ -128,6 +124,21 @@
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem x:Name="logsTabItem" Style="{StaticResource MyMaterialDesignNavigationRailTabItem}">
<TabItem.Header>
<StackPanel Width="auto" Height="auto">
<materialDesign:PackIcon
Width="24"
Height="24"
HorizontalAlignment="Center"
Kind="MessageTextOutline" />
<TextBlock
HorizontalAlignment="Center"
Style="{StaticResource TabItemTitle}"
Text="{x:Static resx:ResUI.TbLogs}" />
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem x:Name="connectionsTabItem" Style="{StaticResource MyMaterialDesignNavigationRailTabItem}">
<TabItem.Header>
<StackPanel Width="auto" Height="auto">
Expand Down Expand Up @@ -293,10 +304,6 @@
<materialDesign:Snackbar x:Name="MainSnackbar" MessageQueue="{materialDesign:MessageQueue}" />

</Grid>

<GridSplitter Width="10" />

<local:MsgView x:Name="viewMsg" Grid.Column="1" />
</Grid>

</materialDesign:DialogHost>
Expand Down
Loading

0 comments on commit 47a21cb

Please sign in to comment.