From 8849ebff9683004daedc56c67daf55320ac04ad4 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Mon, 29 Apr 2024 13:29:02 -0700 Subject: [PATCH] Fix view controller not being released (#8) Fixes #7 --- PreviewExtension/PreviewViewController.swift | 11 +++++++++-- package.json | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/PreviewExtension/PreviewViewController.swift b/PreviewExtension/PreviewViewController.swift index 5681280..b95a91a 100644 --- a/PreviewExtension/PreviewViewController.swift +++ b/PreviewExtension/PreviewViewController.swift @@ -113,11 +113,11 @@ class PreviewViewController: NSViewController, QLPreviewingController, WKUIDeleg } deinit { - log.debug("deinit PreviewViewController") + log.debug("deinit \(self)") } override func loadView() { - log.debug("loadView") + log.debug("\(self) loadView") view = webView webView.uiDelegate = self @@ -168,6 +168,13 @@ class PreviewViewController: NSViewController, QLPreviewingController, WKUIDeleg webView.loadFileURL(configuration.pageURL, allowingReadAccessTo: configuration.pageURL) } + override func viewDidDisappear() { + super.viewDidDisappear() + // Break a strong reference that prevents the view controller from being released + // https://forums.developer.apple.com/forums/thread/713062?answerId=726937022#726937022 + webView.configuration.userContentController.removeAllScriptMessageHandlers() + } + func preparePreviewOfFile(at url: URL, completionHandler: @escaping (Error?) -> Void) { log.info("begin preparing file", metadata: ["url": "\(url)"]) assert(previewedFileURL == nil) diff --git a/package.json b/package.json index 5fcc498..d07fd50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "quicklookjs", - "version": "1.0.0", + "version": "1.0.1", "description": "Quick Look plugin for web-based previews", "homepage": "https://github.com/jtbandes/quicklookjs#readme", "author": "Jacob Bandes-Storch",