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