Skip to content

Commit e530789

Browse files
committed
Improved Desktop TrayIcon
1 parent 7618f9f commit e530789

File tree

4 files changed

+58
-22
lines changed

4 files changed

+58
-22
lines changed

v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class ProfilesViewModel : MyReactiveObject
5656

5757
//servers delete
5858
public ReactiveCommand<Unit, Unit> EditServerCmd { get; }
59+
5960
public ReactiveCommand<Unit, Unit> RemoveServerCmd { get; }
6061
public ReactiveCommand<Unit, Unit> RemoveDuplicateServerCmd { get; }
6162
public ReactiveCommand<Unit, Unit> CopyServerCmd { get; }
@@ -66,19 +67,22 @@ public class ProfilesViewModel : MyReactiveObject
6667

6768
//servers move
6869
public ReactiveCommand<Unit, Unit> MoveTopCmd { get; }
70+
6971
public ReactiveCommand<Unit, Unit> MoveUpCmd { get; }
7072
public ReactiveCommand<Unit, Unit> MoveDownCmd { get; }
7173
public ReactiveCommand<Unit, Unit> MoveBottomCmd { get; }
7274

7375
//servers ping
7476
public ReactiveCommand<Unit, Unit> MixedTestServerCmd { get; }
77+
7578
public ReactiveCommand<Unit, Unit> TcpingServerCmd { get; }
7679
public ReactiveCommand<Unit, Unit> RealPingServerCmd { get; }
7780
public ReactiveCommand<Unit, Unit> SpeedServerCmd { get; }
7881
public ReactiveCommand<Unit, Unit> SortServerResultCmd { get; }
7982

8083
//servers export
8184
public ReactiveCommand<Unit, Unit> Export2ClientConfigCmd { get; }
85+
8286
public ReactiveCommand<Unit, Unit> Export2ClientConfigClipboardCmd { get; }
8387
public ReactiveCommand<Unit, Unit> Export2ShareUrlCmd { get; }
8488
public ReactiveCommand<Unit, Unit> Export2ShareUrlBase64Cmd { get; }
@@ -95,7 +99,11 @@ public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
9599
_config = AppHandler.Instance.Config;
96100
_updateView = updateView;
97101

98-
MessageBus.Current.Listen<string>(EMsgCommand.RefreshProfiles.ToString()).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
102+
if (_updateView != null)
103+
{
104+
MessageBus.Current.Listen<string>(EMsgCommand.RefreshProfiles.ToString())
105+
.Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
106+
}
99107

100108
SelectedProfile = new();
101109
SelectedSub = new();

v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public class StatusBarViewModel : MyReactiveObject
5252
[Reactive]
5353
public bool BlSystemProxyPac { get; set; }
5454

55+
[Reactive]
56+
public bool BlNotSystemProxyClear { get; set; }
57+
58+
[Reactive]
59+
public bool BlNotSystemProxySet { get; set; }
60+
61+
[Reactive]
62+
public bool BlNotSystemProxyNothing { get; set; }
63+
64+
[Reactive]
65+
public bool BlNotSystemProxyPac { get; set; }
66+
5567
public ReactiveCommand<Unit, Unit> SystemProxyClearCmd { get; }
5668
public ReactiveCommand<Unit, Unit> SystemProxySetCmd { get; }
5769
public ReactiveCommand<Unit, Unit> SystemProxyNothingCmd { get; }
@@ -321,6 +333,11 @@ private async Task ChangeSystemProxyAsync(ESysProxyType type, bool blChange)
321333
BlSystemProxyNothing = (type == ESysProxyType.Unchanged);
322334
BlSystemProxyPac = (type == ESysProxyType.Pac);
323335

