Skip to content
Closed
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
26 changes: 26 additions & 0 deletions Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualStudio.Threading;
using NotifyIcon = System.Windows.Forms.NotifyIcon;

namespace Flow.Launcher
{
Expand All @@ -32,6 +33,7 @@
#region Public Properties

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

#endregion
Expand Down Expand Up @@ -103,9 +105,9 @@
// Initialize the public API and Settings first
try
{
API = Ioc.Default.GetRequiredService<IPublicAPI>();

Check warning on line 108 in Flow.Launcher/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Ioc` is not a recognized word. (unrecognized-spelling)
_settings.Initialize();
_mainVM = Ioc.Default.GetRequiredService<MainViewModel>();

Check warning on line 110 in Flow.Launcher/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Ioc` is not a recognized word. (unrecognized-spelling)
}
catch (Exception e)
{
Expand Down Expand Up @@ -154,6 +156,20 @@

#endregion

#region Notify Icon

private static void InitializeNotifyIcon()
{
NotifyIcon = new NotifyIcon
{
Text = Constant.FlowLauncherFullName,
Icon = Constant.Version == "1.0.0" ? Launcher.Properties.Resources.dev : Launcher.Properties.Resources.app,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to not have this hardcoded? I am wary when moving to v2.0.0+ we need to bump this dev version too.

Copy link
Member Author

@Jack251970 Jack251970 Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the original codes here. And I cannot think a better to do this. Dev branch version should be 1.0.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah ok.

I think it's more consistent if we raise this from 1.0.0 to 2.0.0. we can do this in separate PR.

Visible = !_settings.HideNotifyIcon
};
}

#endregion

#region Fail Fast

private static void ShowErrorMsgBoxAndFailFast(string message, Exception e)
Expand Down Expand Up @@ -188,7 +204,7 @@

Notification.Install();

Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();

Check warning on line 207 in Flow.Launcher/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Ioc` is not a recognized word. (unrecognized-spelling)

API.LogInfo(ClassName, "Begin Flow Launcher startup ----------------------------------------------------");
API.LogInfo(ClassName, $"Runtime info:{ErrorReporting.RuntimeInfo()}");
Expand All @@ -197,6 +213,9 @@
RegisterDispatcherUnhandledException();
RegisterTaskSchedulerUnhandledException();

// Display notify icon before loading plugins to tell users that Flow is loading
InitializeNotifyIcon();

var imageLoadertask = ImageLoader.InitializeAsync();

AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);
Expand All @@ -204,7 +223,7 @@
PluginManager.LoadPlugins(_settings.PluginSettings);

// Register ResultsUpdated event after all plugins are loaded
Ioc.Default.GetRequiredService<MainViewModel>().RegisterResultsUpdatedEvent();

Check warning on line 226 in Flow.Launcher/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Ioc` is not a recognized word. (unrecognized-spelling)

Http.Proxy = _settings.Proxy;

Expand All @@ -213,7 +232,7 @@
// Change language after all plugins are initialized because we need to update plugin title based on their api
await Ioc.Default.GetRequiredService<Internationalization>().InitializeLanguageAsync();

await imageLoadertask;

Check warning on line 235 in Flow.Launcher/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Loadertask` is not a recognized word. (unrecognized-spelling)

_mainWindow = new MainWindow();

Expand All @@ -239,7 +258,7 @@
});
}

#pragma warning restore VSTHRD100 // Avoid async void methods

Check warning on line 261 in Flow.Launcher/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`VSTHRD` is not a recognized word. (unrecognized-spelling)

/// <summary>
/// Check startup only for Release
Expand Down Expand Up @@ -370,6 +389,13 @@

if (disposing)
{
// Dispose notify icon first to prevent it from showing balloon tip after main window is closed
if (NotifyIcon != null)
{
NotifyIcon.Visible = false;
NotifyIcon.Dispose();
}

// Dispose needs to be called on the main Windows thread,
// since some resources owned by the thread need to be disposed.
_mainWindow?.Dispatcher.Invoke(_mainWindow.Dispose);
Expand Down
24 changes: 7 additions & 17 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
using DataObject = System.Windows.DataObject;
using Key = System.Windows.Input.Key;
using MouseButtons = System.Windows.Forms.MouseButtons;
using NotifyIcon = System.Windows.Forms.NotifyIcon;
using Screen = System.Windows.Forms.Screen;

namespace Flow.Launcher
Expand All @@ -47,18 +46,17 @@
private readonly Settings _settings;
private readonly Theme _theme;

// Window Notify Icon
private NotifyIcon _notifyIcon;

// Window Context Menu
private readonly ContextMenu _contextMenu = new();
private static readonly ContextMenu _contextMenu = new();

// Window View Model
private readonly MainViewModel _viewModel;

// Window Event: Key Event
private bool _isArrowKeyPressed = false;

// Window Sound Effects
private MediaPlayer animationSoundWMP;

Check warning on line 59 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`WMP` is not a recognized word. (unrecognized-spelling)
private SoundPlayer animationSoundWPF;

// Window WndProc
Expand Down Expand Up @@ -99,7 +97,7 @@

#region Window Event

#pragma warning disable VSTHRD100 // Avoid async void methods

Check warning on line 100 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`VSTHRD` is not a recognized word. (unrecognized-spelling)

private void ThemeManager_ActualApplicationThemeChanged(ModernWpf.ThemeManager sender, object args)
{
Expand All @@ -110,7 +108,7 @@
{
var handle = Win32Helper.GetWindowHandle(this, true);
_hwndSource = HwndSource.FromHwnd(handle);
_hwndSource.AddHook(WndProc);

Check warning on line 111 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Wnd` is not a recognized word. (unrecognized-spelling)
Win32Helper.HideFromAltTab(this);
Win32Helper.DisableControlBox(this);
}
Expand Down Expand Up @@ -266,7 +264,7 @@
}
break;
case nameof(MainViewModel.GameModeStatus):
_notifyIcon.Icon = _viewModel.GameModeStatus
App.NotifyIcon.Icon = _viewModel.GameModeStatus
? Properties.Resources.gamemode
: Properties.Resources.app;
break;
Expand All @@ -279,7 +277,7 @@
switch (e.PropertyName)
{
case nameof(Settings.HideNotifyIcon):
_notifyIcon.Visible = !_settings.HideNotifyIcon;
App.NotifyIcon.Visible = !_settings.HideNotifyIcon;
break;
case nameof(Settings.Language):
UpdateNotifyIconText();
Expand Down Expand Up @@ -343,7 +341,7 @@
if (!CanClose)
{
CanClose = true;
_notifyIcon.Visible = false;
App.NotifyIcon.Visible = false;
App.API.SaveAppAllSettings();
e.Cancel = true;
await ImageLoader.WaitSaveAsync();
Expand All @@ -359,7 +357,7 @@
{
try
{
_hwndSource.RemoveHook(WndProc);

Check warning on line 360 in Flow.Launcher/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Wnd` is not a recognized word. (unrecognized-spelling)
}
catch (Exception)
{
Expand Down Expand Up @@ -689,14 +687,7 @@

private void InitializeNotifyIcon()
{
_notifyIcon = new NotifyIcon
{
Text = Constant.FlowLauncherFullName,
Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app,
Visible = !_settings.HideNotifyIcon
};

_notifyIcon.MouseClick += (o, e) =>
App.NotifyIcon.MouseClick += (o, e) =>
{
switch (e.Button)
{
Expand Down Expand Up @@ -1348,7 +1339,6 @@
if (disposing)
{
_hwndSource?.Dispose();
_notifyIcon?.Dispose();
animationSoundWMP?.Close();
animationSoundWPF?.Dispose();
ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;
Expand Down
Loading