Skip to content

Commit

Permalink
Improve UI
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jul 18, 2024
1 parent bc35938 commit 70ea21f
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 108 deletions.
25 changes: 25 additions & 0 deletions v2rayN/v2rayN/Handler/MainFormHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using Splat;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using v2rayN.Enums;
using v2rayN.Handler.CoreConfig;
Expand Down Expand Up @@ -223,5 +226,27 @@ public void RegisterGlobalHotkey(Config config, Action<EGlobalHotkey> handler, A
HotkeyHandler.Instance.HotkeyTriggerEvent += handler;
HotkeyHandler.Instance.Load();
}

public void RegisterSystemColorSet(Config config, Window window, Action<bool> update)
{
var helper = new WindowInteropHelper(window);
var hwndSource = HwndSource.FromHwnd(helper.EnsureHandle());
hwndSource.AddHook((IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
{
if (config.uiItem.followSystemTheme)
{
const int WM_SETTINGCHANGE = 0x001A;
if (msg == WM_SETTINGCHANGE)
{
if (wParam == IntPtr.Zero && Marshal.PtrToStringUni(lParam) == "ImmersiveColorSet")
{
update(!Utils.IsLightTheme());
}
}
}
return IntPtr.Zero;
});
}
}
}
131 changes: 65 additions & 66 deletions v2rayN/v2rayN/Views/ClashProxiesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,72 +19,71 @@
<converters:DelayColorConverter x:Key="DelayColorConverter" />
</UserControl.Resources>

<DockPanel>
<ToolBarTray DockPanel.Dock="Top">
<ToolBar
HorizontalAlignment="Center"
<DockPanel Margin="2">
<WrapPanel
Margin="8"
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"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.menuRulemode}" />
<ComboBox
x:Name="cmbRulemode"
Width="80"
Margin="8"
Style="{StaticResource DefComboBox}">
<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
Margin="8,0"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSorting}" />
<ComboBox
x:Name="cmbSorting"
Width="60"
Margin="8"
Style="{StaticResource DefComboBox}">
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDelay}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingName}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDefault}" />
</ComboBox>

<TextBlock
Margin="8,0"
VerticalAlignment="Center"
ClipToBounds="True"
Style="{StaticResource MaterialDesignToolBar}">
<Button x:Name="menuProxiesReload">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon
Margin="0,0,8,0"
VerticalAlignment="Center"
Kind="Reload" />
<TextBlock Style="{StaticResource ToolbarTextBlock}" Text="{x:Static resx:ResUI.menuProxiesReload}" />
</StackPanel>
</Button>
<Separator />
<Button x:Name="menuProxiesDelaytest">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon
Margin="0,0,8,0"
VerticalAlignment="Center"
Kind="LightningBolt" />
<TextBlock Style="{StaticResource ToolbarTextBlock}" Text="{x:Static resx:ResUI.menuProxiesDelaytest}" />
</StackPanel>
</Button>
<Separator />
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.menuRulemode}" />
<ComboBox
x:Name="cmbRulemode"
Width="80"
Margin="8"
Style="{StaticResource DefComboBox}">
<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>
<Separator />
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSorting}" />
<ComboBox
x:Name="cmbSorting"
Width="60"
Margin="8"
Style="{StaticResource DefComboBox}">
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDelay}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingName}" />
<ComboBoxItem Content="{x:Static resx:ResUI.TbSortingDefault}" />
</ComboBox>
<Separator />
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbAutoRefresh}" />
<ToggleButton
x:Name="togAutoRefresh"
Margin="8"
HorizontalAlignment="Left" />
</ToolBar>
</ToolBarTray>
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbAutoRefresh}" />
<ToggleButton
x:Name="togAutoRefresh"
Margin="8"
HorizontalAlignment="Left" />
</WrapPanel>
<DockPanel>
<ListView
x:Name="lstProxyGroups"
Expand Down Expand Up @@ -150,7 +149,7 @@
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Border Width="200" Padding="0">
<Border Width="160" Padding="0">
<DockPanel>
<Border
Width="5"
Expand Down
3 changes: 1 addition & 2 deletions v2rayN/v2rayN/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@
x:Name="togDarkMode"
Grid.Row="0"
Grid.Column="1"
Margin="8"
IsEnabled="{Binding ElementName=followSystemTheme, Path=IsChecked, Converter={StaticResource InverseBooleanConverter}}" />
Margin="8" />

