Skip to content

Commit

Permalink
Improve UI
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jul 19, 2024
1 parent 70ea21f commit 5c070e2
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 85 deletions.
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Handler/Statistics/StatisticsSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private async void Run()
await Task.Delay(1000);
try
{
if (!(_config.runningCoreType is ECoreType.sing_box or ECoreType.clash or ECoreType.clash_meta or ECoreType.mihomo))
if (!(_config.IsRunningCore(ECoreType.clash)))
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Handler/Statistics/StatisticsV2ray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private async void Run()
await Task.Delay(1000);
try
{
if (!(_config.runningCoreType is ECoreType.Xray or ECoreType.v2fly or ECoreType.v2fly_v5 or ECoreType.SagerNet))
if (!(_config.IsRunningCore(ECoreType.Xray)))
{
continue;
}
Expand Down
13 changes: 13 additions & 0 deletions v2rayN/v2rayN/Models/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ public class Config

public ECoreType runningCoreType { get; set; }

public bool IsRunningCore(ECoreType type)
{
if (type == ECoreType.Xray && runningCoreType is ECoreType.Xray or ECoreType.v2fly or ECoreType.v2fly_v5 or ECoreType.SagerNet)
{
return true;
}
if (type == ECoreType.clash && runningCoreType is ECoreType.sing_box or ECoreType.clash or ECoreType.clash_meta or ECoreType.mihomo)
{
return true;
}
return false;
}

#endregion property

#region other entities
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Models/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class UIItem
public bool autoHideStartup { get; set; }
public string mainMsgFilter { get; set; }
public List<ColumnItem> mainColumnItem { get; set; }
public bool showInTaskbar { get; set; }
}

[Serializable]
Expand Down Expand Up @@ -216,7 +217,6 @@ public class HysteriaItem
public class ClashUIItem
{
public ERuleMode ruleMode { get; set; }
public bool showInTaskbar { get; set; }
public bool enableIPv6 { get; set; }
public bool enableMixinContent { get; set; }
public int proxiesSorting { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion v2rayN/v2rayN/ViewModels/ClashConnectionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reactive;
using System.Reactive.Linq;
using System.Windows;
using v2rayN.Enums;
using v2rayN.Handler;
using v2rayN.Models;

Expand Down Expand Up @@ -84,7 +85,7 @@ private void Init()
Observable.Interval(TimeSpan.FromSeconds(10))
.Subscribe(x =>
{
if (!(AutoRefresh && _config.clashUIItem.showInTaskbar))
if (!(AutoRefresh && _config.uiItem.showInTaskbar && _config.IsRunningCore(ECoreType.clash)))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/ViewModels/ClashProxiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public void DelayTestTask()
Observable.Interval(TimeSpan.FromSeconds(60))
.Subscribe(x =>
{
if (!(AutoRefresh && _config.clashUIItem.showInTaskbar))
if (!(AutoRefresh && _config.uiItem.showInTaskbar && _config.IsRunningCore(ECoreType.clash)))
{
return;
}
Expand Down
10 changes: 7 additions & 3 deletions v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public class MainWindowViewModel : ReactiveObject
[Reactive]
public bool ShowClashUI { get; set; }

[Reactive]
public int TabMainSelectedIndex { get; set; }

#endregion UI

#region Init
Expand Down Expand Up @@ -404,7 +407,7 @@ public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Action<EV
AutoHideStartup();

_showInTaskbar = true;
_config.clashUIItem.showInTaskbar = _showInTaskbar;
_config.uiItem.showInTaskbar = _showInTaskbar;
}

private void Init()
Expand Down Expand Up @@ -914,11 +917,12 @@ public void Reload()
Application.Current?.Dispatcher.Invoke((Action)(() =>
{
BlReloadEnabled = true;
ShowClashUI = (_config.runningCoreType is ECoreType.sing_box or ECoreType.clash or ECoreType.clash_meta or ECoreType.mihomo);
ShowClashUI = _config.IsRunningCore(ECoreType.clash);
if (ShowClashUI)
{
Locator.Current.GetService<ClashProxiesViewModel>()?.ProxiesReload();
}
else { TabMainSelectedIndex = 0; }
}));
});
}
Expand Down Expand Up @@ -1091,7 +1095,7 @@ public void ShowHideWindow(bool? blShow)
//Utile.RegWriteValue(Global.MyRegPath, Utile.WindowHwndKey, Convert.ToString((long)windowHandle));
}
_showInTaskbar = bl;
_config.clashUIItem.showInTaskbar = _showInTaskbar;
_config.uiItem.showInTaskbar = _showInTaskbar;
}

private void RestoreUI()
Expand Down
1 change: 0 additions & 1 deletion v2rayN/v2rayN/ViewModels/ProfilesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ public ProfilesViewModel(Action<EViewAction> updateView)
}, canEditRemove);

