Skip to content

Commit 83a357a

Browse files
authored
Merge pull request #908 from Flow-Launcher/FixNullReferenceError
fix calling mainwindow animation after loaded
2 parents c9727ea + 58317b7 commit 83a357a

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

Flow.Launcher/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
6969
PluginManager.LoadPlugins(_settings.PluginSettings);
7070
_mainVM = new MainViewModel(_settings);
7171

72-
HotKeyMapper.Initialize(_mainVM);
73-
7472
API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet);
7573

7674
Http.API = API;
@@ -83,6 +81,8 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
8381

8482
Current.MainWindow = window;
8583
Current.MainWindow.Title = Constant.FlowLauncher;
84+
85+
HotKeyMapper.Initialize(_mainVM);
8686

8787
// happlebao todo temp fix for instance code logic
8888
// load plugin before change language, because plugin language also needs be changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
1818
using NotifyIcon = System.Windows.Forms.NotifyIcon;
1919
using Flow.Launcher.Infrastructure;
20+
using System.Windows.Media;
2021

2122
namespace Flow.Launcher
2223
{
@@ -30,6 +31,7 @@ public partial class MainWindow
3031
private NotifyIcon _notifyIcon;
3132
private ContextMenu contextMenu;
3233
private MainViewModel _viewModel;
34+
private readonly MediaPlayer animationSound = new();
3335
private bool _animating;
3436

3537
#endregion
@@ -41,6 +43,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
4143
_settings = settings;
4244
InitializeComponent();
4345
InitializePosition();
46+
animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
4447
}
4548

4649
public MainWindow()
@@ -84,6 +87,12 @@ private void OnLoaded(object sender, RoutedEventArgs _)
8487
{
8588
if (_viewModel.MainWindowVisibilityStatus)
8689
{
90+
if (_settings.UseSound)
91+
{
92+
animationSound.Position = TimeSpan.Zero;
93+
animationSound.Play();
94+
}
95+
8796
UpdatePosition();
8897
Activate();
8998
QueryTextBox.Focus();
@@ -99,6 +108,9 @@ private void OnLoaded(object sender, RoutedEventArgs _)
99108
_progressBarStoryboard.Begin(ProgressBar, true);
100109
isProgressBarStoryboardPaused = false;
101110
}
111+
112+
if(_settings.UseAnimation)
113+
WindowAnimator();
102114
}
103115
else if (!isProgressBarStoryboardPaused)
104116
{

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using System.Windows;
7-
using System.Windows.Media;
87
using System.Windows.Input;
98
using Flow.Launcher.Core.Plugin;
109
using Flow.Launcher.Core.Resource;
@@ -14,7 +13,6 @@
1413
using Flow.Launcher.Infrastructure.Storage;
1514
using Flow.Launcher.Infrastructure.UserSettings;
1615
using Flow.Launcher.Plugin;
17-
using Flow.Launcher.Plugin.SharedCommands;
1816
using Flow.Launcher.Storage;
1917
using Flow.Launcher.Infrastructure.Logger;
2018
using Microsoft.VisualStudio.Threading;
@@ -734,20 +732,10 @@ public void ToggleFlowLauncher()
734732

735733
public void Show()
736734
{
737-
if (_settings.UseSound)
738-
{
739-
MediaPlayer media = new MediaPlayer();
740-
media.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
741-
media.Play();
742-
}
743-
744735
MainWindowVisibility = Visibility.Visible;
745736

746737
MainWindowVisibilityStatus = true;
747-
748-
if(_settings.UseAnimation)
749-
((MainWindow)Application.Current.MainWindow).WindowAnimator();
750-
738+
751739
MainWindowOpacity = 1;
752740
}
753741

0 commit comments

Comments
 (0)