From fb394288dd1b8c52e7f6f53cb8a01156c164ae94 Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Sat, 3 Jun 2017 13:07:48 +0300 Subject: [PATCH] Allow plugin initialization when application starts --- .../QuickLook.Plugin.ArchiveViewer/Plugin.cs | 4 ++++ .../QuickLook.Plugin.HtmlViewer/Plugin.cs | 5 +++++ .../WebpagePanel.xaml.cs | 2 -- .../PluginInterface.cs | 4 ++++ .../QuickLook.Plugin.ImageViewer/Plugin.cs | 6 ++++++ .../QuickLook.Plugin.MarkdownViewer/Plugin.cs | 4 ++++ .../QuickLook.Plugin.PDFViewer/Plugin.cs | 4 ++++ .../QuickLook.Plugin.TextViewer/Plugin.cs | 4 ++++ .../PluginInterface.cs | 5 +++++ QuickLook/Plugin/IViewer.cs | 5 +++++ QuickLook/Plugin/InfoPanel/PluginInterface.cs | 4 ++++ QuickLook/PluginManager.cs | 14 ++++++++++++++ 12 files changed, 59 insertions(+), 2 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs index ce66728..779301c 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/Plugin.cs @@ -11,6 +11,10 @@ namespace QuickLook.Plugin.ArchiveViewer public int Priority => 0; public bool AllowsTransparency => true; + public void Init() + { + } + public bool CanHandle(string path) { if (Directory.Exists(path)) diff --git a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs index 1876273..d8f50b7 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs @@ -12,6 +12,11 @@ namespace QuickLook.Plugin.HtmlViewer public int Priority => int.MaxValue; public bool AllowsTransparency => false; + public void Init() + { + Helper.SetBrowserFeatureControl(); + } + public bool CanHandle(string path) { if (Directory.Exists(path)) diff --git a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml.cs index acadbbd..0ba4b1e 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/WebpagePanel.xaml.cs @@ -14,8 +14,6 @@ namespace QuickLook.Plugin.HtmlViewer public WebpagePanel() { InitializeComponent(); - - Helper.SetBrowserFeatureControl(); } public void Dispose() diff --git a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PluginInterface.cs b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PluginInterface.cs index 963a842..0231653 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PluginInterface.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.IPreviewHandlers/PluginInterface.cs @@ -11,6 +11,10 @@ namespace QuickLook.Plugin.IPreviewHandlers public int Priority => int.MaxValue; public bool AllowsTransparency => false; + public void Init() + { + } + public bool CanHandle(string path) { if (Directory.Exists(path)) diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs index faa9fe0..3312745 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Reflection; using System.Windows; +using ImageMagick; namespace QuickLook.Plugin.ImageViewer { @@ -23,6 +24,11 @@ namespace QuickLook.Plugin.ImageViewer public int Priority => int.MaxValue; public bool AllowsTransparency => true; + public void Init() + { + new MagickImage().Dispose(); + } + public bool CanHandle(string path) { if (Directory.Exists(path)) diff --git a/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs index 8db0618..925bfa8 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Plugin.cs @@ -13,6 +13,10 @@ namespace QuickLook.Plugin.MarkdownViewer public int Priority => int.MaxValue; public bool AllowsTransparency => false; + public void Init() + { + } + public bool CanHandle(string path) { if (Directory.Exists(path)) diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs index d3b340b..b2a64d3 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs @@ -12,6 +12,10 @@ namespace QuickLook.Plugin.PDFViewer public int Priority => int.MaxValue; public bool AllowsTransparency => true; + public void Init() + { + } + public bool CanHandle(string path) { if (Directory.Exists(path)) diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs index 7c3fd6c..b021a61 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs @@ -11,6 +11,10 @@ namespace QuickLook.Plugin.TextViewer public int Priority => 0; public bool AllowsTransparency => true; + public void Init() + { + } + public bool CanHandle(string path) { if (Directory.Exists(path)) diff --git a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/PluginInterface.cs b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/PluginInterface.cs index da09636..103b5b0 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/PluginInterface.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.VideoViewer/PluginInterface.cs @@ -13,6 +13,11 @@ namespace QuickLook.Plugin.VideoViewer public int Priority => int.MaxValue; public bool AllowsTransparency => true; + public void Init() + { + MediaElement.FFmpegPaths.RegisterFFmpeg(); + } + public bool CanHandle(string path) { if (Directory.Exists(path)) diff --git a/QuickLook/Plugin/IViewer.cs b/QuickLook/Plugin/IViewer.cs index 94277c8..d625698 100644 --- a/QuickLook/Plugin/IViewer.cs +++ b/QuickLook/Plugin/IViewer.cs @@ -16,6 +16,11 @@ /// bool AllowsTransparency { get; } + /// + /// Do ont-time job when application starts. You may extract nessessary resource here. + /// + void Init(); + /// /// Determine whether this plugin can open this file. Please also check the file header, if applicable. /// diff --git a/QuickLook/Plugin/InfoPanel/PluginInterface.cs b/QuickLook/Plugin/InfoPanel/PluginInterface.cs index 1a3fb46..1905689 100644 --- a/QuickLook/Plugin/InfoPanel/PluginInterface.cs +++ b/QuickLook/Plugin/InfoPanel/PluginInterface.cs @@ -9,6 +9,10 @@ namespace QuickLook.Plugin.InfoPanel public int Priority => int.MinValue; public bool AllowsTransparency => true; + public void Init() + { + } + public bool CanHandle(string sample) { return true; diff --git a/QuickLook/PluginManager.cs b/QuickLook/PluginManager.cs index ec1e0b8..927be62 100644 --- a/QuickLook/PluginManager.cs +++ b/QuickLook/PluginManager.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Threading.Tasks; using QuickLook.ExtensionMethods; using QuickLook.Plugin; using QuickLook.Plugin.InfoPanel; @@ -66,6 +68,18 @@ namespace QuickLook }); LoadedPlugins = LoadedPlugins.OrderByDescending(i => i.Priority).ToList(); + + LoadedPlugins.ForEach(i => + { + try + { + i.Init(); + } + catch (Exception e) + { + Debug.WriteLine(e); + } + }); } } } \ No newline at end of file