Skip to content

Commit 3c78802

Browse files
committed
- 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.)
1 parent 8f1a9bf commit 3c78802

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Windows;
55
using System.Windows.Input;
66
using System.Windows.Media.Animation;
7+
using System.Windows.Media;
78
using System.Windows.Controls;
89
using System.Windows.Forms;
910
using Flow.Launcher.Core.Plugin;
@@ -243,7 +244,6 @@ public void WindowAnimator()
243244
{
244245
if (_animating)
245246
return;
246-
247247
_animating = true;
248248
UpdatePosition();
249249
Storyboard sb = new Storyboard();
@@ -272,6 +272,12 @@ public void WindowAnimator()
272272
_settings.WindowTop = Top;
273273
sb.Begin(FlowMainWindow);
274274
}
275+
if (_settings.UseSound)
276+
{
277+
MediaPlayer media = new MediaPlayer();
278+
media.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
279+
media.Play();
280+
}
275281
}
276282

277283
private void OnMouseDown(object sender, MouseButtonEventArgs e)
@@ -309,7 +315,7 @@ private void OnPreviewDragOver(object sender, DragEventArgs e)
309315
private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e)
310316
{
311317
_viewModel.Hide();
312-
await Task.Delay(100);
318+
await Task.Delay(50);
313319
App.API.OpenSettingDialog();
314320
}
315321

@@ -318,7 +324,7 @@ private async void OnDeactivated(object sender, EventArgs e)
318324
{
319325
// need time to initialize the main query window animation
320326
if (_settings.UseAnimation)
321-
await Task.Delay(100);
327+
await Task.Delay(50);
322328
if (_settings.HideWhenDeactive)
323329
{
324330
_viewModel.Hide();

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using System.Threading.Tasks.Dataflow;
77
using System.Windows;
8-
using System.Windows.Media;
98
using System.Windows.Input;
109
using Flow.Launcher.Core.Plugin;
1110
using Flow.Launcher.Core.Resource;
@@ -157,26 +156,6 @@ private void RegisterResultsUpdatedEvent()
157156
};
158157
}
159158
}
160-
161-
private void UpdateLastQUeryMode()
162-
{
163-
switch (_settings.LastQueryMode)
164-
{
165-
case LastQueryMode.Empty:
166-
ChangeQueryText(string.Empty);
167-
break;
168-
case LastQueryMode.Preserved:
169-
LastQuerySelected = true;
170-
break;
171-
case LastQueryMode.Selected:
172-
LastQuerySelected = false;
173-
break;
174-
default:
175-
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
176-
177-
}
178-
}
179-
180159
private void InitializeKeyCommands()
181160
{
182161
EscCommand = new RelayCommand(_ =>
@@ -383,7 +362,6 @@ private ResultsViewModel SelectedResults
383362
public Visibility MainWindowVisibility { get; set; }
384363
public double MainWindowOpacity { get; set; } = 1;
385364
public bool WinToggleStatus { get; set; } = true;
386-
387365
public double MainWindowWidth => _settings.WindowSize;
388366

389367
public ICommand EscCommand { get; set; }
@@ -720,45 +698,42 @@ public void ToggleFlowLauncher()
720698
Hide();
721699
}
722700
}
723-
724701
public void Show()
725702
{
726-
if (_settings.UseSound)
727-
{
728-
MediaPlayer media = new MediaPlayer();
729-
media.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
730-
media.Play();
731-
}
703+
((MainWindow)Application.Current.MainWindow).WindowAnimator();
732704
MainWindowVisibility = Visibility.Visible;
733705
WinToggleStatus = true;
734-
((MainWindow)Application.Current.MainWindow).WindowAnimator();
735706
MainWindowOpacity = 1;
736707
}
737708

738709
public async void Hide()
739710
{
740-
MainWindowOpacity = 0;
741711
switch (_settings.LastQueryMode)
742712
{
743713
case LastQueryMode.Empty:
744714
ChangeQueryText(string.Empty);
745715
MainWindowOpacity = 0; // Trick for no delay
746-
await Task.Delay(100); //Time for change to opacity
716+
await Task.Delay(50); //Time for change to opacity
747717
break;
748718
case LastQueryMode.Preserved:
749719
MainWindowOpacity = 0;
750-
await Task.Delay(100);
720+
if (_settings.UseAnimation)
721+
{
722+
await Task.Delay(30);
723+
}
751724
LastQuerySelected = true;
752725
break;
753726
case LastQueryMode.Selected:
754727
MainWindowOpacity = 0;
755-
await Task.Delay(100);
728+
if (_settings.UseAnimation)
729+
{
730+
await Task.Delay(30);
731+
}
756732
LastQuerySelected = false;
757733
break;
758734
default:
759735
throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
760736
}
761-
762737
WinToggleStatus = false;
763738
MainWindowVisibility = Visibility.Collapsed;
764739
}

0 commit comments

Comments
 (0)