From 65106719c723d3664b84a7ec6e8fe02638015cf5 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sun, 19 Dec 2021 12:22:22 -0600 Subject: [PATCH] Refacotr code Move animation and sound to MainWindow instead of MainViewModel --- Flow.Launcher/MainWindow.xaml.cs | 11 +++++++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 12 +----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index cf40c5ebf..58db2083f 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -17,6 +17,7 @@ using DragEventArgs = System.Windows.DragEventArgs; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using NotifyIcon = System.Windows.Forms.NotifyIcon; using Flow.Launcher.Infrastructure; +using System.Windows.Media; namespace Flow.Launcher { @@ -30,6 +31,7 @@ namespace Flow.Launcher private NotifyIcon _notifyIcon; private ContextMenu contextMenu; private MainViewModel _viewModel; + private readonly MediaPlayer showSound = new(); private bool _animating; #endregion @@ -41,6 +43,7 @@ namespace Flow.Launcher _settings = settings; InitializeComponent(); InitializePosition(); + showSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); } public MainWindow() @@ -84,6 +87,12 @@ namespace Flow.Launcher { if (_viewModel.MainWindowVisibilityStatus) { + if (_settings.UseSound) + { + showSound.Position = TimeSpan.Zero; + showSound.Play(); + } + UpdatePosition(); Activate(); QueryTextBox.Focus(); @@ -99,6 +108,8 @@ namespace Flow.Launcher _progressBarStoryboard.Begin(ProgressBar, true); isProgressBarStoryboardPaused = false; } + if(_settings.UseAnimation) + WindowAnimator(); } else if (!isProgressBarStoryboardPaused) { diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index e97adc43d..1bb69ad69 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -734,20 +734,10 @@ namespace Flow.Launcher.ViewModel public void Show() { - if (_settings.UseSound) - { - var media = new MediaPlayer(); - media.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); - media.Play(); - } - MainWindowVisibility = Visibility.Visible; MainWindowVisibilityStatus = true; - - if(_settings.UseAnimation) - ((MainWindow)Application.Current.MainWindow).WindowAnimator(); - + MainWindowOpacity = 1; }