Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tray context menu everytime #316

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CollapseLauncher/XAMLs/MainApp/TrayIcon.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
ContextMenuMode="PopupMenu"
DoubleClickCommand="{x:Bind ToggleAllVisibilityInvokeCommand}"
LeftClickCommand="{x:Bind BringToForegroundInvokeCommand}"
RightClickCommand="{x:Bind UpdateContextMenuInvokeCommand}"
>
<tb:TaskbarIcon.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="MainTaskbarToggle" Command="{x:Bind ToggleMainVisibilityButtonCommand}"/>
<MenuFlyoutItem x:Name="ConsoleTaskbarToggle" Command="{x:Bind ToggleConsoleVisibilityButtonCommand}" Visibility="Collapsed"/>
<MenuFlyoutItem x:Name="ConsoleTaskbarToggle" Command="{x:Bind ToggleConsoleVisibilityButtonCommand}" IsEnabled="False"/>
<MenuFlyoutSeparator/>
<MenuFlyoutItem x:Name="CloseButton" Command="{x:Bind CloseAppCommand}"/>
</MenuFlyout>
Expand Down
28 changes: 24 additions & 4 deletions CollapseLauncher/XAMLs/MainApp/TrayIcon.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using H.NotifyIcon;
using Hi3Helper;
using Hi3Helper.Shared.Region;
using Microsoft.UI.Xaml;
using System;
using System.Runtime.InteropServices;
using static CollapseLauncher.InnerLauncherConfig;
Expand Down Expand Up @@ -59,8 +58,6 @@ public TrayIcon()
// Switch toggle text to see if its started with Start
MainTaskbarToggle.Text = (m_appMode == AppMode.StartOnTray) ? _showApp : _hideApp;
ConsoleTaskbarToggle.Text = (m_appMode == AppMode.StartOnTray) ? _showConsole : _hideConsole;
// Show visibility toggle for console if the console is enabled
if (LauncherConfig.GetAppConfigValue("EnableConsole").ToBool()) ConsoleTaskbarToggle.Visibility = Visibility.Visible;
}
#endregion

Expand Down Expand Up @@ -89,6 +86,12 @@ public TrayIcon()
[RelayCommand]
public void BringToForegroundInvoke() => BringToForeground();

/// <summary>
/// Update tray context menu
/// </summary>
[RelayCommand]
public void UpdateContextMenuInvoke() => UpdateContextMenu();

/// <summary>
/// Close app
/// </summary>
Expand Down Expand Up @@ -143,7 +146,7 @@ public void ToggleMainVisibility()
{
WindowExtensions.Show(m_window);
SetForegroundWindow(mainWindowHandle);
MainTaskbarToggle.Text = _hideConsole;
MainTaskbarToggle.Text = _hideApp;
LogWriteLine("Main window is shown!");
}
}
Expand Down Expand Up @@ -202,6 +205,23 @@ public void BringToForeground()
ShowWindow(mainWindowHandle, 9);
SetForegroundWindow(mainWindowHandle);
}

/// <summary>
/// Update tray context menu
/// </summary>
public void UpdateContextMenu()
{
// Enable visibility toggle for console if the console is enabled
if (LauncherConfig.GetAppConfigValue("EnableConsole").ToBool())
{
ConsoleTaskbarToggle.IsEnabled = true;
}
else
{
ConsoleTaskbarToggle.IsEnabled = false;
ConsoleTaskbarToggle.Text = _hideConsole;
}
}
#endregion
}
}
Loading