//Subscription

AddSubCmd = ReactiveCommand.Create(() =>
{
EditSub(true);
Expand Down
104 changes: 52 additions & 52 deletions v2rayN/v2rayN/Views/ClashConnectionsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,52 @@
d:DesignWidth="800"
x:TypeArguments="vms:ClashConnectionsViewModel"
mc:Ignorable="d">
<DockPanel>
<ToolBarTray Margin="0,8,0,8" DockPanel.Dock="Top">
<ToolBar ClipToBounds="True" Style="{StaticResource MaterialDesignToolBar}">
<Button Width="1" Visibility="Hidden">
<materialDesign:PackIcon
Margin="0,0,8,0"
VerticalAlignment="Center"
Kind="ContentSave" />
</Button>
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSorting}" />
<ComboBox
x:Name="cmbSorting"
Width="100"
Margin="8"
Style="{StaticResource DefComboBox}">
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingUpSpeed}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDownSpeed}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingUpTraffic}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDownTraffic}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingTime}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingHost}" />
</ComboBox>
<Separator />
<Button x:Name="btnConnectionCloseAll" ToolTip="{x:Static resx:ResUI.menuConnectionCloseAll}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon
Margin="0,0,8,0"
VerticalAlignment="Center"
Kind="Close" />
<TextBlock Style="{StaticResource ToolbarTextBlock}" Text="{x:Static resx:ResUI.menuConnectionCloseAll}" />
</StackPanel>
</Button>
<Separator />
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbAutoRefresh}" />
<ToggleButton
x:Name="togAutoRefresh"
Margin="8"
HorizontalAlignment="Left" />
</ToolBar>
</ToolBarTray>

<DockPanel Margin="2">
<WrapPanel
Margin="8"
VerticalAlignment="Center"
DockPanel.Dock="Top"
Orientation="Horizontal">

<TextBlock
Margin="8,0"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSorting}" />
<ComboBox
x:Name="cmbSorting"
Width="100"
Margin="8"
Style="{StaticResource DefComboBox}">
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingUpSpeed}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDownSpeed}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingUpTraffic}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDownTraffic}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingTime}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingHost}" />
</ComboBox>

<Button
x:Name="btnConnectionCloseAll"
Width="30"
Height="30"
Margin="8,0"
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Close" />
</Button>

<TextBlock
Margin="8,0"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbAutoRefresh}" />
<ToggleButton
x:Name="togAutoRefresh"
Margin="8"
HorizontalAlignment="Left" />
</WrapPanel>

<DataGrid
x:Name="lstConnections"
AutoGenerateColumns="False"
Expand All @@ -79,21 +79,21 @@
</DataGrid.ContextMenu>
<DataGrid.Columns>
<DataGridTextColumn
Width="300"
Width="240"
Binding="{Binding host}"
Header="{x:Static resx:ResUI.TbSortingHost}" />
<DataGridTextColumn
Width="100"
Width="160"
Binding="{Binding chain}"
Header="{x:Static resx:ResUI.TbSortingChain}" />
<DataGridTextColumn
Width="80"
Binding="{Binding network}"
Header="{x:Static resx:ResUI.TbSortingNetwork}" />
<DataGridTextColumn
Width="100"
Binding="{Binding type}"
Header="{x:Static resx:ResUI.TbSortingType}" />
<DataGridTextColumn
Width="200"
Binding="{Binding chain}"
Header="{x:Static resx:ResUI.TbSortingChain}" />
<DataGridTextColumn
Width="100"
Binding="{Binding uploadTraffic}"
Expand Down
36 changes: 18 additions & 18 deletions v2rayN/v2rayN/Views/ClashProxiesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@
VerticalAlignment="Center"
DockPanel.Dock="Top"
Orientation="Horizontal">
<Button
x:Name="menuProxiesReload"
Width="30"
Height="30"
Margin="8,0"
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Reload" />
</Button>

