From b6bbd6899ee9f64740243d22ab5c9884286fd345 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Mon, 13 Jan 2014 18:43:44 +0800 Subject: [PATCH] fix issues --- WinAlfred/Commands/BaseCommand.cs | 7 ++++++- WinAlfred/Commands/Command.cs | 6 ++++++ WinAlfred/Commands/PluginCommand.cs | 4 ++-- WinAlfred/Commands/SystemCommand.cs | 4 ++-- WinAlfred/MainWindow.xaml.cs | 29 ++++++++++++++++++++++------- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/WinAlfred/Commands/BaseCommand.cs b/WinAlfred/Commands/BaseCommand.cs index fd16c8ab55..ca0a5ebe6d 100644 --- a/WinAlfred/Commands/BaseCommand.cs +++ b/WinAlfred/Commands/BaseCommand.cs @@ -10,7 +10,12 @@ namespace WinAlfred.Commands { private MainWindow window; - public abstract void Dispatch(Query query); + public void Dispatch(Query query) + { + Dispatch(query, true); + } + + public abstract void Dispatch(Query query, bool updateView); //TODO:Ugly, we should subscribe events here, instead of just use usercontrol as the parameter protected BaseCommand(MainWindow window) diff --git a/WinAlfred/Commands/Command.cs b/WinAlfred/Commands/Command.cs index 7e9af536e5..2bab900136 100644 --- a/WinAlfred/Commands/Command.cs +++ b/WinAlfred/Commands/Command.cs @@ -23,5 +23,11 @@ namespace WinAlfred.Commands systemCmd.Dispatch(query); pluginCmd.Dispatch(query); } + + public void DispatchCommand(Query query,bool updateView) + { + systemCmd.Dispatch(query,updateView); + pluginCmd.Dispatch(query,updateView); + } } } diff --git a/WinAlfred/Commands/PluginCommand.cs b/WinAlfred/Commands/PluginCommand.cs index 81f5e739d1..590e7b252c 100644 --- a/WinAlfred/Commands/PluginCommand.cs +++ b/WinAlfred/Commands/PluginCommand.cs @@ -20,7 +20,7 @@ namespace WinAlfred.Commands } - public override void Dispatch(Query q) + public override void Dispatch(Query q,bool updateView) { PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName); if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword)) @@ -39,7 +39,7 @@ namespace WinAlfred.Commands o.PluginDirectory = thirdPlugin.Metadata.PluginDirecotry; o.OriginQuery = q; }); - UpdateResultView(r); + if(updateView) UpdateResultView(r); } catch (Exception queryException) { diff --git a/WinAlfred/Commands/SystemCommand.cs b/WinAlfred/Commands/SystemCommand.cs index 7ecad98203..f1e43e2acf 100644 --- a/WinAlfred/Commands/SystemCommand.cs +++ b/WinAlfred/Commands/SystemCommand.cs @@ -18,7 +18,7 @@ namespace WinAlfred.Commands systemPlugins = Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System).ToList(); } - public override void Dispatch(Query query) + public override void Dispatch(Query query,bool updateView) { foreach (PluginPair pair in systemPlugins) { @@ -31,7 +31,7 @@ namespace WinAlfred.Commands result.PluginDirectory = pair1.Metadata.PluginDirecotry; result.OriginQuery = query; } - if(results.Count > 0) UpdateResultView(results); + if(results.Count > 0 && updateView) UpdateResultView(results); }); } } diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs index 6a627110a3..25b47c42d6 100644 --- a/WinAlfred/MainWindow.xaml.cs +++ b/WinAlfred/MainWindow.xaml.cs @@ -7,19 +7,12 @@ using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media.Animation; -using System.Windows.Shapes; -using System.Windows.Threading; -using Microsoft.Win32; using WinAlfred.Commands; using WinAlfred.Helper; using WinAlfred.Plugin; using WinAlfred.PluginLoader; -using DataFormats = System.Windows.DataFormats; -using DragDropEffects = System.Windows.DragDropEffects; -using DragEventArgs = System.Windows.DragEventArgs; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MessageBox = System.Windows.MessageBox; -using Timer = System.Threading.Timer; namespace WinAlfred { @@ -41,6 +34,28 @@ namespace WinAlfred resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent; ThreadPool.SetMaxThreads(30, 10); InitProgressbarAnimation(); + WakeupApp(); + } + + private void WakeupApp() + { + //After hide winalfred in the background for a long time. It will become very slow in the next show. + //This is caused by the Virtual Mermory Page Mechanisam. So, our solution is execute some codes in every 20min + //which may prevent sysetem uninstall memory from RAM to disk. + + System.Timers.Timer t = new System.Timers.Timer(1000 * 30 * 1) { AutoReset = true, Enabled = true }; + t.Elapsed += (o, e) => Dispatcher.Invoke(new Action(() => + { + if (Visibility != Visibility.Visible) + { + double oldLeft = Left; + Left = 20000; + ShowWinAlfred(); + cmdDispatcher.DispatchCommand(new Query("qq"),false); + HideWinAlfred(); + Left = oldLeft; + } + })); } private void InitProgressbarAnimation()