2022-06-21 01:58:22 +00:00
|
|
|
//
|
|
|
|
// AboutWIndowController.swift
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Kevin López Brante on 20-06-22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
2022-06-22 02:17:03 +00:00
|
|
|
import WebKit
|
2022-06-21 01:58:22 +00:00
|
|
|
|
2022-06-22 16:01:42 +00:00
|
|
|
class AboutWindowController: NSWindowController, WKNavigationDelegate {
|
2022-06-21 01:58:22 +00:00
|
|
|
|
|
|
|
@IBOutlet weak var appName: NSTextField!
|
|
|
|
@IBOutlet weak var appVersion: NSTextField!
|
|
|
|
@IBOutlet weak var appCopyright: NSTextField!
|
|
|
|
|
2022-06-22 02:17:03 +00:00
|
|
|
@IBOutlet weak var creditsView: WKWebView!
|
2022-06-21 01:58:22 +00:00
|
|
|
|
|
|
|
override var windowNibName: NSNib.Name? {
|
|
|
|
return "AboutWindowController"
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBOutlet weak var vfxView: NSVisualEffectView!
|
|
|
|
|
|
|
|
override func windowDidLoad() {
|
|
|
|
super.windowDidLoad()
|
|
|
|
|
|
|
|
self.window?.center()
|
|
|
|
self.window?.isMovableByWindowBackground = true
|
|
|
|
|
2022-06-22 02:17:03 +00:00
|
|
|
creditsView.setValue(false, forKey: "drawsBackground")
|
|
|
|
|
2022-06-22 16:01:42 +00:00
|
|
|
vfxView.wantsLayer = true
|
|
|
|
vfxView.layer?.cornerRadius = 4
|
2022-06-21 01:58:22 +00:00
|
|
|
|
|
|
|
// fill up labels
|
|
|
|
|
|
|
|
appName.stringValue = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String
|
|
|
|
|
|
|
|
let shortVersionString = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
|
2022-06-21 13:27:29 +00:00
|
|
|
let fullVersionString = Bundle.main.object(forInfoDictionaryKey: "GitVersion") as! String
|
2022-06-21 01:58:22 +00:00
|
|
|
|
2022-06-22 16:01:42 +00:00
|
|
|
appVersion.stringValue = String.localizedStringWithFormat(NSLocalizedString("Version %@ (%@)", comment: "Version string"), shortVersionString, fullVersionString);
|
2022-06-21 01:58:22 +00:00
|
|
|
|
|
|
|
appCopyright.stringValue = Bundle.main.object(forInfoDictionaryKey: "NSHumanReadableCopyright") as! String
|
|
|
|
|
|
|
|
if let creditsFile = Bundle.main.url(forResource: "Credits", withExtension: "html") {
|
|
|
|
let data = try! Data(contentsOf: creditsFile)
|
|
|
|
|
2022-06-22 02:17:03 +00:00
|
|
|
creditsView.loadHTMLString(String(data: data, encoding: .utf8) ?? "Could not load credits.", baseURL: nil)
|
|
|
|
|
2022-06-21 01:58:22 +00:00
|
|
|
}
|
2022-06-22 16:01:42 +00:00
|
|
|
|
|
|
|
creditsView.navigationDelegate = self
|
2022-06-21 01:58:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-22 16:01:42 +00:00
|
|
|
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
|
|
|
if navigationAction.navigationType == .linkActivated,
|
|
|
|
let url = navigationAction.request.url {
|
|
|
|
NSWorkspace.shared.open(url)
|
|
|
|
decisionHandler(.cancel)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
decisionHandler(.allow)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func cancel(_ sender: Any?) {
|
|
|
|
close()
|
|
|
|
}
|
2022-06-21 01:58:22 +00:00
|
|
|
}
|