43 lines
1.6 KiB
Swift
43 lines
1.6 KiB
Swift
import AppKit
|
|||
|
|
import WebKit
|
||
|
|
|
||
|
|
/// Help → ProdDash Viewer Help: the page that ships inside the app, so it
|
||
|
|
/// opens with no network and always matches this version.
|
||
|
|
final class HelpWindowController: NSWindowController, WKNavigationDelegate {
|
||
|
|
|
||
|
|
convenience init() {
|
||
|
|
let web = WKWebView()
|
||
|
|
let window = NSWindow(
|
||
|
|
contentRect: NSRect(x: 0, y: 0, width: 640, height: 720),
|
||
|
|
styleMask: [.titled, .closable, .miniaturizable, .resizable],
|
||
|
|
backing: .buffered, defer: false)
|
||
|
|
window.title = "ProdDash Viewer Help"
|
||
|
|
window.minSize = NSSize(width: 420, height: 360)
|
||
|
|
window.contentView = web
|
||
|
|
window.tabbingMode = .disallowed
|
||
|
|
window.isRestorable = false
|
||
|
|
window.center()
|
||
|
|
window.setFrameAutosaveName("ProdDashViewerHelp")
|
||
|
|
self.init(window: window)
|
||
|
|
web.navigationDelegate = self
|
||
|
|
if let page = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "Help") {
|
||
|
|
web.loadFileURL(page, allowingReadAccessTo: page.deletingLastPathComponent())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func show() {
|
||
|
|
showWindow(nil)
|
||
|
|
window?.makeKeyAndOrderFront(nil)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// The help page itself stays here; its links to the web open in the browser.
|
||
|
|
func webView(_ webView: WKWebView, decidePolicyFor action: WKNavigationAction,
|
||
|
|
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
||
|
|
guard let url = action.request.url, !url.isFileURL, url.scheme != "about" else {
|
||
|
|
return decisionHandler(.allow)
|
||
|
|
}
|
||
|
|
NSWorkspace.shared.open(url)
|
||
|
|
decisionHandler(.cancel)
|
||
|
|
}
|
||
|
|
}
|