From 739bf2036eea976d5f17e0b1b305d356bd48ed75 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Wed, 15 Dec 2021 20:36:04 -0600 Subject: [PATCH 1/5] Delay Hotkey register & use safe way calling mainwindow animation --- Flow.Launcher/App.xaml.cs | 3 ++- Flow.Launcher/ViewModel/MainViewModel.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 9ee486b3b..1091f2f2f 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -69,7 +69,6 @@ namespace Flow.Launcher PluginManager.LoadPlugins(_settings.PluginSettings); _mainVM = new MainViewModel(_settings); - HotKeyMapper.Initialize(_mainVM); API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); @@ -79,6 +78,8 @@ namespace Flow.Launcher await PluginManager.InitializePlugins(API); var window = new MainWindow(_settings, _mainVM); + HotKeyMapper.Initialize(_mainVM); + Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); Current.MainWindow = window; diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index abf3a1d14..a86eb77e7 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -736,7 +736,7 @@ namespace Flow.Launcher.ViewModel { if (_settings.UseSound) { - MediaPlayer media = new MediaPlayer(); + var media = new MediaPlayer(); media.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); media.Play(); } @@ -746,7 +746,7 @@ namespace Flow.Launcher.ViewModel MainWindowVisibilityStatus = true; if(_settings.UseAnimation) - ((MainWindow)Application.Current.MainWindow).WindowAnimator(); + ((MainWindow)Application.Current.MainWindow)?.WindowAnimator(); MainWindowOpacity = 1; } From 04c92b05ee487fa11b9738fd81052316cef79ec3 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Wed, 15 Dec 2021 20:39:45 -0600 Subject: [PATCH 2/5] Delay till assign to Current.MainWindow --- Flow.Launcher/App.xaml.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 1091f2f2f..d397856ad 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -78,12 +78,13 @@ namespace Flow.Launcher await PluginManager.InitializePlugins(API); var window = new MainWindow(_settings, _mainVM); - HotKeyMapper.Initialize(_mainVM); Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); Current.MainWindow = window; Current.MainWindow.Title = Constant.FlowLauncher; + + HotKeyMapper.Initialize(_mainVM); // happlebao todo temp fix for instance code logic // load plugin before change language, because plugin language also needs be changed From b487b6b10cfdff450a280010800a227cec6141c4 Mon Sep 17 00:00:00 2001 From: Kevin Zhang <45326534+taooceros@users.noreply.github.com> Date: Sun, 19 Dec 2021 11:57:25 -0600 Subject: [PATCH 3/5] Update Flow.Launcher/ViewModel/MainViewModel.cs Co-authored-by: Jeremy Wu --- Flow.Launcher/ViewModel/MainViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index a86eb77e7..e97adc43d 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -746,7 +746,7 @@ namespace Flow.Launcher.ViewModel MainWindowVisibilityStatus = true; if(_settings.UseAnimation) - ((MainWindow)Application.Current.MainWindow)?.WindowAnimator(); + ((MainWindow)Application.Current.MainWindow).WindowAnimator(); MainWindowOpacity = 1; } From 65106719c723d3664b84a7ec6e8fe02638015cf5 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sun, 19 Dec 2021 12:22:22 -0600 Subject: [PATCH 4/5] 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; } From 58317b7d3f263192a3eb62721d2e78a5201ce63f Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 20 Dec 2021 20:58:50 +1100 Subject: [PATCH 5/5] rename showSound to animationSound --- Flow.Launcher/App.xaml.cs | 2 -- Flow.Launcher/MainWindow.xaml.cs | 9 +++++---- Flow.Launcher/ViewModel/MainViewModel.cs | 2 -- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index d397856ad..ea4b25f5e 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -69,7 +69,6 @@ namespace Flow.Launcher PluginManager.LoadPlugins(_settings.PluginSettings); _mainVM = new MainViewModel(_settings); - API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); Http.API = API; @@ -78,7 +77,6 @@ namespace Flow.Launcher await PluginManager.InitializePlugins(API); var window = new MainWindow(_settings, _mainVM); - Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}"); Current.MainWindow = window; diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 58db2083f..e842f6e88 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -31,7 +31,7 @@ namespace Flow.Launcher private NotifyIcon _notifyIcon; private ContextMenu contextMenu; private MainViewModel _viewModel; - private readonly MediaPlayer showSound = new(); + private readonly MediaPlayer animationSound = new(); private bool _animating; #endregion @@ -43,7 +43,7 @@ namespace Flow.Launcher _settings = settings; InitializeComponent(); InitializePosition(); - showSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); + animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); } public MainWindow() @@ -89,8 +89,8 @@ namespace Flow.Launcher { if (_settings.UseSound) { - showSound.Position = TimeSpan.Zero; - showSound.Play(); + animationSound.Position = TimeSpan.Zero; + animationSound.Play(); } UpdatePosition(); @@ -108,6 +108,7 @@ namespace Flow.Launcher _progressBarStoryboard.Begin(ProgressBar, true); isProgressBarStoryboardPaused = false; } + if(_settings.UseAnimation) WindowAnimator(); } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 1bb69ad69..95ef5d483 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows; -using System.Windows.Media; using System.Windows.Input; using Flow.Launcher.Core.Plugin; using Flow.Launcher.Core.Resource; @@ -14,7 +13,6 @@ using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; -using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Storage; using Flow.Launcher.Infrastructure.Logger; using Microsoft.VisualStudio.Threading;