Last active
March 5, 2021 01:22
-
-
Save jcburns/a5a83ca58a101e174ea220eb0a3db09b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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