Skip to content

Instantly share code, notes, and snippets.

@jcburns
Last active March 5, 2021 01:22
Show Gist options
  • Save jcburns/a5a83ca58a101e174ea220eb0a3db09b to your computer and use it in GitHub Desktop.
Save jcburns/a5a83ca58a101e174ea220eb0a3db09b to your computer and use it in GitHub Desktop.
#!/usr/bin/env xcrun swift
import Cocoa
import WebKit
let myapp = NSApplication.shared
let window = NSWindow(contentRect: NSMakeRect(0,0,940,800), styleMask: [.titled, .closable, .resizable, .miniaturizable], backing: .buffered, defer: true)
window.center()
window.title = "Swift webkit webview"
window.makeKeyAndOrderFront(window)
class WindowDelegate: NSObject, NSWindowDelegate {
func windowWillClose(_ notification: Notification) {
myapp.terminate(0)
}
}
let windowDelegate = WindowDelegate()
window.delegate = windowDelegate
class ApplicationDelegate: NSObject, NSApplicationDelegate {
var _window: NSWindow
init(window: NSWindow) {
self._window = window
}
func applicationDidFinishLaunching(_ notification: Notification) {
let webView = WebView(frame: (self._window.contentView?.frame)!)
self._window.contentView = webView
webView.mainFrameURL = "http://archaeofacts.com/musings"
}
func applicationShouldTerminateAfterLastWindowClosed(_ app: NSApplication) -> Bool {
return true
}
}
let applicationDelegate = ApplicationDelegate(window: window)
myapp.setActivationPolicy(.regular)
myapp.delegate = applicationDelegate
myapp.activate(ignoringOtherApps:true)
myapp.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment