Skip to content

Commit 25c56f9

Browse files
committed
Display notify icon before loading plugins to tell users that Flow is loading
1 parent 2a4b4de commit 25c56f9

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

Flow.Launcher/App.xaml.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Microsoft.Extensions.DependencyInjection;
2525
using Microsoft.Extensions.Hosting;
2626
using Microsoft.VisualStudio.Threading;
27+
using NotifyIcon = System.Windows.Forms.NotifyIcon;
2728

2829
namespace Flow.Launcher
2930
{
@@ -32,6 +33,7 @@ public partial class App : IDisposable, ISingleInstanceApp
3233
#region Public Properties
3334

3435
public static IPublicAPI API { get; private set; }
36+
public static NotifyIcon NotifyIcon { get; private set; }
3537
public static bool LoadingOrExiting => _mainWindow == null || _mainWindow.CanClose;
3638

3739
#endregion
@@ -152,6 +154,20 @@ public static void Main()
152154

153155
#endregion
154156

157+
#region Notify Icon
158+
159+
private void InitializeNotifyIcon()
160+
{
161+
NotifyIcon = new NotifyIcon
162+
{
163+
Text = Constant.FlowLauncherFullName,
164+
Icon = Constant.Version == "1.0.0" ? Launcher.Properties.Resources.dev : Launcher.Properties.Resources.app,
165+
Visible = !_settings.HideNotifyIcon
166+
};
167+
}
168+
169+
#endregion
170+
155171
#region App Events
156172

157173
#pragma warning disable VSTHRD100 // Avoid async void methods
@@ -180,6 +196,9 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
180196
RegisterDispatcherUnhandledException();
181197
RegisterTaskSchedulerUnhandledException();
182198

199+
// Display notify icon before loading plugins to tell users that Flow is loading
200+
InitializeNotifyIcon();
201+
183202
var imageLoadertask = ImageLoader.InitializeAsync();
184203

185204
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
using DataObject = System.Windows.DataObject;
2828
using Key = System.Windows.Input.Key;
2929
using MouseButtons = System.Windows.Forms.MouseButtons;
30-
using NotifyIcon = System.Windows.Forms.NotifyIcon;
3130
using Screen = System.Windows.Forms.Screen;
3231

3332
namespace Flow.Launcher
@@ -47,11 +46,10 @@ public partial class MainWindow : IDisposable
4746
private readonly Settings _settings;
4847
private readonly Theme _theme;
4948

50-
// Window Notify Icon
51-
private NotifyIcon _notifyIcon;
52-
5349
// Window Context Menu
54-
private readonly ContextMenu _contextMenu = new();
50+
private static readonly ContextMenu _contextMenu = new();
51+
52+
// Window View Model
5553
private readonly MainViewModel _viewModel;
5654

5755
// Window Event: Key Event
@@ -243,7 +241,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
243241
}
244242
break;
245243
case nameof(MainViewModel.GameModeStatus):
246-
_notifyIcon.Icon = _viewModel.GameModeStatus
244+
App.NotifyIcon.Icon = _viewModel.GameModeStatus
247245
? Properties.Resources.gamemode
248246
: Properties.Resources.app;
249247
break;
@@ -256,7 +254,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
256254
switch (e.PropertyName)
257255
{
258256
case nameof(Settings.HideNotifyIcon):
259-
_notifyIcon.Visible = !_settings.HideNotifyIcon;
257+
App.NotifyIcon.Visible = !_settings.HideNotifyIcon;
260258
break;
261259
case nameof(Settings.Language):
262260
UpdateNotifyIconText();
@@ -317,7 +315,7 @@ private async void OnClosing(object sender, CancelEventArgs e)
317315
if (!CanClose)
318316
{
319317
CanClose = true;
320-
_notifyIcon.Visible = false;
318+
App.NotifyIcon.Visible = false;
321319
App.API.SaveAppAllSettings();
322320
e.Cancel = true;
323321
await ImageLoader.WaitSaveAsync();
@@ -663,14 +661,7 @@ private void SoundPlay()
663661

664662
private void InitializeNotifyIcon()
665663
{
666-
_notifyIcon = new NotifyIcon
667-
{
668-
Text = Constant.FlowLauncherFullName,
669-
Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app,
670-
Visible = !_settings.HideNotifyIcon
671-
};
672-
673-
_notifyIcon.MouseClick += (o, e) =>
664+
App.NotifyIcon.MouseClick += (o, e) =>
674665
{
675666
switch (e.Button)
676667
{
@@ -1322,7 +1313,7 @@ protected virtual void Dispose(bool disposing)
13221313
if (disposing)
13231314
{
13241315
_hwndSource?.Dispose();
1325-
_notifyIcon?.Dispose();
1316+
App.NotifyIcon?.Dispose();
13261317
animationSoundWMP?.Close();
13271318
animationSoundWPF?.Dispose();
13281319
ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;

0 commit comments

Comments
 (0)