- move sound play code to animator from show

- Adjusting the delay time.
- Delete unused code.
- Process so that there is no delay when the animation settings are turned off. (Exclude erasing queries.)
This commit is contained in:
DB p 2021-11-20 18:40:21 +09:00
parent 8f1a9bfa94
commit 3c78802eae
2 changed files with 19 additions and 38 deletions

View file

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Forms;
using Flow.Launcher.Core.Plugin;
@ -243,7 +244,6 @@ namespace Flow.Launcher
{
if (_animating)
return;
_animating = true;
UpdatePosition();
Storyboard sb = new Storyboard();
@ -272,6 +272,12 @@ namespace Flow.Launcher
_settings.WindowTop = Top;
sb.Begin(FlowMainWindow);
}
if (_settings.UseSound)
{
MediaPlayer media = new MediaPlayer();
media.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
media.Play();
}
}
private void OnMouseDown(object sender, MouseButtonEventArgs e)
@ -309,7 +315,7 @@ namespace Flow.Launcher
private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e)
{
_viewModel.Hide();
await Task.Delay(100);
await Task.Delay(50);
App.API.OpenSettingDialog();
}
@ -318,7 +324,7 @@ namespace Flow.Launcher
{
// need time to initialize the main query window animation
if (_settings.UseAnimation)
await Task.Delay(100);
await Task.Delay(50);
if (_settings.HideWhenDeactive)
{
_viewModel.Hide();

View file

@ -5,7 +5,6 @@ using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using System.Windows;
using System.Windows.Media;
using System.Windows.Input;
using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Core.Resource;
@ -157,26 +156,6 @@ namespace Flow.Launcher.ViewModel
};
}
}
private void UpdateLastQUeryMode()
{
switch (_settings.LastQueryMode)
{
case LastQueryMode.Empty:
ChangeQueryText(string.Empty);
break;
case LastQueryMode.Preserved:
LastQuerySelected = true;
break;
case LastQueryMode.Selected:
LastQuerySelected = false;
break;
default:
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
}
}
private void InitializeKeyCommands()
{
EscCommand = new RelayCommand(_ =>
@ -383,7 +362,6 @@ namespace Flow.Launcher.ViewModel
public Visibility MainWindowVisibility { get; set; }
public double MainWindowOpacity { get; set; } = 1;
public bool WinToggleStatus { get; set; } = true;
public double MainWindowWidth => _settings.WindowSize;
public ICommand EscCommand { get; set; }
@ -720,45 +698,42 @@ namespace Flow.Launcher.ViewModel
Hide();
}
}
public void Show()
{
if (_settings.UseSound)
{
MediaPlayer media = new MediaPlayer();
media.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
media.Play();
}
((MainWindow)Application.Current.MainWindow).WindowAnimator();
MainWindowVisibility = Visibility.Visible;
WinToggleStatus = true;
((MainWindow)Application.Current.MainWindow).WindowAnimator();
MainWindowOpacity = 1;
}
public async void Hide()
{
MainWindowOpacity = 0;
switch (_settings.LastQueryMode)
{
case LastQueryMode.Empty:
ChangeQueryText(string.Empty);
MainWindowOpacity = 0; // Trick for no delay
await Task.Delay(100); //Time for change to opacity
await Task.Delay(50); //Time for change to opacity
break;
case LastQueryMode.Preserved:
MainWindowOpacity = 0;
await Task.Delay(100);
if (_settings.UseAnimation)
{
await Task.Delay(30);
}
LastQuerySelected = true;
break;
case LastQueryMode.Selected:
MainWindowOpacity = 0;
await Task.Delay(100);
if (_settings.UseAnimation)
{
await Task.Delay(30);
}
LastQuerySelected = false;
break;
default:
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
}
WinToggleStatus = false;
MainWindowVisibility = Visibility.Collapsed;
}