Skip to content

Commit

Permalink
Fix view controller not being released (#8)
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
jtbandes authored Apr 29, 2024
1 parent 18c1578 commit 8849ebf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions PreviewExtension/PreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 8849ebf

Please sign in to comment.