mirror of https://github.com/2dust/v2rayN
Add clash display in the main interface
parent
e3c2a4b8da
commit
e963f9e349
|
@ -10,7 +10,6 @@ namespace v2rayN.Handler
|
|||
|
||||
private Dictionary<String, ProxiesItem> _proxies;
|
||||
public Dictionary<string, object> ProfileContent { get; set; }
|
||||
public bool ShowInTaskbar { get; set; } = true;
|
||||
|
||||
public void SetProxies(Dictionary<String, ProxiesItem> proxies)
|
||||
{
|
||||
|
|
|
@ -216,11 +216,12 @@ namespace v2rayN.Models
|
|||
public class ClashUIItem
|
||||
{
|
||||
public ERuleMode ruleMode { get; set; }
|
||||
public bool showInTaskbar { get; set; }
|
||||
public int proxiesSorting { get; set; }
|
||||
public bool proxiesAutoRefresh { get; set; }
|
||||
public int AutoDelayTestInterval { get; set; } = 10;
|
||||
public int proxiesAutoDelayTestInterval { get; set; } = 10;
|
||||
public int connectionsSorting { get; set; }
|
||||
public bool connectionsAutoRefresh { get; set; }
|
||||
|
||||
public int connectionsRefreshInterval { get; set; } = 2;
|
||||
}
|
||||
}
|
|
@ -36,11 +36,8 @@ namespace v2rayN.ViewModels
|
|||
[Reactive]
|
||||
public bool AutoRefresh { get; set; }
|
||||
|
||||
private int AutoRefreshInterval;
|
||||
|
||||
public ClashConnectionsViewModel()
|
||||
{
|
||||
AutoRefreshInterval = 10;
|
||||
SortingSelected = _config.clashUIItem.connectionsSorting;
|
||||
AutoRefresh = _config.clashUIItem.connectionsAutoRefresh;
|
||||
|
||||
|
@ -87,14 +84,25 @@ namespace v2rayN.ViewModels
|
|||
|
||||
private void Init()
|
||||
{
|
||||
Observable.Interval(TimeSpan.FromSeconds(AutoRefreshInterval))
|
||||
var lastTime = DateTime.Now;
|
||||
|
||||
Observable.Interval(TimeSpan.FromSeconds(10))
|
||||
.Subscribe(x =>
|
||||
{
|
||||
if (!(AutoRefresh && ClashApiHandler.Instance.ShowInTaskbar))
|
||||
if (!(AutoRefresh && _config.clashUIItem.showInTaskbar))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var dtNow = DateTime.Now;
|
||||
if (_config.clashUIItem.connectionsRefreshInterval > 0)
|
||||
{
|
||||
if ((dtNow - lastTime).Minutes % _config.clashUIItem.connectionsRefreshInterval == 0)
|
||||
{
|
||||
GetClashConnections();
|
||||
lastTime = dtNow;
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -434,8 +434,8 @@ namespace v2rayN.ViewModels
|
|||
var dicResult = JsonUtils.Deserialize<Dictionary<string, object>>(result);
|
||||
if (dicResult != null && dicResult.ContainsKey("delay"))
|
||||
{
|
||||
detail.delay = Convert.ToInt32(dicResult["delay"]);
|
||||
detail.delayName = $"{dicResult["delay"]}ms";
|
||||
detail.delay = Convert.ToInt32(dicResult["delay"].ToString());
|
||||
detail.delayName = $"{detail.delay}ms";
|
||||
}
|
||||
else if (dicResult != null && dicResult.ContainsKey("message"))
|
||||
{
|
||||
|
@ -459,23 +459,22 @@ namespace v2rayN.ViewModels
|
|||
|
||||
public void DelayTestTask()
|
||||
{
|
||||
var autoDelayTestTime = DateTime.Now;
|
||||
var lastTime = DateTime.Now;
|
||||
|
||||
Observable.Interval(TimeSpan.FromSeconds(60))
|
||||
.Subscribe(x =>
|
||||
{
|
||||
if (!(AutoRefresh && ClashApiHandler.Instance.ShowInTaskbar))
|
||||
if (!(AutoRefresh && _config.clashUIItem.showInTaskbar))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var dtNow = DateTime.Now;
|
||||
|
||||
if (_config.clashUIItem.AutoDelayTestInterval > 0)
|
||||
if (_config.clashUIItem.proxiesAutoDelayTestInterval > 0)
|
||||
{
|
||||
if ((dtNow - autoDelayTestTime).Minutes % _config.clashUIItem.AutoDelayTestInterval == 0)
|
||||
if ((dtNow - lastTime).Minutes % _config.clashUIItem.proxiesAutoDelayTestInterval == 0)
|
||||
{
|
||||
ProxiesDelayTest();
|
||||
autoDelayTestTime = dtNow;
|
||||
lastTime = dtNow;
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
|
|
@ -243,6 +243,9 @@ namespace v2rayN.ViewModels
|
|||
[Reactive]
|
||||
public string CurrentLanguage { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public bool ShowCalshUI { get; set; }
|
||||
|
||||
#endregion UI
|
||||
|
||||
#region Init
|
||||
|
@ -569,6 +572,7 @@ namespace v2rayN.ViewModels
|
|||
AutoHideStartup();
|
||||
|
||||
_showInTaskbar = true;
|
||||
_config.clashUIItem.showInTaskbar = _showInTaskbar;
|
||||
}
|
||||
|
||||
private void Init()
|
||||
|
@ -1509,7 +1513,12 @@ namespace v2rayN.ViewModels
|
|||
Application.Current?.Dispatcher.Invoke((Action)(() =>
|
||||
{
|
||||
BlReloadEnabled = true;
|
||||
ShowCalshUI = (_config.runningCoreType is ECoreType.clash or ECoreType.clash_meta or ECoreType.mihomo);
|
||||
if (ShowCalshUI) {
|
||||
Locator.Current.GetService<ClashProxiesViewModel>()?.ProxiesReload();
|
||||
}
|
||||
}));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1680,6 +1689,7 @@ namespace v2rayN.ViewModels
|
|||
//Utile.RegWriteValue(Global.MyRegPath, Utile.WindowHwndKey, Convert.ToString((long)windowHandle));
|
||||
}
|
||||
_showInTaskbar = bl;
|
||||
_config.clashUIItem.showInTaskbar = _showInTaskbar;
|
||||
}
|
||||
|
||||
private void RestoreUI()
|
||||
|
|
|
@ -13,19 +13,7 @@
|
|||
d:DesignWidth="800"
|
||||
x:TypeArguments="vms:ClashConnectionsViewModel"
|
||||
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.TbConnections}" />
|
||||
<materialDesign:Chip
|
||||
x:Name="chipCount"
|
||||
Height="20"
|
||||
IsEnabled="False"
|
||||
Style="{StaticResource ListItemChip}" />
|
||||
</StackPanel>
|
||||
<DockPanel>
|
||||
<ToolBarTray Margin="0,8,0,8" DockPanel.Dock="Top">
|
||||
<ToolBar ClipToBounds="True" Style="{StaticResource MaterialDesignToolBar}">
|
||||
<Button Width="1" Visibility="Hidden">
|
||||
|
|
|
@ -18,7 +18,6 @@ namespace v2rayN.Views
|
|||
{
|
||||
this.OneWayBind(ViewModel, vm => vm.ConnectionItems, v => v.lstConnections.ItemsSource).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstConnections.SelectedItem).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.ConnectionItems.Count, v => v.chipCount.Content).DisposeWith(disposables);
|
||||
|
||||
this.BindCommand(ViewModel, vm => vm.ConnectionCloseCmd, v => v.menuConnectionClose).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.ConnectionCloseAllCmd, v => v.menuConnectionCloseAll).DisposeWith(disposables);
|
||||
|
|
|
@ -20,13 +20,7 @@
|
|||
<converters:DelayColorConverter x:Key="DelayColorConverter" />
|
||||
</UserControl.Resources>
|
||||
|
||||
<DockPanel Margin="8">
|
||||
<TextBlock
|
||||
Margin="8,0,8,8"
|
||||
DockPanel.Dock="Top"
|
||||
Style="{StaticResource ModuleTitle}"
|
||||
Text="{x:Static resx:ResUI.TbProxies}" />
|
||||
|
||||
<DockPanel>
|
||||
<ToolBarTray DockPanel.Dock="Top">
|
||||
<ToolBar
|
||||
HorizontalAlignment="Center"
|
||||
|
|
|
@ -437,6 +437,14 @@
|
|||
materialDesign:HintAssist.Hint="{x:Static resx:ResUI.MsgServerTitle}"
|
||||
materialDesign:TextFieldAssist.HasClearButton="True"
|
||||
Style="{StaticResource DefTextBox}" />
|
||||
<Button
|
||||
x:Name="btnShowCalshUI"
|
||||
Width="30"
|
||||
Height="30"
|
||||
Margin="20,0"
|
||||
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
|
||||
<materialDesign:PackIcon VerticalAlignment="Center" Kind="EyeOutline" />
|
||||
</Button>
|
||||
</WrapPanel>
|
||||
|
||||
<materialDesign:ColorZone
|
||||
|
@ -524,9 +532,10 @@
|
|||
<RowDefinition Height="10" />
|
||||
<RowDefinition Height="1*" />
|
||||
</Grid.RowDefinitions>
|
||||
<DockPanel Grid.Row="0">
|
||||
<ContentControl x:Name="tabClashUI" DockPanel.Dock="Right" />
|
||||
<DataGrid
|
||||
x:Name="lstProfiles"
|
||||
Grid.Row="0"
|
||||
materialDesign:DataGridAssist.CellPadding="2,2"
|
||||
AutoGenerateColumns="False"
|
||||
BorderThickness="1"
|
||||
|
@ -755,6 +764,8 @@
|
|||
Header="{x:Static resx:ResUI.LvTotalDownloadDataAmount}" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</DockPanel>
|
||||
|
||||
<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" />
|
||||
<local:MsgView Grid.Row="2" />
|
||||
<materialDesign:Snackbar
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace v2rayN.Views
|
|||
this.PreviewKeyDown += MainWindow_PreviewKeyDown;
|
||||
btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;
|
||||
txtServerFilter.PreviewKeyDown += TxtServerFilter_PreviewKeyDown;
|
||||
btnShowCalshUI.Click += BtnShowCalshUI_Click;
|
||||
lstProfiles.PreviewKeyDown += LstProfiles_PreviewKeyDown;
|
||||
lstProfiles.SelectionChanged += lstProfiles_SelectionChanged;
|
||||
lstProfiles.LoadingRow += LstProfiles_LoadingRow;
|
||||
|
@ -205,6 +206,8 @@ namespace v2rayN.Views
|
|||
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.ShowCalshUI, v => v.btnShowCalshUI.Visibility).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.ShowCalshUI, v => v.tabClashUI.Visibility).DisposeWith(disposables);
|
||||
});
|
||||
|
||||
RestoreUI();
|
||||
|
@ -455,6 +458,27 @@ namespace v2rayN.Views
|
|||
}
|
||||
}
|
||||
|
||||
private bool blShowClashUI = false;
|
||||
|
||||
private void BtnShowCalshUI_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (blShowClashUI)
|
||||
{
|
||||
tabClashUI.Visibility = Visibility.Hidden;
|
||||
tabClashUI.Width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tabClashUI.Visibility = Visibility.Visible;
|
||||
if (tabClashUI.Content is null)
|
||||
{
|
||||
tabClashUI.Content = new ClashProxiesView();
|
||||
}
|
||||
tabClashUI.Width = this.ActualWidth * 5 / 6;
|
||||
}
|
||||
blShowClashUI = !blShowClashUI;
|
||||
}
|
||||
|
||||
#endregion Event
|
||||
|
||||
#region UI
|
||||
|
|
Loading…
Reference in New Issue