Skip to content

Commit

Permalink
Implemented reset to factory settings and bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarex committed Dec 30, 2020
1 parent bf6e5e1 commit f43b1b6
Show file tree
Hide file tree
Showing 10 changed files with 668 additions and 417 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.0b10
New features:
- Implemented reset to factory settings.

Bugfix:
- Incomplete saving settings.
- UI fix.

1.0.b9
New features:
- Updated the default css style (thanks to [hazarek](https://github.com/hazarek)).
Expand Down
15 changes: 0 additions & 15 deletions QLExtension/Base.lproj/PreviewViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,19 @@
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
<plugIn identifier="com.apple.WebKit2IBPlugin" version="17701"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="PreviewViewController" customModule="Markdown_QL_Extension" customModuleProvider="target">
<connections>
<outlet property="view" destination="c22-O7-iKe" id="NRM-P4-wb6"/>
<outlet property="webView" destination="uoH-IG-NbN" id="1k7-3F-mub"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe" userLabel="Preview View">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<wkWebView wantsLayer="YES" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uoH-IG-NbN">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
<wkPreferences key="preferences"/>
</wkWebViewConfiguration>
<connections>
<outlet property="navigationDelegate" destination="-2" id="dbJ-XA-N9D"/>
</connections>
</wkWebView>
</subviews>
<point key="canvasLocation" x="22" y="107"/>
</customView>
</objects>
Expand Down
97 changes: 95 additions & 2 deletions QLExtension/PreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,34 @@ import Quartz
import WebKit
import OSLog

class MyWKWebView: WKWebView {
override var canBecomeKeyView: Bool {
return false
}

override func becomeFirstResponder() -> Bool {
// Quicklook window do not allow first responder child.
return false
}
}

@available(macOS, deprecated: 10.14)
class MyWebView: WebView {
override var canBecomeKeyView: Bool {
return false
}

override func becomeFirstResponder() -> Bool {
// Quicklook window do not allow first responder child.
return false
}
}

class PreviewViewController: NSViewController, QLPreviewingController {
private let log = {
return OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "quicklook.qlmarkdown-extension")
}()

@IBOutlet weak var webView: WKWebView!
var handler: ((Error?) -> Void)? = nil

override var nibName: NSNib.Name? {
Expand Down Expand Up @@ -76,13 +98,84 @@ class PreviewViewController: NSViewController, QLPreviewingController {
let text = try settings.render(file: url, forAppearance: type == "Light" ? .light : .dark, baseDir: url.deletingLastPathComponent().path, log: self.log)

let html = settings.getCompleteHTML(title: url.lastPathComponent, body: text)
webView.loadHTMLString(html, baseURL: url.deletingLastPathComponent())

let previewRect: CGRect
if #available(macOS 11, *) {
previewRect = self.view.bounds
} else {
previewRect = self.view.bounds.insetBy(dx: 2, dy: 2)
}

/*
if #available(macOS 11, *) {
// On Big Sur there are some bugs with the current WKWebView:
// - WKWebView crash on launch becaouse ignore the com.apple.security.network.client entitlement (workaround setting the com.apple.security.temporary-exception.mach-lookup.global-name exception for com.apple.nsurlsessiond
// - WKWebView cannot scroll when QL preview window is in fullscreen.
// Old WebView API works.
let webView = MyWebView(frame: previewRect)
webView.autoresizingMask = [.height, .width]
webView.preferences.isJavaScriptEnabled = false
webView.preferences.allowsAirPlayForMediaPlayback = false
webView.preferences.arePlugInsEnabled = false
self.view.addSubview(webView)
webView.mainFrame.loadHTMLString(html, baseURL: nil)
webView.frameLoadDelegate = self
webView.drawsBackground = false // Best solution is use the same color of the body
} else {
*/
let preferences = WKPreferences()
preferences.javaScriptEnabled = false

// Create a configuration for the preferences
let configuration = WKWebViewConfiguration()
//configuration.preferences = preferences
configuration.allowsAirPlayForMediaPlayback = false
// configuration.userContentController.add(self, name: "jsHandler")

let webView = MyWKWebView(frame: previewRect, configuration: configuration)
webView.autoresizingMask = [.height, .width]

webView.wantsLayer = true
if #available(macOS 11, *) {
webView.layer?.borderWidth = 0
} else {
// Draw a border around the web view
webView.layer?.borderColor = NSColor.gridColor.cgColor
webView.layer?.borderWidth = 1
}

webView.navigationDelegate = self
// webView.uiDelegate = self

webView.loadHTMLString(html, baseURL: nil)
self.view.addSubview(webView)

webView.loadHTMLString(html, baseURL: url.deletingLastPathComponent())
/* } */
} catch {
handler(error)
}
}
}

@available(macOS, deprecated: 10.14)
extension PreviewViewController: WebFrameLoadDelegate {
func webView(_ sender: WebView!, didFinishLoadFor frame: WebFrame!) {
if let handler = self.handler {
handler(nil)
}
self.handler = nil
}
func webView(_ sender: WebView!, didFailLoadWithError error: Error!, for frame: WebFrame!) {
if let handler = self.handler {
handler(error)
}
self.handler = nil
}
}

extension PreviewViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if let handler = self.handler {
Expand Down
8 changes: 4 additions & 4 deletions QLMarkdown.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
HEADER_SEARCH_PATHS = (
Expand Down Expand Up @@ -1063,7 +1063,7 @@
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
HEADER_SEARCH_PATHS = (
Expand Down Expand Up @@ -1218,7 +1218,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1262,7 +1262,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Loading

0 comments on commit f43b1b6

Please sign in to comment.