From 7c2e2a01c24627d2b05e64b1a32349b8bb256e19 Mon Sep 17 00:00:00 2001 From: Aaron Campf Date: Thu, 8 May 2014 15:58:38 -0700 Subject: [PATCH] Fixed Image Errors + Handing Bad ShellRun --- Wox/App.xaml | 4 +- Wox/App.xaml.cs | 2 +- Wox/Helper/FontHelper.cs | 4 +- Wox/MainWindow.xaml.cs | 6 ++ Wox/Msg.xaml.cs | 111 ++++++++++++------------- Wox/PluginLoader/Plugins.cs | 159 +++++++++++++++++------------------- Wox/Wox.csproj | 8 +- 7 files changed, 144 insertions(+), 150 deletions(-) diff --git a/Wox/App.xaml b/Wox/App.xaml index 4f0225e563..fe72ce333e 100644 --- a/Wox/App.xaml +++ b/Wox/App.xaml @@ -5,8 +5,8 @@ - - + + diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 478adc5b5a..57c0215e17 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -57,7 +57,7 @@ namespace Wox { // First time app is launched app = new App(); - app.InitializeComponent(); + //app.InitializeComponent(); app.Run(); return true; } diff --git a/Wox/Helper/FontHelper.cs b/Wox/Helper/FontHelper.cs index 64fe18ead1..4aa340bb61 100644 --- a/Wox/Helper/FontHelper.cs +++ b/Wox/Helper/FontHelper.cs @@ -24,7 +24,7 @@ namespace Wox.Helper static FontStyleConverter fontStyleConverter = new FontStyleConverter(); public static FontStyle GetFontStyleFromInvariantStringOrNormal(string value) - { + { try { return (FontStyle)fontStyleConverter.ConvertFromInvariantString(value); @@ -37,7 +37,7 @@ namespace Wox.Helper static FontStretchConverter fontStretchConverter = new FontStretchConverter(); public static FontStretch GetFontStretchFromInvariantStringOrNormal(string value) - { + { try { return (FontStretch)fontStretchConverter.ConvertFromInvariantString(value); diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index e903db9791..7a2f2cc676 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -455,6 +455,12 @@ namespace Wox { } public void SetTheme(string themeName) { + //Uri uri = new Uri("Themes/Default.xaml", UriKind.Relative); + //System.Windows.Resources.StreamResourceInfo info = Application.GetResourceStream(uri); + //System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader(); + + + var dict = new ResourceDictionary { Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute) }; diff --git a/Wox/Msg.xaml.cs b/Wox/Msg.xaml.cs index bf11f2f9a5..bf61c06ab1 100644 --- a/Wox/Msg.xaml.cs +++ b/Wox/Msg.xaml.cs @@ -15,70 +15,65 @@ using System.Windows.Media.Imaging; using System.Windows.Shapes; using Timer = System.Threading.Timer; -namespace Wox -{ - public partial class Msg : Window - { - Storyboard fadeOutStoryboard = new Storyboard(); - private bool closing = false; +namespace Wox { + public partial class Msg : Window { + Storyboard fadeOutStoryboard = new Storyboard(); + private bool closing = false; - public Msg() - { - InitializeComponent(); + public Msg() { + InitializeComponent(); - Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width; - Top = Screen.PrimaryScreen.Bounds.Bottom; - showAnimation.From = Screen.PrimaryScreen.Bounds.Bottom; - showAnimation.To = Screen.PrimaryScreen.WorkingArea.Bottom - Height; + Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width; + Top = Screen.PrimaryScreen.Bounds.Bottom; + showAnimation.From = Screen.PrimaryScreen.Bounds.Bottom; + showAnimation.To = Screen.PrimaryScreen.WorkingArea.Bottom - Height; - // Create the fade out storyboard - fadeOutStoryboard.Completed += new EventHandler(fadeOutStoryboard_Completed); - DoubleAnimation fadeOutAnimation = new DoubleAnimation(Screen.PrimaryScreen.WorkingArea.Bottom - Height, Screen.PrimaryScreen.Bounds.Bottom, new Duration(TimeSpan.FromSeconds(0.3))) - { - AccelerationRatio = 0.2 - }; - Storyboard.SetTarget(fadeOutAnimation, this); - Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty)); - fadeOutStoryboard.Children.Add(fadeOutAnimation); + // Create the fade out storyboard + fadeOutStoryboard.Completed += new EventHandler(fadeOutStoryboard_Completed); + DoubleAnimation fadeOutAnimation = new DoubleAnimation(Screen.PrimaryScreen.WorkingArea.Bottom - Height, Screen.PrimaryScreen.Bounds.Bottom, new Duration(TimeSpan.FromSeconds(0.3))) { + AccelerationRatio = 0.2 + }; + Storyboard.SetTarget(fadeOutAnimation, this); + Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty)); + fadeOutStoryboard.Children.Add(fadeOutAnimation); - imgClose.Source = new BitmapImage(new Uri(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\close.png"))); - imgClose.MouseUp += imgClose_MouseUp; - } - void imgClose_MouseUp(object sender, MouseButtonEventArgs e) - { - if (!closing) - { - closing = true; - fadeOutStoryboard.Begin(); - } - } + imgClose.Source = new BitmapImage(new Uri("Images\\close.pn", UriKind.Relative)); + //imgClose.Source = new BitmapImage(new Uri(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\close.png"))); + imgClose.MouseUp += imgClose_MouseUp; + } - private void fadeOutStoryboard_Completed(object sender, EventArgs e) - { - Close(); - } + void imgClose_MouseUp(object sender, MouseButtonEventArgs e) { + if (!closing) { + closing = true; + fadeOutStoryboard.Begin(); + } + } - public void Show(string title, string subTitle, string icopath) - { - tbTitle.Text = title; - tbSubTitle.Text = subTitle; - if (!File.Exists(icopath)) - { - icopath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\app.png"); - } - imgIco.Source = new BitmapImage(new Uri(icopath)); - Show(); + private void fadeOutStoryboard_Completed(object sender, EventArgs e) { + Close(); + } - Dispatcher.DelayInvoke("ShowMsg", - o => - { - if (!closing) - { - closing = true; - Dispatcher.Invoke(new Action(fadeOutStoryboard.Begin)); - } - }, TimeSpan.FromSeconds(3)); - } - } + public void Show(string title, string subTitle, string icopath) { + tbTitle.Text = title; + tbSubTitle.Text = subTitle; + if (!File.Exists(icopath)) { + //icopath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\app.png"); + imgIco.Source = new BitmapImage(new Uri("Images\\app.png", UriKind.Relative)); + } + else { + imgIco.Source = new BitmapImage(new Uri(icopath)); + } + + Show(); + + Dispatcher.DelayInvoke("ShowMsg", + o => { + if (!closing) { + closing = true; + Dispatcher.Invoke(new Action(fadeOutStoryboard.Begin)); + } + }, TimeSpan.FromSeconds(3)); + } + } } diff --git a/Wox/PluginLoader/Plugins.cs b/Wox/PluginLoader/Plugins.cs index d42335e6d2..1a295cc721 100644 --- a/Wox/PluginLoader/Plugins.cs +++ b/Wox/PluginLoader/Plugins.cs @@ -10,97 +10,90 @@ using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; -namespace Wox.PluginLoader -{ - public static class Plugins - { - private static string debuggerMode = null; - private static List plugins = new List(); - private static ManualResetEvent initializing = null; +namespace Wox.PluginLoader { + public static class Plugins { + //private static string debuggerMode = null; + public static String DebuggerMode { get; private set; } - public static void Init() - { - if (initializing != null) return; + private static List plugins = new List(); + private static ManualResetEvent initializing = null; - initializing = new ManualResetEvent(false); - plugins.Clear(); - BasePluginLoader.ParsePluginsConfig(); + public static void Init() { + if (initializing != null) return; - if (UserSettingStorage.Instance.EnablePythonPlugins) - { - plugins.AddRange(new PythonPluginLoader().LoadPlugin()); - } + initializing = new ManualResetEvent(false); + plugins.Clear(); + BasePluginLoader.ParsePluginsConfig(); - plugins.AddRange(new CSharpPluginLoader().LoadPlugin()); - Forker forker = new Forker(); - foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin)) - { - IPlugin plugin1 = plugin; - PluginPair pluginPair = plugins.FirstOrDefault(o => o.Plugin == plugin1); - if (pluginPair != null) - { - PluginMetadata metadata = pluginPair.Metadata; - pluginPair.InitContext = new PluginInitContext() - { - Plugins = plugins, - CurrentPluginMetadata = metadata, - ChangeQuery = s => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ChangeQuery(s))), - CloseApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.CloseApp())), - HideApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.HideApp())), - ShowApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowApp())), - ShowMsg = (title, subTitle, iconPath) => App.Window.Dispatcher.Invoke(new Action(() => - App.Window.ShowMsg(title, subTitle, iconPath))), - OpenSettingDialog = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.OpenSettingDialog())), - ShowCurrentResultItemTooltip = (msg) => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowCurrentResultItemTooltip(msg))), - ReloadPlugins = () => App.Window.Dispatcher.Invoke(new Action(() => Init())), - InstallPlugin = (filePath) => App.Window.Dispatcher.Invoke(new Action(() => - { - PluginInstaller.Install(filePath); - })), - StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())), - StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())), - ShellRun = (cmd) => (bool) App.Window.Dispatcher.Invoke(new Func(() => App.Window.ShellRun(cmd))), - }; - forker.Fork(() => plugin1.Init(pluginPair.InitContext)); - } - } + if (UserSettingStorage.Instance.EnablePythonPlugins) { + plugins.AddRange(new PythonPluginLoader().LoadPlugin()); + } - ThreadPool.QueueUserWorkItem(o => - { - forker.Join(); - initializing.Set(); - initializing = null; - }); - } + plugins.AddRange(new CSharpPluginLoader().LoadPlugin()); + Forker forker = new Forker(); + foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin)) { + IPlugin plugin1 = plugin; + PluginPair pluginPair = plugins.FirstOrDefault(o => o.Plugin == plugin1); + if (pluginPair != null) { + PluginMetadata metadata = pluginPair.Metadata; + pluginPair.InitContext = new PluginInitContext() { + Plugins = plugins, + CurrentPluginMetadata = metadata, + ChangeQuery = s => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ChangeQuery(s))), + CloseApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.CloseApp())), + HideApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.HideApp())), + ShowApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowApp())), + ShowMsg = (title, subTitle, iconPath) => App.Window.Dispatcher.Invoke(new Action(() => + App.Window.ShowMsg(title, subTitle, iconPath))), + OpenSettingDialog = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.OpenSettingDialog())), + ShowCurrentResultItemTooltip = (msg) => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowCurrentResultItemTooltip(msg))), + ReloadPlugins = () => App.Window.Dispatcher.Invoke(new Action(() => Init())), + InstallPlugin = (filePath) => App.Window.Dispatcher.Invoke(new Action(() => { + PluginInstaller.Install(filePath); + })), + StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())), + StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())), + //ShellRun = (cmd) => (bool)App.Window.Dispatcher.Invoke(new Func(() => App.Window.ShellRun(cmd))) + }; - public static List AllPlugins - { - get - { - var init = initializing; - if (init != null) - { - init.WaitOne(); - } - return plugins; - } - } + pluginPair.InitContext.ShellRun = (cmd) => { + try { + return (bool)App.Window.Dispatcher.Invoke(new Func(() => App.Window.ShellRun(cmd))); + } + catch (Exception) { + return false; + } + }; - public static bool HitThirdpartyKeyword(Query query) - { - if (string.IsNullOrEmpty(query.ActionName)) return false; + forker.Fork(() => plugin1.Init(pluginPair.InitContext)); + } + } - return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName); - } + ThreadPool.QueueUserWorkItem(o => { + forker.Join(); + initializing.Set(); + initializing = null; + }); + } - public static void ActivatePluginDebugger(string path) - { - debuggerMode = path; - } + public static List AllPlugins { + get { + var init = initializing; + if (init != null) { + init.WaitOne(); + } + return plugins; + } + } - public static String DebuggerMode - { - get { return debuggerMode; } - } - } + public static bool HitThirdpartyKeyword(Query query) { + if (string.IsNullOrEmpty(query.ActionName)) return false; + + return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName); + } + + public static void ActivatePluginDebugger(string path) { + DebuggerMode = path; + } + } } diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index f952240371..dd4c4e29d2 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -197,21 +197,21 @@ Designer PreserveNewest - + MSBuild:Compile Designer PreserveNewest - + MSBuild:Compile Designer PreserveNewest - + MSBuild:Compile Designer PreserveNewest - + MSBuild:Compile Designer