Skip to content

Commit

Permalink
Remove extra logging.
Browse files Browse the repository at this point in the history
Only clear browsing data after first preview is closed.
  • Loading branch information
mooflu committed Feb 19, 2025
1 parent 0ecb4a2 commit 8c38133
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions WebpagePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class WebpagePanel : UserControl
private FileInfo _activeFileInfo = null;
private CoreWebView2Environment _webViewEnvironment;
private bool DetectEncoding = false;
private static bool firstPreview = true;

public WebpagePanel()
{
Expand Down Expand Up @@ -257,19 +258,6 @@ private void CoreWebView2InitializationCompleted(object sender, EventArgs e)
_webView.CoreWebView2.FrameNavigationStarting += FrameNavigationStarting;
_webView.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
_webView.CoreWebView2.Settings.AreHostObjectsAllowed = false;
_webView.CoreWebView2.Profile.ClearBrowsingDataAsync(
CoreWebView2BrowsingDataKinds.FileSystems |
CoreWebView2BrowsingDataKinds.IndexedDb |
// keep local storage
CoreWebView2BrowsingDataKinds.WebSql |
CoreWebView2BrowsingDataKinds.CacheStorage |
CoreWebView2BrowsingDataKinds.Cookies |
CoreWebView2BrowsingDataKinds.DiskCache |
CoreWebView2BrowsingDataKinds.DownloadHistory |
CoreWebView2BrowsingDataKinds.GeneralAutofill |
CoreWebView2BrowsingDataKinds.PasswordAutosave |
CoreWebView2BrowsingDataKinds.Settings
);

// 3 places to get web app:
// 1. a url via WebAppUrl (e.g. locally hosted vite dev version of app)
Expand All @@ -281,20 +269,20 @@ private void CoreWebView2InitializationCompleted(object sender, EventArgs e)
var webAppUrl = SettingHelper.Get<string>("WebAppUrl", null, "QuickLook.Plugin.WebViewPlus");
if (webAppUrl != null)
{
ProcessHelper.WriteLog($"QuickLook.Plugin.WebViewPlus using app via custom url: {webAppUrl}");
// ProcessHelper.WriteLog($"QuickLook.Plugin.WebViewPlus using app via custom url: {webAppUrl}");
uri = new Uri(webAppUrl);
}
else
{
// map webviewplus folder to a private virtual hostname
if (File.Exists(Path.Combine(webAppInConfigFolder, "index.html")))
{
ProcessHelper.WriteLog("QuickLook.Plugin.WebViewPlus using app from config");
// ProcessHelper.WriteLog("QuickLook.Plugin.WebViewPlus using app from config");
_webView.CoreWebView2.SetVirtualHostNameToFolderMapping("webviewplus.mooflu.com", webAppInConfigFolder, CoreWebView2HostResourceAccessKind.Allow);
}
else if(File.Exists(Path.Combine(webAppInBundledFolder, "index.html")))
{
ProcessHelper.WriteLog("QuickLook.Plugin.WebViewPlus using app from plugin");
// ProcessHelper.WriteLog("QuickLook.Plugin.WebViewPlus using app from plugin");
_webView.CoreWebView2.SetVirtualHostNameToFolderMapping("webviewplus.mooflu.com", webAppInBundledFolder, CoreWebView2HostResourceAccessKind.Allow);
}
}
Expand Down Expand Up @@ -343,6 +331,24 @@ public void UnloadData()

public void Dispose()
{
if (firstPreview)
{
firstPreview = false;
_webView.CoreWebView2.Profile.ClearBrowsingDataAsync(
CoreWebView2BrowsingDataKinds.FileSystems |
CoreWebView2BrowsingDataKinds.IndexedDb |
// keep local storage
CoreWebView2BrowsingDataKinds.WebSql |
CoreWebView2BrowsingDataKinds.CacheStorage |
CoreWebView2BrowsingDataKinds.Cookies |
CoreWebView2BrowsingDataKinds.DiskCache |
CoreWebView2BrowsingDataKinds.DownloadHistory |
CoreWebView2BrowsingDataKinds.GeneralAutofill |
CoreWebView2BrowsingDataKinds.PasswordAutosave |
CoreWebView2BrowsingDataKinds.Settings
);
}

_activeFileInfo = null;
_sharedBuffer?.Dispose();
_sharedBuffer = null;
Expand Down

0 comments on commit 8c38133

Please sign in to comment.