Refacotr code

Move animation and sound to MainWindow instead of MainViewModel
This commit is contained in:
Hongtao Zhang 2021-12-19 12:22:22 -06:00
parent b487b6b10c
commit 65106719c7
2 changed files with 12 additions and 11 deletions

View file

@ -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)
{

View file

@ -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;
}