mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 18:30:34 +00:00
Display .url files as webpage (#550)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// Copyright © 2017 Paddy Xu
|
// Copyright © 2017 Paddy Xu
|
||||||
//
|
//
|
||||||
// This file is part of QuickLook program.
|
// This file is part of QuickLook program.
|
||||||
//
|
//
|
||||||
@@ -63,5 +63,25 @@ namespace QuickLook.Plugin.HtmlViewer
|
|||||||
key?.SetValue(appName, value, RegistryValueKind.DWord);
|
key?.SetValue(appName, value, RegistryValueKind.DWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string GetUrlPath(string url)
|
||||||
|
{
|
||||||
|
int index = -1;
|
||||||
|
string[] lines = File.ReadAllLines(url);
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
if (line.ToLower().Contains("url="))
|
||||||
|
{
|
||||||
|
index = System.Array.IndexOf(lines, line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
var fullLine = lines.GetValue(index);
|
||||||
|
return fullLine.ToString().Substring(fullLine.ToString().LastIndexOf('=') + 1);
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -26,7 +26,7 @@ namespace QuickLook.Plugin.HtmlViewer
|
|||||||
{
|
{
|
||||||
public class Plugin : IViewer
|
public class Plugin : IViewer
|
||||||
{
|
{
|
||||||
private static readonly string[] Extensions = { ".mht", ".mhtml", ".htm", ".html", ".svg" };
|
private static readonly string[] Extensions = { ".mht", ".mhtml", ".htm", ".html", ".svg", ".url" };
|
||||||
|
|
||||||
private WebpagePanel _panel;
|
private WebpagePanel _panel;
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ namespace QuickLook.Plugin.HtmlViewer
|
|||||||
|
|
||||||
public void Prepare(string path, ContextObject context)
|
public void Prepare(string path, ContextObject context)
|
||||||
{
|
{
|
||||||
context.PreferredSize = new Size(1000, 600);
|
context.PreferredSize = new Size(1280, 720);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void View(string path, ContextObject context)
|
public void View(string path, ContextObject context)
|
||||||
@@ -53,6 +53,10 @@ namespace QuickLook.Plugin.HtmlViewer
|
|||||||
context.ViewerContent = _panel;
|
context.ViewerContent = _panel;
|
||||||
context.Title = Path.IsPathRooted(path) ? Path.GetFileName(path) : path;
|
context.Title = Path.IsPathRooted(path) ? Path.GetFileName(path) : path;
|
||||||
|
|
||||||
|
if (path.ToLower().EndsWith(".url"))
|
||||||
|
{
|
||||||
|
path = Helper.GetUrlPath(path);
|
||||||
|
}
|
||||||
_panel.LoadFile(path);
|
_panel.LoadFile(path);
|
||||||
_panel.Dispatcher.Invoke(() => { context.IsBusy = false; }, DispatcherPriority.Loaded);
|
_panel.Dispatcher.Invoke(() => { context.IsBusy = false; }, DispatcherPriority.Loaded);
|
||||||
}
|
}
|
||||||
|
@@ -115,9 +115,10 @@ namespace QuickLook.Plugin.HtmlViewer
|
|||||||
private void InnerBrowserNavigating(object sender, NavigatingCancelEventArgs e)
|
private void InnerBrowserNavigating(object sender, NavigatingCancelEventArgs e)
|
||||||
{
|
{
|
||||||
if (_loaded)
|
if (_loaded)
|
||||||
if (_innerBrowser.Source.Scheme != e.Uri.Scheme ||
|
if (_innerBrowser.Source != null)
|
||||||
_innerBrowser.Source.AbsolutePath != e.Uri.AbsolutePath) // allow in-page navigation
|
if (_innerBrowser.Source.Scheme != e.Uri.Scheme ||
|
||||||
e.Cancel = true;
|
_innerBrowser.Source.AbsolutePath != e.Uri.AbsolutePath) // allow in-page navigation
|
||||||
|
e.Cancel = true;
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +170,7 @@ namespace QuickLook.Plugin.HtmlViewer
|
|||||||
// register script errors handler on DOM - document.window
|
// register script errors handler on DOM - document.window
|
||||||
private void RegisterWindowErrorHanlder_()
|
private void RegisterWindowErrorHanlder_()
|
||||||
{
|
{
|
||||||
object parwin = ((dynamic) _innerBrowser.Document).parentWindow;
|
object parwin = ((dynamic)_innerBrowser.Document).parentWindow;
|
||||||
var cookie = new AxHost.ConnectionPointCookie(parwin, new HtmlWindowEvents2Impl(this),
|
var cookie = new AxHost.ConnectionPointCookie(parwin, new HtmlWindowEvents2Impl(this),
|
||||||
typeof(IIntHTMLWindowEvents2));
|
typeof(IIntHTMLWindowEvents2));
|
||||||
// MemoryLEAK? No: cookie has a Finalize() to Disconnect istelf. We'll rely on that. If disconnected too early,
|
// MemoryLEAK? No: cookie has a Finalize() to Disconnect istelf. We'll rely on that. If disconnected too early,
|
||||||
@@ -185,14 +186,14 @@ namespace QuickLook.Plugin.HtmlViewer
|
|||||||
// grab a handle to the underlying ActiveX object
|
// grab a handle to the underlying ActiveX object
|
||||||
IServiceProvider serviceProvider = null;
|
IServiceProvider serviceProvider = null;
|
||||||
if (_innerBrowser.Document != null)
|
if (_innerBrowser.Document != null)
|
||||||
serviceProvider = (IServiceProvider) _innerBrowser.Document;
|
serviceProvider = (IServiceProvider)_innerBrowser.Document;
|
||||||
if (serviceProvider == null)
|
if (serviceProvider == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var serviceGuid = SidSWebBrowserApp;
|
var serviceGuid = SidSWebBrowserApp;
|
||||||
var iid = typeof(IWebBrowser2).GUID;
|
var iid = typeof(IWebBrowser2).GUID;
|
||||||
var browserInst =
|
var browserInst =
|
||||||
(IWebBrowser2) serviceProvider.QueryService(ref serviceGuid, ref iid);
|
(IWebBrowser2)serviceProvider.QueryService(ref serviceGuid, ref iid);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user