Skip to content

Commit

Permalink
Improved Desktop TrayIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 12, 2024
1 parent 7618f9f commit e530789
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 22 deletions.
10 changes: 9 additions & 1 deletion v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ProfilesViewModel : MyReactiveObject

//servers delete
public ReactiveCommand<Unit, Unit> EditServerCmd { get; }

public ReactiveCommand<Unit, Unit> RemoveServerCmd { get; }
public ReactiveCommand<Unit, Unit> RemoveDuplicateServerCmd { get; }
public ReactiveCommand<Unit, Unit> CopyServerCmd { get; }
Expand All @@ -66,19 +67,22 @@ public class ProfilesViewModel : MyReactiveObject

//servers move
public ReactiveCommand<Unit, Unit> MoveTopCmd { get; }

public ReactiveCommand<Unit, Unit> MoveUpCmd { get; }
public ReactiveCommand<Unit, Unit> MoveDownCmd { get; }
public ReactiveCommand<Unit, Unit> MoveBottomCmd { get; }

//servers ping
public ReactiveCommand<Unit, Unit> MixedTestServerCmd { get; }

public ReactiveCommand<Unit, Unit> TcpingServerCmd { get; }
public ReactiveCommand<Unit, Unit> RealPingServerCmd { get; }
public ReactiveCommand<Unit, Unit> SpeedServerCmd { get; }
public ReactiveCommand<Unit, Unit> SortServerResultCmd { get; }

//servers export
public ReactiveCommand<Unit, Unit> Export2ClientConfigCmd { get; }

public ReactiveCommand<Unit, Unit> Export2ClientConfigClipboardCmd { get; }
public ReactiveCommand<Unit, Unit> Export2ShareUrlCmd { get; }
public ReactiveCommand<Unit, Unit> Export2ShareUrlBase64Cmd { get; }
Expand All @@ -95,7 +99,11 @@ public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
_config = AppHandler.Instance.Config;
_updateView = updateView;

MessageBus.Current.Listen<string>(EMsgCommand.RefreshProfiles.ToString()).Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
if (_updateView != null)
{
MessageBus.Current.Listen<string>(EMsgCommand.RefreshProfiles.ToString())
.Subscribe(async x => await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null));
}

SelectedProfile = new();
SelectedSub = new();
Expand Down
17 changes: 17 additions & 0 deletions v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ public class StatusBarViewModel : MyReactiveObject
[Reactive]
public bool BlSystemProxyPac { get; set; }

[Reactive]
public bool BlNotSystemProxyClear { get; set; }

[Reactive]
public bool BlNotSystemProxySet { get; set; }

[Reactive]
public bool BlNotSystemProxyNothing { get; set; }

[Reactive]
public bool BlNotSystemProxyPac { get; set; }

public ReactiveCommand<Unit, Unit> SystemProxyClearCmd { get; }
public ReactiveCommand<Unit, Unit> SystemProxySetCmd { get; }
public ReactiveCommand<Unit, Unit> SystemProxyNothingCmd { get; }
Expand Down Expand Up @@ -321,6 +333,11 @@ private async Task ChangeSystemProxyAsync(ESysProxyType type, bool blChange)
BlSystemProxyNothing = (type == ESysProxyType.Unchanged);
BlSystemProxyPac = (type == ESysProxyType.Pac);

BlNotSystemProxyClear = !BlSystemProxyClear;
BlNotSystemProxySet = !BlSystemProxySet;
BlNotSystemProxyNothing = !BlSystemProxyNothing;
BlNotSystemProxyPac = !BlSystemProxyPac;

if (blChange)
{
_updateView?.Invoke(EViewAction.DispatcherRefreshIcon, null);
Expand Down
38 changes: 32 additions & 6 deletions v2rayN/v2rayN.Desktop/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,47 @@
<TrayIcon.Icons>
<TrayIcons>
<TrayIcon
Clicked="TrayIcon_Clicked"
Command="{Binding NotifyLeftClickCmd}"
Icon="/Assets/NotifyIcon1.ico"
ToolTipText="v2rayN Desktop">
ToolTipText="{Binding RunningServerToolTipText}">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Command="{Binding SystemProxyClearCmd}" Header="{x:Static resx:ResUI.menuSystemProxyClear}" />
<NativeMenuItem Command="{Binding SystemProxySetCmd}" Header="{x:Static resx:ResUI.menuSystemProxySet}" />
<NativeMenuItem Command="{Binding SystemProxyNothingCmd}" Header="{x:Static resx:ResUI.menuSystemProxyNothing}" />
<NativeMenuItem
Command="{Binding SystemProxyClearCmd}"
Header="{x:Static resx:ResUI.menuSystemProxyClear}"
IsVisible="{Binding BlNotSystemProxyClear}" />
<NativeMenuItem
Command="{Binding SystemProxyClearCmd}"
Header="{x:Static resx:ResUI.menuSystemProxyClear}"
Icon="/Assets/NotifyIcon1.ico"
IsVisible="{Binding BlSystemProxyClear}" />

<NativeMenuItem
Command="{Binding SystemProxySetCmd}"
Header="{x:Static resx:ResUI.menuSystemProxySet}"
IsVisible="{Binding BlNotSystemProxySet}" />
<NativeMenuItem
Command="{Binding SystemProxySetCmd}"
Header="{x:Static resx:ResUI.menuSystemProxySet}"
Icon="/Assets/NotifyIcon2.ico"
IsVisible="{Binding BlSystemProxySet}" />

<NativeMenuItem
Command="{Binding SystemProxyNothingCmd}"
Header="{x:Static resx:ResUI.menuSystemProxyNothing}"
IsVisible="{Binding BlNotSystemProxyNothing}" />
<NativeMenuItem
Command="{Binding SystemProxyNothingCmd}"
Header="{x:Static resx:ResUI.menuSystemProxyNothing}"
Icon="/Assets/NotifyIcon3.ico"
IsVisible="{Binding BlSystemProxyNothing}" />
<NativeMenuItemSeparator />
<NativeMenuItem Click="MenuAddServerViaClipboardClick" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
<NativeMenuItem Header="{x:Static resx:ResUI.menuAddServerViaScan}" IsVisible="False" />
<NativeMenuItem Command="{Binding SubUpdateCmd}" Header="{x:Static resx:ResUI.menuSubUpdate}" />
<NativeMenuItem Command="{Binding SubUpdateViaProxyCmd}" Header="{x:Static resx:ResUI.menuSubUpdateViaProxy}" />
<NativeMenuItemSeparator />
<NativeMenuItem Click="TrayIcon_Clicked" Header="{x:Static resx:ResUI.menuShowOrHideMainWindow}" />
<NativeMenuItem Command="{Binding NotifyLeftClickCmd}" Header="{x:Static resx:ResUI.menuShowOrHideMainWindow}" />
<NativeMenuItem Click="MenuExit_Click" Header="{x:Static resx:ResUI.menuExit}" />
</NativeMenu>
</TrayIcon.Menu>
Expand Down
15 changes: 0 additions & 15 deletions v2rayN/v2rayN.Desktop/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,6 @@ private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs e
{
}

private void TrayIcon_Clicked(object? sender, EventArgs e)
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (desktop.MainWindow.IsVisible)
{
desktop.MainWindow?.Hide();
}
else
{
desktop.MainWindow?.Show();
}
}
}

private void MenuAddServerViaClipboardClick(object? sender, EventArgs e)
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
Expand Down

0 comments on commit e530789

Please sign in to comment.