<Button
x:Name="menuProxiesDelaytest"
Width="30"
Height="30"
Margin="8,0"
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
<materialDesign:PackIcon VerticalAlignment="Center" Kind="LightningBolt" />
</Button>

<TextBlock
Margin="8,0"
Expand All @@ -56,7 +39,6 @@
<ComboBoxItem Content="{x:Static resx:ResUI.menuModeRule}" />
<ComboBoxItem Content="{x:Static resx:ResUI.menuModeGlobal}" />
<ComboBoxItem Content="{x:Static resx:ResUI.menuModeDirect}" />
<ComboBoxItem Content="{x:Static resx:ResUI.menuModeNothing}" />
</ComboBox>

<TextBlock
Expand All @@ -74,6 +56,24 @@
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDefault}" />
</ComboBox>

<Button
x:Name="menuProxiesReload"
Width="30"
Height="30"
Margin="8,0"
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Reload" />
</Button>

<Button
x:Name="menuProxiesDelaytest"
Width="30"
Height="30"
Margin="8,0"
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
<materialDesign:PackIcon VerticalAlignment="Center" Kind="LightningBolt" />
</Button>

<TextBlock
Margin="8,0"
VerticalAlignment="Center"
Expand Down
10 changes: 6 additions & 4 deletions v2rayN/v2rayN/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
x:Class="v2rayN.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:v2rayN.Base"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:v2rayN.Views"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net"
Expand Down Expand Up @@ -476,9 +474,13 @@
</Grid.ColumnDefinitions>
<ContentControl x:Name="tabProfiles" Grid.Column="0" />
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" />
<TabControl Grid.Column="2" HorizontalContentAlignment="Left">
<TabControl
x:Name="tabMain"
Grid.Column="2"
HorizontalContentAlignment="Left">
<TabItem x:Name="tabMsgView" Header="{x:Static resx:ResUI.MsgInformationTitle}" />
<TabItem x:Name="tabClashUI" Header="{x:Static resx:ResUI.TbProxies}" />
<TabItem x:Name="tabClashProxies" Header="{x:Static resx:ResUI.TbProxies}" />
<TabItem x:Name="tabClashConnections" Header="{x:Static resx:ResUI.TbConnections}" />
</TabControl>

<materialDesign:Snackbar
Expand Down
7 changes: 5 additions & 2 deletions v2rayN/v2rayN/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public MainWindow()
this.Bind(ViewModel, vm => vm.SelectedSwatch, v => v.cmbSwatches.SelectedItem).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.CurrentFontSize, v => v.cmbCurrentFontSize.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.CurrentLanguage, v => v.cmbCurrentLanguage.Text).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.ShowClashUI, v => v.tabClashUI.Visibility).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.ShowClashUI, v => v.tabClashProxies.Visibility).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.ShowClashUI, v => v.tabClashConnections.Visibility).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TabMainSelectedIndex, v => v.tabMain.SelectedIndex).DisposeWith(disposables);
});

var IsAdministrator = Utils.IsAdministrator();
Expand All @@ -152,7 +154,8 @@ public MainWindow()

tabProfiles.Content ??= new ProfilesView();
tabMsgView.Content ??= new MsgView();
tabClashUI.Content ??= new ClashProxiesView();
tabClashProxies.Content ??= new ClashProxiesView();
tabClashConnections.Content ??= new ClashConnectionsView();

RestoreUI();
AddHelpMenuItem();
Expand Down

0 comments on commit 5c070e2

Please sign in to comment.