Skip to content

Commit 6510671

Browse files
committed
Refacotr code
Move animation and sound to MainWindow instead of MainViewModel
1 parent b487b6b commit 6510671

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 11 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 showSound = 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+
showSound.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+
showSound.Position = TimeSpan.Zero;
93+
showSound.Play();
94+
}
95+
8796
UpdatePosition();
8897
Activate();
8998
QueryTextBox.Focus();
@@ -99,6 +108,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
99108
_progressBarStoryboard.Begin(ProgressBar, true);
100109
isProgressBarStoryboardPaused = false;
101110
}
111+
if(_settings.UseAnimation)
112+
WindowAnimator();
102113
}
103114
else if (!isProgressBarStoryboardPaused)
104115
{

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -734,20 +734,10 @@ public void ToggleFlowLauncher()
734734

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

746739
MainWindowVisibilityStatus = true;
747-
748-
if(_settings.UseAnimation)
749-
((MainWindow)Application.Current.MainWindow).WindowAnimator();
750-
740+
751741
MainWindowOpacity = 1;
752742
}
753743

0 commit comments

Comments
 (0)