add logs view
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace clashN
|
||||
namespace clashN
|
||||
{
|
||||
class Global
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
@@ -146,6 +147,7 @@ namespace clashN.Handler
|
||||
}
|
||||
else
|
||||
{
|
||||
Locator.Current.GetService<NoticeHandler>()?.Enqueue(args.Msg);
|
||||
_updateFunc(false, args.Msg);
|
||||
}
|
||||
};
|
||||
|
||||
27
clashN/clashN/Resx/ResUI.Designer.cs
generated
27
clashN/clashN/Resx/ResUI.Designer.cs
generated
@@ -1069,6 +1069,15 @@ namespace clashN.Resx {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Filter 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbFilter {
|
||||
get {
|
||||
return ResourceManager.GetString("TbFilter", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 GlobalHotkey Setting 的本地化字符串。
|
||||
/// </summary>
|
||||
@@ -1123,6 +1132,24 @@ namespace clashN.Resx {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Max Line 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbLineCount {
|
||||
get {
|
||||
return ResourceManager.GetString("TbLineCount", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Logs 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbLogs {
|
||||
get {
|
||||
return ResourceManager.GetString("TbLogs", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Informations 的本地化字符串。
|
||||
/// </summary>
|
||||
|
||||
@@ -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>
|
||||
@@ -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
clashN/clashN/ViewModels/LogsViewModel.cs
Normal file
24
clashN/clashN/ViewModels/LogsViewModel.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ namespace clashN.ViewModels
|
||||
//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; }
|
||||
@@ -95,6 +96,7 @@ namespace clashN.ViewModels
|
||||
//GetDashboardView = new();
|
||||
GetProxyView = new();
|
||||
GetProfilesView = new();
|
||||
GetLogsView = new();
|
||||
GetConnectionsView = new();
|
||||
GetSettingsView = new();
|
||||
GetHelpView = new();
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
78
clashN/clashN/Views/LogsView.xaml
Normal file
78
clashN/clashN/Views/LogsView.xaml
Normal file
@@ -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
clashN/clashN/Views/LogsView.xaml.cs
Normal file
82
clashN/clashN/Views/LogsView.xaml.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
@@ -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>
|
||||
@@ -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">
|
||||
@@ -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>
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace clashN.Views
|
||||
//this.OneWayBind(ViewModel, vm => vm.GetDashboardView, v => v.dashboardTabItem.Content).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.GetProxyView, v => v.proxiesTabItem.Content).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.GetProfilesView, v => v.profilesTabItem.Content).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.GetLogsView, v => v.logsTabItem.Content).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.GetConnectionsView, v => v.connectionsTabItem.Content).DisposeWith(disposables);
|
||||
|
||||
this.OneWayBind(ViewModel, vm => vm.GetSettingsView, v => v.settingsTabItem.Content).DisposeWith(disposables);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<UserControl.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
|
||||
</UserControl.Resources>
|
||||
<DockPanel Grid.Row="0" Margin="16">
|
||||
<DockPanel Margin="8">
|
||||
<TextBlock
|
||||
Margin="8,0,8,8"
|
||||
DockPanel.Dock="Top"
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
materialDesign:ScrollViewerAssist.IsAutoHideEnabled="True"
|
||||
HorizontalScrollBarVisibility="Auto"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<Grid Margin="16">
|
||||
<Grid Margin="8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -36,7 +36,7 @@
|
||||
<materialDesign:Card
|
||||
Grid.Row="1"
|
||||
Width="300"
|
||||
Margin="16">
|
||||
Margin="8">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<converters:DelayColorConverter x:Key="DelayColorConverter" />
|
||||
</UserControl.Resources>
|
||||
|
||||
<DockPanel Margin="16">
|
||||
<DockPanel Margin="8">
|
||||
<TextBlock
|
||||
Margin="8,0,8,8"
|
||||
DockPanel.Dock="Top"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
d:DesignWidth="800"
|
||||
x:TypeArguments="vms:SettingsViewModel"
|
||||
mc:Ignorable="d">
|
||||
<DockPanel Grid.Row="0" Margin="16">
|
||||
<DockPanel Margin="8">
|
||||
<TextBlock
|
||||
Margin="8,0,8,8"
|
||||
DockPanel.Dock="Top"
|
||||
@@ -56,7 +56,7 @@
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<TabControl>
|
||||
<TabItem Header="{x:Static resx:ResUI.TbSettingsCore}">
|
||||
<Grid Grid.Row="1" Margin="16">
|
||||
<Grid Grid.Row="1" Margin="8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -203,7 +203,7 @@
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="{x:Static resx:ResUI.TbSettingsClashN}">
|
||||
<Grid Grid.Row="2" Margin="16">
|
||||
<Grid Grid.Row="2" Margin="8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -334,7 +334,7 @@
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="{x:Static resx:ResUI.TbSettingsSystemproxy}">
|
||||
<Grid Grid.Row="3" Margin="16">
|
||||
<Grid Grid.Row="3" Margin="8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace clashN.Views
|
||||
Global.LogLevel.ForEach(it =>
|
||||
{
|
||||
cmbLogLevel.Items.Add(it);
|
||||
});
|
||||
});
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user