mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 09:49:07 +00:00
reuse plugin instances
This commit is contained in:
@@ -45,7 +45,7 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace QuickLook.Plugin.ArchiveViewer
|
||||
|
||||
~Plugin()
|
||||
{
|
||||
Dispose();
|
||||
Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
@@ -43,7 +43,7 @@ namespace QuickLook.Plugin.HtmlViewer
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace QuickLook.Plugin.HtmlViewer
|
||||
|
||||
~Plugin()
|
||||
{
|
||||
Dispose();
|
||||
Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
@@ -50,7 +50,7 @@ namespace QuickLook.Plugin.ImageViewer
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ namespace QuickLook.Plugin.MarkdownViewer
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace QuickLook.Plugin.MarkdownViewer
|
||||
|
||||
~Plugin()
|
||||
{
|
||||
Dispose();
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
private string GenerateMarkdownHtml(string path)
|
||||
|
@@ -69,7 +69,7 @@ namespace QuickLook.Plugin.OfficeViewer
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace QuickLook.Plugin.OfficeViewer
|
||||
|
||||
~PluginInterface()
|
||||
{
|
||||
Dispose();
|
||||
Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
@@ -49,7 +49,7 @@ namespace QuickLook.Plugin.PDFViewer
|
||||
};
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace QuickLook.Plugin.PDFViewer
|
||||
|
||||
~Plugin()
|
||||
{
|
||||
Dispose();
|
||||
Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
@@ -56,7 +56,7 @@ namespace QuickLook.Plugin.TextViewer
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ namespace QuickLook.Plugin.VideoViewer
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
_vp?.Dispose();
|
||||
}
|
||||
|
@@ -77,13 +77,16 @@ namespace QuickLook
|
||||
|
||||
private new void Hide()
|
||||
{
|
||||
if (App.RunningAsViewer)
|
||||
Application.Current.Shutdown();
|
||||
|
||||
container.Content = null;
|
||||
|
||||
// clean up plugin and refresh ContextObject for next use
|
||||
ContextObject.ViewerPlugin?.Dispose();
|
||||
ContextObject.ViewerPlugin?.Cleanup();
|
||||
ContextObject.Reset();
|
||||
|
||||
//GC.Collect();
|
||||
GC.Collect();
|
||||
|
||||
// revert UI changes
|
||||
ContextObject.IsBusy = true;
|
||||
|
@@ -5,6 +5,8 @@ namespace QuickLook
|
||||
{
|
||||
internal static class PidHelper
|
||||
{
|
||||
private static FileStream _pidLocker;
|
||||
|
||||
private static readonly string PidListener =
|
||||
Path.Combine(Path.GetTempPath(), "QuickLook.App.Listener.D6EC3F8DDF6B.pid");
|
||||
|
||||
@@ -35,11 +37,18 @@ namespace QuickLook
|
||||
|
||||
internal static void WritePid()
|
||||
{
|
||||
File.WriteAllText(App.RunningAsViewer ? PidViewer : PidListener, Process.GetCurrentProcess().Id.ToString());
|
||||
var pidFile = App.RunningAsViewer ? PidViewer : PidListener;
|
||||
|
||||
File.WriteAllText(pidFile, Process.GetCurrentProcess().Id.ToString());
|
||||
|
||||
_pidLocker = File.Open(pidFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
|
||||
}
|
||||
|
||||
internal static void DeletePid()
|
||||
{
|
||||
_pidLocker?.Close();
|
||||
_pidLocker = null;
|
||||
|
||||
File.Delete(App.RunningAsViewer ? PidViewer : PidListener);
|
||||
}
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ namespace QuickLook.Plugin
|
||||
|
||||
public void DisposePlugin()
|
||||
{
|
||||
ViewerPlugin?.Dispose();
|
||||
ViewerPlugin?.Cleanup();
|
||||
ViewerPlugin = null;
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,6 @@
|
||||
/// <summary>
|
||||
/// Release any unmanaged resource here.
|
||||
/// </summary>
|
||||
void Dispose();
|
||||
void Cleanup();
|
||||
}
|
||||
}
|
@@ -11,7 +11,24 @@
|
||||
<ColumnDefinition Width="150" />
|
||||
<ColumnDefinition Width="65*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="image" Grid.Column="0" Height="128" Width="128" Stretch="Fill" Margin="0,-20,0,0" />
|
||||
<Image x:Name="image" Grid.Column="0" Height="128" Width="128" Stretch="Fill" Opacity="0" Margin="0,-20,0,0">
|
||||
<Image.Style>
|
||||
<Style TargetType="{x:Type Image}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Source, ElementName=image}" Value="{x:Null}">
|
||||
<DataTrigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1"
|
||||
BeginTime="0:0:0" Duration="0:0:0.05" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.ExitActions>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Image.Style>
|
||||
</Image>
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20" />
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
@@ -25,15 +26,19 @@ namespace QuickLook.Plugin.InfoPanel
|
||||
|
||||
public void DisplayInfo(string path)
|
||||
{
|
||||
var icon =
|
||||
WindowsThumbnailProvider.GetThumbnail(path,
|
||||
(int) (128 * DpiHelper.GetCurrentDpi().HorizontalDpi / DpiHelper.DEFAULT_DPI),
|
||||
(int) (128 * DpiHelper.GetCurrentDpi().VerticalDpi / DpiHelper.DEFAULT_DPI),
|
||||
ThumbnailOptions.ScaleUp);
|
||||
Task.Run(() =>
|
||||
{
|
||||
var icon =
|
||||
WindowsThumbnailProvider.GetThumbnail(path,
|
||||
(int) (128 * DpiHelper.GetCurrentDpi().HorizontalDpi / DpiHelper.DEFAULT_DPI),
|
||||
(int) (128 * DpiHelper.GetCurrentDpi().VerticalDpi / DpiHelper.DEFAULT_DPI),
|
||||
ThumbnailOptions.ScaleUp);
|
||||
|
||||
image.Source = icon.ToBitmapSource();
|
||||
var source = icon.ToBitmapSource();
|
||||
icon.Dispose();
|
||||
|
||||
icon.Dispose();
|
||||
Dispatcher.BeginInvoke(new Action(() => image.Source = source));
|
||||
});
|
||||
|
||||
var name = Path.GetFileName(path);
|
||||
filename.Text = string.IsNullOrEmpty(name) ? path : name;
|
||||
|
@@ -3,7 +3,7 @@ using System.Windows;
|
||||
|
||||
namespace QuickLook.Plugin.InfoPanel
|
||||
{
|
||||
public class PluginInterface : IViewer, IDisposable
|
||||
public class PluginInterface : IViewer
|
||||
{
|
||||
private InfoPanel _ip;
|
||||
|
||||
@@ -31,14 +31,9 @@ namespace QuickLook.Plugin.InfoPanel
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Cleanup()
|
||||
{
|
||||
_ip.Stop = true;
|
||||
}
|
||||
|
||||
~PluginInterface()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,7 +5,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using QuickLook.ExtensionMethods;
|
||||
using QuickLook.Plugin;
|
||||
using QuickLook.Plugin.InfoPanel;
|
||||
|
||||
namespace QuickLook
|
||||
{
|
||||
@@ -18,9 +17,9 @@ namespace QuickLook
|
||||
LoadPlugins();
|
||||
}
|
||||
|
||||
internal Type DefaultPlugin { get; } = typeof(PluginInterface);
|
||||
internal IViewer DefaultPlugin { get; } = new Plugin.InfoPanel.PluginInterface();
|
||||
|
||||
internal List<Type> LoadedPlugins { get; private set; } = new List<Type>();
|
||||
internal List<IViewer> LoadedPlugins { get; private set; } = new List<IViewer>();
|
||||
|
||||
internal static PluginManager GetInstance()
|
||||
{
|
||||
@@ -38,17 +37,16 @@ namespace QuickLook
|
||||
var can = false;
|
||||
try
|
||||
{
|
||||
can = plugin.CreateInstance<IViewer>().CanHandle(path);
|
||||
can = plugin.CanHandle(path);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
return can;
|
||||
})
|
||||
?.CreateInstance<IViewer>();
|
||||
});
|
||||
|
||||
return matched ?? DefaultPlugin.CreateInstance<IViewer>();
|
||||
return matched ?? DefaultPlugin;
|
||||
}
|
||||
|
||||
private void LoadPlugins()
|
||||
@@ -63,10 +61,10 @@ namespace QuickLook
|
||||
where !t.IsInterface && !t.IsAbstract
|
||||
where typeof(IViewer).IsAssignableFrom(t)
|
||||
select t).ToList()
|
||||
.ForEach(type => LoadedPlugins.Add(type));
|
||||
.ForEach(type => LoadedPlugins.Add(type.CreateInstance<IViewer>()));
|
||||
});
|
||||
|
||||
LoadedPlugins = LoadedPlugins.OrderByDescending(i => i.CreateInstance<IViewer>().Priority).ToList();
|
||||
LoadedPlugins = LoadedPlugins.OrderByDescending(i => i.Priority).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,11 +20,6 @@ namespace QuickLook
|
||||
internal ViewWindowManager()
|
||||
{
|
||||
_viewWindow = new MainWindow();
|
||||
_viewWindow.Closed += (sender, e) =>
|
||||
{
|
||||
if (App.RunningAsViewer)
|
||||
Application.Current.Shutdown();
|
||||
};
|
||||
}
|
||||
|
||||
internal void InvokeRoutine()
|
||||
@@ -66,10 +61,10 @@ namespace QuickLook
|
||||
Debug.WriteLine(e.ToString());
|
||||
Debug.WriteLine(e.StackTrace);
|
||||
|
||||
if (matchedPlugin.GetType() != PluginManager.GetInstance().DefaultPlugin)
|
||||
if (matchedPlugin != PluginManager.GetInstance().DefaultPlugin)
|
||||
{
|
||||
matchedPlugin.Dispose();
|
||||
matchedPlugin = PluginManager.GetInstance().DefaultPlugin.CreateInstance<IViewer>();
|
||||
matchedPlugin.Cleanup();
|
||||
matchedPlugin = PluginManager.GetInstance().DefaultPlugin;
|
||||
BeginShowNewWindow(matchedPlugin, path);
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user