<TextBlock
Grid.Row="1"
Expand Down
40 changes: 7 additions & 33 deletions v2rayN/v2rayN/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Splat;
using System.ComponentModel;
using System.Reactive.Disposables;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -141,9 +140,6 @@ public MainWindow()
this.OneWayBind(ViewModel, vm => vm.ShowClashUI, v => v.tabClashUI.Visibility).DisposeWith(disposables);
});

RestoreUI();
AddHelpMenuItem();

var IsAdministrator = Utils.IsAdministrator();
this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";

Expand All @@ -152,36 +148,14 @@ public MainWindow()
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
}

var helper = new WindowInteropHelper(this);
var hwndSource = HwndSource.FromHwnd(helper.EnsureHandle());
hwndSource.AddHook((IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
{
if (_config.uiItem.followSystemTheme)
{
const int WM_SETTINGCHANGE = 0x001A;
if (msg == WM_SETTINGCHANGE)
{
if (wParam == IntPtr.Zero && Marshal.PtrToStringUni(lParam) == "ImmersiveColorSet")
{
ViewModel?.ModifyTheme(!Utils.IsLightTheme());
}
}
}
MainFormHandler.Instance.RegisterSystemColorSet(_config, this, (bool bl) => { ViewModel?.ModifyTheme(bl); });

return IntPtr.Zero;
});
if (tabProfiles.Content is null)
{
tabProfiles.Content = new ProfilesView();
}
if (tabMsgView.Content is null)
{
tabMsgView.Content = new MsgView();
}
if (tabClashUI.Content is null)
{
tabClashUI.Content = new ClashProxiesView();
}
tabProfiles.Content ??= new ProfilesView();
tabMsgView.Content ??= new MsgView();
tabClashUI.Content ??= new ClashProxiesView();

RestoreUI();
AddHelpMenuItem();
}

#region Event
Expand Down
29 changes: 22 additions & 7 deletions v2rayN/v2rayN/Views/MsgView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
d:DesignWidth="800"
mc:Ignorable="d">
<DockPanel Margin="2">
<StackPanel
<WrapPanel
Margin="8"
VerticalAlignment="Center"
DockPanel.Dock="Top"
Orientation="Horizontal">
<TextBlock
Margin="8,0"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.MsgInformationTitle}" />

<ComboBox
x:Name="cmbMsgFilter"
Width="200"
Expand All @@ -28,6 +25,24 @@
IsEditable="True"
Style="{StaticResource DefComboBox}"
TextBoxBase.TextChanged="cmbMsgFilter_TextChanged" />
<Button
x:Name="btnCopy"
Width="30"
Height="30"
Margin="8,0"
Click="menuMsgViewCopyAll_Click"
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
<materialDesign:PackIcon VerticalAlignment="Center" Kind="ContentCopy" />
</Button>
<Button
x:Name="btnClear"
Width="30"
Height="30"
Margin="8,0"
Click="menuMsgViewClear_Click"
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Delete" />
</Button>
<TextBlock
Margin="8,0"
VerticalAlignment="Center"
Expand All @@ -48,7 +63,7 @@
Margin="8,0"
HorizontalAlignment="Left"
IsChecked="True" />
</StackPanel>
</WrapPanel>
<TextBox
Name="txtMsg"
BorderThickness="0"
Expand Down

0 comments on commit 70ea21f

Please sign in to comment.