forked from QL-Win/QuickLook
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Edge WebView2 as an alternative.
WebView2 is the default. To use old set useOldViewer to true in config file. WebView2 will also preview svg, txt and pdf files.
- Loading branch information
Showing
5 changed files
with
196 additions
and
3 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/BrowserPanel.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<UserControl x:Class="QuickLook.Plugin.HtmlViewer.BrowserPanel" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf" | ||
xmlns:local="clr-namespace:QuickLook.Plugin.HtmlViewer" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
<UserControl.Resources> | ||
<wv2:CoreWebView2CreationProperties x:Key="EvergreenWebView2CreationProperties" /> | ||
</UserControl.Resources> | ||
<wv2:WebView2 | ||
x:Name="webView" | ||
CreationProperties="{StaticResource EvergreenWebView2CreationProperties}" | ||
NavigationStarting="NavigationStarting" | ||
/> | ||
</UserControl> |
59 changes: 59 additions & 0 deletions
59
QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/BrowserPanel.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Microsoft.Web.WebView2.Core; | ||
using System; | ||
using System.IO; | ||
using System.Windows.Controls; | ||
|
||
namespace QuickLook.Plugin.HtmlViewer | ||
{ | ||
/// <summary> | ||
/// Interaction logic for BrowserPanel.xaml | ||
/// </summary> | ||
public partial class BrowserPanel : UserControl | ||
{ | ||
private Uri _currentUri; | ||
|
||
public BrowserPanel() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public void LoadFile(string path) | ||
{ | ||
if (Path.IsPathRooted(path)) | ||
path = Helper.FilePathToFileUrl(path); | ||
|
||
Navigate(path); | ||
} | ||
|
||
public void Navigate(string uri) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(uri) && Uri.IsWellFormedUriString(uri, UriKind.Absolute)) | ||
try | ||
{ | ||
webView.Source = new Uri(uri); | ||
} | ||
catch (UriFormatException) | ||
{ | ||
// just don't crash because of a malformed url | ||
} | ||
else | ||
webView.Source = null; | ||
|
||
_currentUri = webView.Source; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
webView.Dispose(); | ||
} | ||
|
||
void NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e) | ||
{ | ||
var newUri = new Uri(e.Uri); | ||
if (newUri != _currentUri) | ||
{ | ||
e.Cancel = true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.Web.WebView2" version="1.0.664.37" targetFramework="net462" /> | ||
</packages> |