336+
BlNotSystemProxyClear = !BlSystemProxyClear;
337+
BlNotSystemProxySet = !BlSystemProxySet;
338+
BlNotSystemProxyNothing = !BlSystemProxyNothing;
339+
BlNotSystemProxyPac = !BlSystemProxyPac;
340+
324341
if (blChange)
325342
{
326343
_updateView?.Invoke(EViewAction.DispatcherRefreshIcon, null);

v2rayN/v2rayN.Desktop/App.axaml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,47 @@
2828
<TrayIcon.Icons>
2929
<TrayIcons>
3030
<TrayIcon
31-
Clicked="TrayIcon_Clicked"
31+
Command="{Binding NotifyLeftClickCmd}"
3232
Icon="/Assets/NotifyIcon1.ico"
33-
ToolTipText="v2rayN Desktop">
33+
ToolTipText="{Binding RunningServerToolTipText}">
3434
<TrayIcon.Menu>
3535
<NativeMenu>
36-
<NativeMenuItem Command="{Binding SystemProxyClearCmd}" Header="{x:Static resx:ResUI.menuSystemProxyClear}" />
37-
<NativeMenuItem Command="{Binding SystemProxySetCmd}" Header="{x:Static resx:ResUI.menuSystemProxySet}" />
38-
<NativeMenuItem Command="{Binding SystemProxyNothingCmd}" Header="{x:Static resx:ResUI.menuSystemProxyNothing}" />
36+
<NativeMenuItem
37+
Command="{Binding SystemProxyClearCmd}"
38+
Header="{x:Static resx:ResUI.menuSystemProxyClear}"
39+
IsVisible="{Binding BlNotSystemProxyClear}" />
40+
<NativeMenuItem
41+
Command="{Binding SystemProxyClearCmd}"
42+
Header="{x:Static resx:ResUI.menuSystemProxyClear}"
43+
Icon="/Assets/NotifyIcon1.ico"
44+
IsVisible="{Binding BlSystemProxyClear}" />
45+
46+
<NativeMenuItem
47+
Command="{Binding SystemProxySetCmd}"
48+
Header="{x:Static resx:ResUI.menuSystemProxySet}"
49+
IsVisible="{Binding BlNotSystemProxySet}" />
50+
<NativeMenuItem
51+
Command="{Binding SystemProxySetCmd}"
52+
Header="{x:Static resx:ResUI.menuSystemProxySet}"
53+
Icon="/Assets/NotifyIcon2.ico"
54+
IsVisible="{Binding BlSystemProxySet}" />
55+
56+
<NativeMenuItem
57+
Command="{Binding SystemProxyNothingCmd}"
58+
Header="{x:Static resx:ResUI.menuSystemProxyNothing}"
59+
IsVisible="{Binding BlNotSystemProxyNothing}" />
60+
<NativeMenuItem
61+
Command="{Binding SystemProxyNothingCmd}"
62+
Header="{x:Static resx:ResUI.menuSystemProxyNothing}"
63+
Icon="/Assets/NotifyIcon3.ico"
64+
IsVisible="{Binding BlSystemProxyNothing}" />
3965
<NativeMenuItemSeparator />
4066
<NativeMenuItem Click="MenuAddServerViaClipboardClick" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
4167
<NativeMenuItem Header="{x:Static resx:ResUI.menuAddServerViaScan}" IsVisible="False" />
4268
<NativeMenuItem Command="{Binding SubUpdateCmd}" Header="{x:Static resx:ResUI.menuSubUpdate}" />
4369
<NativeMenuItem Command="{Binding SubUpdateViaProxyCmd}" Header="{x:Static resx:ResUI.menuSubUpdateViaProxy}" />
4470
<NativeMenuItemSeparator />
45-
<NativeMenuItem Click="TrayIcon_Clicked" Header="{x:Static resx:ResUI.menuShowOrHideMainWindow}" />
71+
<NativeMenuItem Command="{Binding NotifyLeftClickCmd}" Header="{x:Static resx:ResUI.menuShowOrHideMainWindow}" />
4672
<NativeMenuItem Click="MenuExit_Click" Header="{x:Static resx:ResUI.menuExit}" />
4773
</NativeMenu>
4874
</TrayIcon.Menu>

v2rayN/v2rayN.Desktop/App.axaml.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,6 @@ private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs e
7474
{
7575
}
7676

77-
private void TrayIcon_Clicked(object? sender, EventArgs e)
78-
{
79-
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
80-
{
81-
if (desktop.MainWindow.IsVisible)
82-
{
83-
desktop.MainWindow?.Hide();
84-
}
85-
else
86-
{
87-
desktop.MainWindow?.Show();
88-
}
89-
}
90-
}
91-
9277
private void MenuAddServerViaClipboardClick(object? sender, EventArgs e)
9378
{
9479
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)

0 commit comments

Comments
 (0)