feat: initial Swift version
This commit is contained in:
22
QLPreview/Base.lproj/PreviewViewController.xib
Normal file
22
QLPreview/Base.lproj/PreviewViewController.xib
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="23727" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23727"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="PreviewViewController" customModule="QLPreview" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="view" destination="c22-O7-iKe" id="NRM-P4-wb6"/>
|
||||
</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"/>
|
||||
<point key="canvasLocation" x="53" y="-36"/>
|
||||
</customView>
|
||||
</objects>
|
||||
</document>
|
||||
26
QLPreview/Info.plist
Normal file
26
QLPreview/Info.plist
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionAttributes</key>
|
||||
<dict>
|
||||
<key>QLIsDataBasedPreview</key>
|
||||
<false/>
|
||||
<key>QLSupportedContentTypes</key>
|
||||
<array>
|
||||
<string>com.apple.itunes.ipa</string>
|
||||
<string>com.apple.application-and-system-extension</string>
|
||||
<string>com.apple.xcode.archive</string>
|
||||
</array>
|
||||
<key>QLSupportsSearchableItems</key>
|
||||
<false/>
|
||||
</dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.quicklook.preview</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).PreviewViewController</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
25
QLPreview/PreviewViewController.swift
Normal file
25
QLPreview/PreviewViewController.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
import Cocoa
|
||||
import Quartz // QLPreviewingController
|
||||
import WebKit // WebView
|
||||
import os // OSLog
|
||||
|
||||
// show Console logs with subsystem:de.relikd.QLApps
|
||||
private let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "main")
|
||||
|
||||
class PreviewViewController: NSViewController, QLPreviewingController {
|
||||
|
||||
override var nibName: NSNib.Name? {
|
||||
return NSNib.Name("PreviewViewController")
|
||||
}
|
||||
|
||||
func preparePreviewOfFile(at url: URL) async throws {
|
||||
let html = generateHtml(at: url)
|
||||
// sure, we could use `WKWebView`, but that requires the `com.apple.security.network.client` entitlement
|
||||
//let web = WKWebView(frame: self.view.bounds)
|
||||
let web = WebView(frame: self.view.bounds)
|
||||
web.autoresizingMask = [.width, .height]
|
||||
self.view.addSubview(web)
|
||||
web.mainFrame.loadHTMLString(html, baseURL: nil) // WebView
|
||||
//web.loadHTMLString(html, baseURL: nil) // WKWebView
|
||||
}
|
||||
}
|
||||
10
QLPreview/QLPreview.entitlements
Normal file
10
QLPreview/QLPreview.entitlements
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-only</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
Reference in New Issue
Block a user