├── .github
└── workflows
│ └── build.yml
├── .gitignore
├── .gitmodules
├── LICENSE.txt
├── Plugin.cs
├── Properties
└── AssemblyInfo.cs
├── QuickLook.Plugin.Metadata.Base.config
├── QuickLook.Plugin.WebViewPlus.csproj
├── QuickLook.Plugin.WebViewPlus.sln
├── README.md
├── Scripts
├── pack-zip.ps1
└── update-version.ps1
├── WebpagePanel.cs
├── packages.config
└── webApp
└── _WebViewPlus_WebApp_Goes_Here_.txt
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: WebViewPlugin Build
2 |
3 | on:
4 | push:
5 | tags:
6 | - "[1-9].[0-9]+.[0-9]+"
7 |
8 | env:
9 | # Path to the solution file relative to the root of the project.
10 | SOLUTION_FILE_PATH: ./QuickLook.Plugin.WebViewPlus.sln
11 |
12 | # Configuration type to build.
13 | # You can convert this to a build matrix if you need coverage of multiple configuration types.
14 | # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
15 | BUILD_CONFIGURATION: Release
16 |
17 | #GITHUB_REF_NAME - short ref name of the branch or tag
18 |
19 | permissions:
20 | contents: read
21 |
22 | jobs:
23 | build-webapp:
24 | runs-on: ubuntu-latest
25 |
26 | steps:
27 | - name: Checkout
28 | uses: actions/checkout@v4
29 | with:
30 | repository: mooflu/WebViewPlus
31 | ref: master
32 |
33 | - name: Detect package manager
34 | id: detect-package-manager
35 | run: |
36 | if [ -f "${{ github.workspace }}/yarn.lock" ]; then
37 | echo "manager=yarn" >> $GITHUB_OUTPUT
38 | echo "command=install" >> $GITHUB_OUTPUT
39 | echo "runner=yarn" >> $GITHUB_OUTPUT
40 | exit 0
41 | elif [ -f "${{ github.workspace }}/package.json" ]; then
42 | echo "manager=npm" >> $GITHUB_OUTPUT
43 | echo "command=ci" >> $GITHUB_OUTPUT
44 | echo "runner=npx --no-install" >> $GITHUB_OUTPUT
45 | exit 0
46 | else
47 | echo "Unable to determine package manager"
48 | exit 1
49 | fi
50 |
51 | - name: Setup Node
52 | uses: actions/setup-node@v4
53 | with:
54 | node-version: "20"
55 | cache: ${{ steps.detect-package-manager.outputs.manager }}
56 |
57 | - name: Install dependencies
58 | run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
59 |
60 | - name: Build with vitejs
61 | run: ${{ steps.detect-package-manager.outputs.runner }} vite build
62 |
63 | - name: Tar webapp files
64 | run: tar -C ./build -cvf webapp.tar .
65 |
66 | - name: Upload artifact
67 | uses: actions/upload-artifact@v4
68 | with:
69 | name: webapp
70 | path: webapp.tar
71 |
72 | build-plugin:
73 | needs: build-webapp
74 |
75 | runs-on: windows-latest
76 |
77 | steps:
78 | - uses: actions/checkout@v4
79 | with:
80 | ref: master
81 | submodules: recursive
82 | fetch-depth: 0
83 |
84 | - uses: actions/download-artifact@v4
85 | with:
86 | name: webapp
87 |
88 | - name: Untar webapp files
89 | run: tar -C ./webApp -xvf webapp.tar
90 |
91 | - name: Add MSBuild to PATH
92 | uses: microsoft/setup-msbuild@v2
93 |
94 | - name: Restore NuGet packages
95 | working-directory: ${{github.workspace}}
96 | run: nuget restore ${{env.SOLUTION_FILE_PATH}}
97 |
98 | - name: Build
99 | working-directory: ${{github.workspace}}
100 | # Add additional options to the MSBuild command line here (like platform or verbosity level).
101 | # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
102 | run: |
103 | msbuild /m /p:BuildInParallel=true /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
104 | cd scripts
105 | powershell ./pack-zip.ps1
106 |
107 | # upload msi and zip artifacts so the publish job below can download and then update latest release via Linux
108 | - uses: actions/upload-artifact@v4
109 | with:
110 | name: quicklook-plugin
111 | path: QuickLook.Plugin.WebViewPlus.qlplugin
112 |
113 | publish:
114 | needs: build-plugin
115 |
116 | # one of the steps uses container action which is Linux only
117 | runs-on: ubuntu-latest
118 |
119 | permissions: write-all
120 |
121 | steps:
122 | - uses: actions/download-artifact@v4
123 | with:
124 | name: quicklook-plugin
125 |
126 | - name: Publish release
127 | # see https://github.com/pyTooling/Actions/tree/main/releaser
128 | uses: pyTooling/Actions/releaser@main
129 | with:
130 | tag: ${{ github.ref_name }}
131 | rm: true
132 | token: ${{ secrets.GITHUB_TOKEN }}
133 | files: QuickLook.Plugin.WebViewPlus.qlplugin
134 |
135 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 | /*.qlplugin
332 | /GitVersion.cs
333 | /QuickLook.Plugin.Metadata.config
334 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "QuickLook.Common"]
2 | path = QuickLook.Common
3 | url = https://github.com/QL-Win/QuickLook.Common.git
4 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Frank Becker
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/Plugin.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2022 Frank Becker
2 |
3 | using System.IO;
4 | using System.Linq;
5 | using System.Windows;
6 | using System.Windows.Threading;
7 | using QuickLook.Common.Plugin;
8 |
9 | namespace QuickLook.Plugin.WebViewPlus
10 | {
11 | public class Plugin : IViewer
12 | {
13 | private WebpagePanel _panel;
14 |
15 | public int Priority => 1;
16 | private static double _width = 1000;
17 | private static double _height = 1200;
18 |
19 | public void Init()
20 | {
21 | }
22 |
23 | public bool CanHandle(string path)
24 | {
25 | var extension = Path.GetExtension(path).ToLower().Substring(1);
26 | return !Directory.Exists(path) && WebpagePanel.Extensions.Any(extension.Equals);
27 | }
28 |
29 | public void Prepare(string path, ContextObject context)
30 | {
31 | var desiredSize = new Size(_width, _height);
32 | context.SetPreferredSizeFit(desiredSize, 0.9);
33 | }
34 |
35 | public void View(string path, ContextObject context)
36 | {
37 | _panel = new WebpagePanel();
38 | context.ViewerContent = _panel;
39 | context.Title = Path.IsPathRooted(path) ? Path.GetFileName(path) : path;
40 |
41 | _panel.NavigateToFile(path);
42 | _panel.Dispatcher.Invoke(() => { context.IsBusy = false; }, DispatcherPriority.Loaded);
43 | }
44 |
45 | public void Cleanup()
46 | {
47 | _width = _panel.ActualWidth;
48 | _height = _panel.ActualHeight;
49 |
50 | _panel?.Dispose();
51 | _panel = null;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using System.Windows;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("QuickLook.Plugin.WebViewPlus")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("mooflu.com")]
12 | [assembly: AssemblyProduct("QuickLook.Plugin.WebViewPlus")]
13 | [assembly: AssemblyCopyright("Copyright © Frank Becker 2022")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | //In order to begin building localizable applications, set
23 | //CultureYouAreCodingWith in your .csproj file
24 | //inside a . For example, if you are using US english
25 | //in your source files, set the to en-US. Then uncomment
26 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
27 | //the line below to match the UICulture setting in the project file.
28 |
29 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
30 |
31 |
32 | [assembly: ThemeInfo(
33 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
34 | //(used if a resource is not found in the page,
35 | // or application resource dictionaries)
36 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
37 | //(used if a resource is not found in the page,
38 | // app, or any theme specific resource dictionaries)
39 | )]
40 |
41 |
42 | // Version information for an assembly consists of the following four values:
43 | //
44 | // Major Version
45 | // Minor Version
46 | // Build Number
47 | // Revision
48 | //
49 | // You can specify all the values or you can default the Build and Revision Numbers
50 | // by using the '*' as shown below:
51 | //[assembly: AssemblyVersion("1.0.*")]
--------------------------------------------------------------------------------
/QuickLook.Plugin.Metadata.Base.config:
--------------------------------------------------------------------------------
1 |
2 |
3 | QuickLook.Plugin.WebViewPlus
4 | 0
5 | Enhanced version of the built-in HtmlViewer plugin.
6 |
--------------------------------------------------------------------------------
/QuickLook.Plugin.WebViewPlus.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {863ECAAC-18D9-4256-A27D-0F308089FB47}
8 | library
9 | QuickLook.Plugin.WebViewPlus
10 | QuickLook.Plugin.WebViewPlus
11 | v4.6.2
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 |
16 |
17 |
18 |
19 | true
20 | full
21 | false
22 | ..\QuickLook.upstream\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.WebViewPlus\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 | true
37 | Debug\
38 | DEBUG;TRACE
39 | full
40 | x86
41 | prompt
42 | MinimumRecommendedRules.ruleset
43 |
44 |
45 | Release\
46 | TRACE
47 | true
48 | pdbonly
49 | x86
50 | prompt
51 | MinimumRecommendedRules.ruleset
52 |
53 |
54 | false
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | packages\Microsoft.Web.WebView2.1.0.3065.39\lib\net462\Microsoft.Web.WebView2.Core.dll
63 |
64 |
65 | packages\Microsoft.Web.WebView2.1.0.3065.39\lib\net462\Microsoft.Web.WebView2.WinForms.dll
66 |
67 |
68 | packages\Microsoft.Web.WebView2.1.0.3065.39\lib\net462\Microsoft.Web.WebView2.Wpf.dll
69 |
70 |
71 | packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll
72 |
73 |
74 |
75 |
76 | 4.0
77 |
78 |
79 | packages\UTF.Unknown.2.5.1\lib\net40\UtfUnknown.dll
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 | {85fdd6ba-871d-46c8-bd64-f6bb0cb5ea95}
94 | QuickLook.Common
95 | False
96 |
97 |
98 |
99 |
100 |
101 |
102 | Always
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/QuickLook.Plugin.WebViewPlus.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28010.2003
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.WebViewPlus", "QuickLook.Plugin.WebViewPlus.csproj", "{863ECAAC-18D9-4256-A27D-0F308089FB47}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Common", "QuickLook.Common\QuickLook.Common.csproj", "{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|x86 = Debug|x86
14 | Release|Any CPU = Release|Any CPU
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|x86.ActiveCfg = Debug|x86
21 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|x86.Build.0 = Debug|x86
22 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|x86.ActiveCfg = Release|x86
25 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|x86.Build.0 = Release|x86
26 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|x86.ActiveCfg = Debug|Any CPU
29 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|x86.Build.0 = Debug|Any CPU
30 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|x86.ActiveCfg = Release|Any CPU
33 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|x86.Build.0 = Release|Any CPU
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | GlobalSection(ExtensibilityGlobals) = postSolution
39 | SolutionGuid = {D545EDE6-0533-4E3F-BB67-308B17E4EDAC}
40 | EndGlobalSection
41 | EndGlobal
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # QuickLook.Plugin.WebViewPlus
4 |
5 | [QuickLook](https://github.com/QL-Win/QuickLook) plugin for previewing various file types with [WebViewPlus](https://github.com/mooflu/WebViewPlus).
6 |
7 | ## Try out
8 |
9 | 1. Go to [Release page](https://github.com/mooflu/QuickLook.Plugin.WebViewPlus/releases) and download the latest version.
10 | 2. Make sure that you have QuickLook running in the background. Go to your Download folder, and press Spacebar on the downloaded `.qlplugin` file.
11 | 3. Click the “Install” button in the popup window.
12 | 4. Restart QuickLook.
13 | 5. To configure which file types to preview via WebViewPlus, open an html file and click the gears button on the bottom right.
14 |
15 | ## Development
16 |
17 | 1. Clone this project. Do not forget to update submodules.
18 | 2. Copy WebViewPlus web app to `webApp` or set plugin config `WebAppUrl` - see `WebpagePanel.cs`
19 | 3. Set `Output path` in `Debug` configuration to something like `..\QuickLook.upstream\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.WebViewPlus\`
20 | 4. Build plugin project with `Debug` profile
21 | 5. Build and run upstream Quicklook with `Debug` profile
22 |
23 | # Release
24 | 1. Build project with `Release` profile.
25 | 2. Run `Scripts\pack-zip.ps1`.
26 | 3. You should find a file named `QuickLook.Plugin.WebViewPlus.qlplugin` in the project directory.
27 |
28 | ## License
29 |
30 | MIT License.
31 |
--------------------------------------------------------------------------------
/Scripts/pack-zip.ps1:
--------------------------------------------------------------------------------
1 | Remove-Item ..\QuickLook.Plugin.WebViewPlus.qlplugin -ErrorAction SilentlyContinue
2 |
3 | $files = Get-ChildItem -Path ..\bin\Release\ -Exclude *.pdb,*.xml
4 | Compress-Archive $files ..\QuickLook.Plugin.WebViewPlus.zip
5 | Move-Item ..\QuickLook.Plugin.WebViewPlus.zip ..\QuickLook.Plugin.WebViewPlus.qlplugin
--------------------------------------------------------------------------------
/Scripts/update-version.ps1:
--------------------------------------------------------------------------------
1 | $tag = git describe --always --tags "--abbrev=0"
2 | $revision = git describe --always --tags
3 |
4 | $text = @"
5 | // This file is generated by update-version.ps1
6 |
7 | using System.Reflection;
8 |
9 | [assembly: AssemblyVersion("$tag")]
10 | [assembly: AssemblyInformationalVersion("$revision")]
11 | "@
12 |
13 | $text | Out-File $PSScriptRoot\..\GitVersion.cs -Encoding utf8
14 |
15 |
16 | $xml = [xml](Get-Content $PSScriptRoot\..\QuickLook.Plugin.Metadata.Base.config)
17 | $xml.Metadata.Version="$revision"
18 | $xml.Save("$PSScriptRoot\..\QuickLook.Plugin.Metadata.config")
--------------------------------------------------------------------------------
/WebpagePanel.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2022 Frank Becker
2 |
3 | using System;
4 | using System.Diagnostics;
5 | using System.Globalization;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Reflection;
9 | using System.Text;
10 | using System.Windows;
11 | using System.Windows.Controls;
12 | using Microsoft.Web.WebView2.Core;
13 | using Microsoft.Web.WebView2.Wpf;
14 | using Newtonsoft.Json;
15 | using QuickLook.Common.Helpers;
16 | using UtfUnknown;
17 |
18 | // Note: see webview2 sample app:
19 | // https://github.com/MicrosoftEdge/WebView2Samples/blob/main/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs
20 |
21 | public class FileData
22 | {
23 | public string fileName { get; set; }
24 | public long fileSize { get; set; }
25 | public bool isBinary { get; set; }
26 | public string textContent { get; set; }
27 | }
28 |
29 | public class CommandMessage
30 | {
31 | public string command { get; set; }
32 | public string[] data { get; set; }
33 | public bool boolValue;
34 | }
35 |
36 | public class InitData
37 | {
38 | public string langCode { get; set; }
39 | public bool detectEncoding { get; set; }
40 | public bool showTrayIcon { get; set; }
41 | public bool useTransparency { get; set; }
42 | }
43 |
44 | namespace QuickLook.Plugin.WebViewPlus
45 | {
46 | public class WebpagePanel : UserControl
47 | {
48 | public static readonly string DefaultExtensions =
49 | "html,htm,mht,mhtml,pdf,epub,csv,xlsx,svg,md,markdown,gltf,glb,c++,h++,bat,c,cmake,cpp,cs,css,d,go,h,hpp,java,js,json,jsx,kt,lua,m,mm,makefile,pas,perl,php,pl,ps1,psm1,py,r,rb,rs,sass,scala,scss,sh,sql,swift,tex,ts,tsx,txt,webp,xml,yaml,yml";
50 | public static string[] Extensions = SettingHelper.Get("ExtensionList", WebpagePanel.DefaultExtensions, "QuickLook.Plugin.WebViewPlus").Split(',');
51 |
52 | // These should match the ones in the web app openFile.ts:BINARY_EXTENSIONS
53 | private static readonly string[] _binExtensions = "pdf,epub,xlsx,xls,ods,gltf,glb,fbx,obj,webp,jpg,jpeg,png,apng,gif,bmp,avif,ttf,otf,woff,woff2".Split(',');
54 | private Uri _currentUri;
55 | private WebView2 _webView;
56 | private bool _webAppReady = false;
57 | private CoreWebView2SharedBuffer _sharedBuffer = null;
58 | private FileInfo _activeFileInfo = null;
59 | private CoreWebView2Environment _webViewEnvironment;
60 | private bool DetectEncoding = false;
61 | private static bool firstPreview = true;
62 |
63 | public WebpagePanel()
64 | {
65 | DetectEncoding = SettingHelper.Get("DetectEncoding", false, "QuickLook.Plugin.WebViewPlus");
66 |
67 | var unavailReason = WebpagePanel.WebView2UnavailableReason();
68 | if (unavailReason != null)
69 | {
70 | Content = CreateDownloadButton(unavailReason);
71 | }
72 | else
73 | {
74 | _webView = new WebView2
75 | {
76 | CreationProperties = new CoreWebView2CreationProperties
77 | {
78 | // Note: using a different user data folder than the built-in HTmlViewer plugin
79 | // This plugin starts the webview once and keeps it running and would effectively
80 | // block the HTmlViewer if it used the same folder.
81 | // See "Process model for WebView2 apps"
82 | UserDataFolder = Path.Combine(SettingHelper.LocalDataPath, @"WebViewPlus_Data\\"),
83 | Language = CultureInfo.CurrentUICulture.Name
84 | }
85 | };
86 | _webView.NavigationStarting += NavigationStarting_CancelNavigation;
87 | _webView.CoreWebView2InitializationCompleted += CoreWebView2InitializationCompleted;
88 | _webView.EnsureCoreWebView2Async();
89 | Content = _webView;
90 | }
91 | }
92 |
93 | public static string WebView2UnavailableReason()
94 | {
95 | try
96 | {
97 | var version = CoreWebView2Environment.GetAvailableBrowserVersionString();
98 | // verion format example: "110.0.1556.0 dev"
99 |
100 | // This plugin uses an experimental feature introduced in 1466
101 | // https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes?tabs=dotnetcsharp#101466-prerelease
102 | var buildNum = Int32.Parse(version.Split('.')[2]);
103 | if (buildNum < 1466)
104 | {
105 | var reason = $"QuickLook.Plugin.WebViewPlus found incompatible webview2: {version} - 1466 or higher needed";
106 | return reason;
107 | }
108 |
109 | // TODO: validate api availability.
110 |
111 | return null;
112 | }
113 | catch (Exception)
114 | {
115 | return "Viewing this file requires Microsoft Edge WebView2 (build 1466 or higher) to be installed.";
116 | }
117 | }
118 |
119 | CoreWebView2Environment WebViewEnvironment
120 | {
121 | get
122 | {
123 | if (_webViewEnvironment == null && _webView?.CoreWebView2 != null)
124 | {
125 | _webViewEnvironment = _webView.CoreWebView2.Environment;
126 | }
127 | return _webViewEnvironment;
128 | }
129 | }
130 |
131 | public void NavigateToFile(string path)
132 | {
133 | _activeFileInfo = new FileInfo(path);
134 | if (_webAppReady)
135 | {
136 | sendFileData();
137 | }
138 | }
139 |
140 | void sendFileData()
141 | {
142 | if (_sharedBuffer != null)
143 | {
144 | _sharedBuffer.Dispose();
145 | _sharedBuffer = null;
146 | }
147 | var extension = _activeFileInfo.Extension.ToLower().Substring(1);
148 | var isBinary = _binExtensions.Any(extension.Equals);
149 | var textContent = "";
150 | if (isBinary)
151 | {
152 | _sharedBuffer = WebViewEnvironment.CreateSharedBuffer((ulong)_activeFileInfo.Length);
153 | using (BinaryWriter writer = new BinaryWriter(_sharedBuffer.OpenStream()))
154 | {
155 | using (var br = new BinaryReader(new FileStream(_activeFileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
156 | {
157 | writer.Write(br.ReadBytes((int)br.BaseStream.Length));
158 | }
159 | }
160 | }
161 | else
162 | {
163 | _sharedBuffer = WebViewEnvironment.CreateSharedBuffer(1);
164 |
165 | var encoding = Encoding.Default;
166 | if (DetectEncoding)
167 | {
168 | encoding = CharsetDetector.DetectFromFile(_activeFileInfo).Detected?.Encoding ?? encoding;
169 | }
170 | using (var sr = new StreamReader(new FileStream(_activeFileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), encoding))
171 | {
172 | textContent = sr.ReadToEnd();
173 | }
174 | }
175 | var json = JsonConvert.SerializeObject(
176 | new FileData
177 | {
178 | fileName = _activeFileInfo.Name,
179 | fileSize = _activeFileInfo.Length,
180 | isBinary = isBinary,
181 | textContent = textContent
182 | }
183 | );
184 |
185 | // read-write access needed for epub/jszip. ArrayReader writes to itself.
186 | // See https://github.com/Stuk/jszip/blob/v3.10.1/lib/reader/ArrayReader.js#L8
187 | _webView.CoreWebView2.PostSharedBufferToScript(_sharedBuffer, CoreWebView2SharedBufferAccess.ReadWrite, json);
188 | }
189 |
190 | void WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs args)
191 | {
192 | var msg = JsonConvert.DeserializeObject(args.WebMessageAsJson);
193 | switch(msg.command)
194 | {
195 | case "AppReadyForData":
196 | _webAppReady = true;
197 | // If the user profile was previously generated (WebView2_Data), it doesn't seem to change the navigator.language setting
198 | // when a webview is created with a different language in 'new WebView2' above.
199 | // You'd have to delete the WebView2_Data folder first.
200 | // Oh, well. Explicitly sending current language to web app, instead.
201 | var json = JsonConvert.SerializeObject(
202 | new InitData
203 | {
204 | langCode = CultureInfo.CurrentUICulture.Name,
205 | detectEncoding = SettingHelper.Get("DetectEncoding", false, "QuickLook.Plugin.WebViewPlus"),
206 | showTrayIcon = SettingHelper.Get("ShowTrayIcon", true),
207 | useTransparency = SettingHelper.Get("UseTransparency", true)
208 | }
209 | );
210 |
211 | _webView.CoreWebView2.PostWebMessageAsString($"initData:{json}");
212 | sendFileData();
213 | break;
214 |
215 | case "Extensions":
216 | SettingHelper.Set("ExtensionList", String.Join(",", msg.data), "QuickLook.Plugin.WebViewPlus");
217 | Extensions = SettingHelper.Get("ExtensionList", WebpagePanel.DefaultExtensions, "QuickLook.Plugin.WebViewPlus").Split(',');
218 | break;
219 |
220 | case "DetectEncoding":
221 | SettingHelper.Set("DetectEncoding", msg.boolValue, "QuickLook.Plugin.WebViewPlus");
222 | DetectEncoding = SettingHelper.Get("DetectEncoding", false, "QuickLook.Plugin.WebViewPlus");
223 | break;
224 |
225 | case "ShowTrayIcon":
226 | SettingHelper.Set("ShowTrayIcon", msg.boolValue);
227 | break;
228 |
229 | case "UseTransparency":
230 | SettingHelper.Set("UseTransparency", msg.boolValue);
231 | break;
232 |
233 | case "Restart":
234 | RestartQuicklook();
235 | break;
236 |
237 | default:
238 | break;
239 | }
240 | }
241 |
242 | private void RestartQuicklook()
243 | {
244 | // Restart QL. Clunky way to delay startup to pass already running check.
245 | ProcessStartInfo Info = new ProcessStartInfo();
246 | Info.Arguments = "/C ping 127.0.0.1 -n 2 && \"" + string.Join(" ", Environment.GetCommandLineArgs()) + "\"";
247 | Info.WindowStyle = ProcessWindowStyle.Hidden;
248 | Info.CreateNoWindow = true;
249 | Info.FileName = "cmd.exe";
250 | Process.Start(Info);
251 | Process.GetCurrentProcess().Kill();
252 | }
253 |
254 | private void CoreWebView2InitializationCompleted(object sender, EventArgs e)
255 | {
256 | _webView.CoreWebView2.WebMessageReceived += WebMessageReceived;
257 | _webView.CoreWebView2.NewWindowRequested += NewWindowRequested;
258 | _webView.CoreWebView2.FrameNavigationStarting += FrameNavigationStarting;
259 | _webView.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
260 | _webView.CoreWebView2.Settings.AreHostObjectsAllowed = false;
261 |
262 | // 3 places to get web app:
263 | // 1. a url via WebAppUrl (e.g. locally hosted vite dev version of app)
264 | // 2. in SettingHelper.LocalDataPath (same place as config files)
265 | // 3. bundled with plugin
266 | var webAppInConfigFolder = Path.Combine(SettingHelper.LocalDataPath, "webviewplus");
267 | var webAppInBundledFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "webviewplus");
268 | var uri = new Uri("https://webviewplus.mooflu.com/index.html");
269 | var webAppUrl = SettingHelper.Get("WebAppUrl", null, "QuickLook.Plugin.WebViewPlus");
270 | if (webAppUrl != null)
271 | {
272 | // ProcessHelper.WriteLog($"QuickLook.Plugin.WebViewPlus using app via custom url: {webAppUrl}");
273 | uri = new Uri(webAppUrl);
274 | }
275 | else
276 | {
277 | // map webviewplus folder to a private virtual hostname
278 | if (File.Exists(Path.Combine(webAppInConfigFolder, "index.html")))
279 | {
280 | // ProcessHelper.WriteLog("QuickLook.Plugin.WebViewPlus using app from config");
281 | _webView.CoreWebView2.SetVirtualHostNameToFolderMapping("webviewplus.mooflu.com", webAppInConfigFolder, CoreWebView2HostResourceAccessKind.Allow);
282 | }
283 | else if(File.Exists(Path.Combine(webAppInBundledFolder, "index.html")))
284 | {
285 | // ProcessHelper.WriteLog("QuickLook.Plugin.WebViewPlus using app from plugin");
286 | _webView.CoreWebView2.SetVirtualHostNameToFolderMapping("webviewplus.mooflu.com", webAppInBundledFolder, CoreWebView2HostResourceAccessKind.Allow);
287 | }
288 | }
289 | _webView.Source = uri;
290 | _currentUri = _webView.Source;
291 | }
292 | private void NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
293 | {
294 | // Prevent new windows being opened (e.g. ctrl-click link)
295 | e.Handled = true;
296 | if (_webAppReady)
297 | {
298 | _webView.CoreWebView2.PostWebMessageAsString("newWindowRejected");
299 | }
300 | }
301 | private void NavigationStarting_CancelNavigation(object sender, CoreWebView2NavigationStartingEventArgs e)
302 | {
303 | var newUri = new Uri(e.Uri);
304 | if (newUri != _currentUri) e.Cancel = true;
305 | }
306 |
307 | private void FrameNavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
308 | {
309 | if (!e.Uri.StartsWith("blob:") && !e.Uri.StartsWith("about:"))
310 | {
311 | e.Cancel = true;
312 | if (_webAppReady)
313 | {
314 | _webView.CoreWebView2.PostWebMessageAsString("frameNavigationRejected");
315 | }
316 | }
317 | }
318 |
319 | // No longer used - Changes in webview2 caused crashes due to
320 | // "WebView2 controller will be auto closed if the parent hwnd is destroyed"
321 | public void UnloadData()
322 | {
323 | _activeFileInfo = null;
324 | _sharedBuffer?.Dispose();
325 | _sharedBuffer = null;
326 | if (_webAppReady)
327 | {
328 | _webView.CoreWebView2.PostWebMessageAsString("unload");
329 | }
330 | }
331 |
332 | public void Dispose()
333 | {
334 | if (firstPreview)
335 | {
336 | firstPreview = false;
337 | _webView.CoreWebView2.Profile.ClearBrowsingDataAsync(
338 | CoreWebView2BrowsingDataKinds.FileSystems |
339 | CoreWebView2BrowsingDataKinds.IndexedDb |
340 | // keep local storage
341 | CoreWebView2BrowsingDataKinds.WebSql |
342 | CoreWebView2BrowsingDataKinds.CacheStorage |
343 | CoreWebView2BrowsingDataKinds.Cookies |
344 | CoreWebView2BrowsingDataKinds.DiskCache |
345 | CoreWebView2BrowsingDataKinds.DownloadHistory |
346 | CoreWebView2BrowsingDataKinds.GeneralAutofill |
347 | CoreWebView2BrowsingDataKinds.PasswordAutosave |
348 | CoreWebView2BrowsingDataKinds.Settings
349 | );
350 | }
351 |
352 | _activeFileInfo = null;
353 | _sharedBuffer?.Dispose();
354 | _sharedBuffer = null;
355 | _webView?.Dispose();
356 | _webView = null;
357 | }
358 |
359 | private object CreateDownloadButton(string reason)
360 | {
361 | var button = new Button
362 | {
363 | Content = reason,
364 | HorizontalAlignment = HorizontalAlignment.Center,
365 | VerticalAlignment = VerticalAlignment.Center,
366 | Padding = new Thickness(20, 6, 20, 6)
367 | };
368 | button.Click += (sender, e) => Process.Start("https://go.microsoft.com/fwlink/p/?LinkId=2124703");
369 |
370 | return button;
371 | }
372 | }
373 | }
374 |
--------------------------------------------------------------------------------
/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/webApp/_WebViewPlus_WebApp_Goes_Here_.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mooflu/QuickLook.Plugin.WebViewPlus/8c38133c5f57b427c4abc56683ae73b1cc3b400c/webApp/_WebViewPlus_WebApp_Goes_Here_.txt
--------------------------------------------------------------------------------