5
5
using Hi3Helper ;
6
6
using Hi3Helper . Shared . Region ;
7
7
using Microsoft . UI . Xaml ;
8
- using Microsoft . UI . Xaml . Controls ;
9
8
using System ;
10
9
using System . Drawing ;
10
+ using System . Threading . Tasks ;
11
11
using static CollapseLauncher . InnerLauncherConfig ;
12
12
using static CollapseLauncher . Pages . HomePage ;
13
13
using static Hi3Helper . InvokeProp ;
@@ -69,18 +69,42 @@ public TrayIcon()
69
69
#endif
70
70
CloseButton . Text = _exitApp ;
71
71
72
- // Switch toggle text to see if its started with Start
72
+ // Switch toggle text to see if it's started with Start
73
73
MainTaskbarToggle . Text = ( m_appMode == AppMode . StartOnTray ) ? _showApp : _hideApp ;
74
74
ConsoleTaskbarToggle . Text = ( m_appMode == AppMode . StartOnTray ) ? _showConsole : _hideConsole ;
75
75
76
76
CollapseTaskbar . Icon = Icon . FromHandle ( LauncherConfig . AppIconSmall ) ;
77
77
CollapseTaskbar . Visibility = Visibility . Visible ;
78
+
79
+ CollapseTaskbar . TrayIcon . MessageWindow . BalloonToolTipChanged += BalloonChangedEvent ;
78
80
}
79
81
80
82
public void Dispose ( )
81
83
{
82
84
CollapseTaskbar . Dispose ( ) ;
83
85
}
86
+
87
+ private void BalloonChangedEvent ( object o , MessageWindow . BalloonToolTipChangedEventArgs args )
88
+ {
89
+ // Subscribe to the event when the Balloon is visible, and unsub when it's not.
90
+ // Due to bug, this MouseEvent is not available when the notification already went to the tray.
91
+ if ( args . IsVisible )
92
+ CollapseTaskbar . TrayIcon . MessageWindow . MouseEventReceived += NotificationOnMouseEventReceived ;
93
+ else
94
+ CollapseTaskbar . TrayIcon . MessageWindow . MouseEventReceived -= NotificationOnMouseEventReceived ;
95
+ }
96
+
97
+ private bool _mouseEventProcessing ;
98
+ private async void NotificationOnMouseEventReceived ( object o , MessageWindow . MouseEventReceivedEventArgs args )
99
+ {
100
+ if ( _mouseEventProcessing ) return ;
101
+ if ( args . MouseEvent != MouseEvent . BalloonToolTipClicked ) return ;
102
+
103
+ _mouseEventProcessing = true ;
104
+ BringToForeground ( ) ;
105
+ await Task . Delay ( 250 ) ;
106
+ _mouseEventProcessing = false ;
107
+ }
84
108
#endregion
85
109
86
110
#region Visibility Toggler
@@ -97,7 +121,7 @@ public void Dispose()
97
121
private void ToggleConsoleVisibilityButton ( ) => ToggleConsoleVisibility ( ) ;
98
122
99
123
/// <summary>
100
- /// Toggle both main and console visibility while avoiding flip flop condition
124
+ /// Toggle both main and console visibility while avoiding flip- flop condition
101
125
/// </summary>
102
126
[ RelayCommand ]
103
127
private void ToggleAllVisibilityInvoke ( ) => ToggleAllVisibility ( ) ;
@@ -125,6 +149,7 @@ public void Dispose()
125
149
/// <summary>
126
150
/// Toggle console window visibility
127
151
/// </summary>
152
+ // ReSharper disable once MemberCanBePrivate.Global
128
153
public void ToggleConsoleVisibility ( bool forceShow = false )
129
154
{
130
155
if ( LauncherConfig . GetAppConfigValue ( "EnableConsole" ) . ToBool ( ) )
@@ -162,7 +187,7 @@ public void ToggleMainVisibility(bool forceShow = false)
162
187
// Increase refresh rate to 1000ms when main window is hidden
163
188
RefreshRate = RefreshRateSlow ;
164
189
LogWriteLine ( "Main window is hidden!" ) ;
165
- ShowNotification ( "Main window is hidden! ", "a " ) ;
190
+ WindowUtility . Tray_ShowNotification ( "test1 ", "neon stinki " ) ;
166
191
}
167
192
else
168
193
{
@@ -204,6 +229,7 @@ public void ToggleAllVisibility()
204
229
/// <summary>
205
230
/// Bring all windows into foreground, also brought all windows if they were hidden in taskbar.
206
231
/// </summary>
232
+ // ReSharper disable once MemberCanBePrivate.Global
207
233
public void BringToForeground ( )
208
234
{
209
235
IntPtr mainWindowHandle = WindowUtility . CurrentWindowPtr ;
@@ -233,6 +259,7 @@ public void BringToForeground()
233
259
/// <summary>
234
260
/// Update tray context menu
235
261
/// </summary>
262
+ // ReSharper disable once MemberCanBePrivate.Global
236
263
public void UpdateContextMenu ( )
237
264
{
238
265
// Enable visibility toggle for console if the console is enabled
@@ -253,11 +280,8 @@ public void UpdateContextMenu()
253
280
bool isMainWindowVisible = IsWindowVisible ( mainWindowHandle ) ;
254
281
bool isConsoleVisible = LauncherConfig . GetAppConfigValue ( "EnableConsole" ) . ToBool ( ) && IsWindowVisible ( consoleWindowHandle ) ;
255
282
256
- if ( isConsoleVisible ) ConsoleTaskbarToggle . Text = _hideConsole ;
257
- else ConsoleTaskbarToggle . Text = _showConsole ;
258
-
259
- if ( isMainWindowVisible ) MainTaskbarToggle . Text = _hideApp ;
260
- else MainTaskbarToggle . Text = _showApp ;
283
+ ConsoleTaskbarToggle . Text = isConsoleVisible ? _hideConsole : _showConsole ;
284
+ MainTaskbarToggle . Text = isMainWindowVisible ? _hideApp : _showApp ;
261
285
}
262
286
263
287
/// <summary>
0 commit comments