|
// swiftc -o dotgrid dotgrid.swift -target x86_64-apple-macosx10.12 |
|
// strip -x dotgrid |
|
|
|
import Cocoa |
|
import WebKit |
|
|
|
class WindowController: NSWindowController { |
|
} |
|
|
|
class AppDelegate: NSObject { |
|
var mainWindow: NSWindow? |
|
var webView: WKWebView! |
|
} |
|
|
|
extension AppDelegate: NSApplicationDelegate, WKUIDelegate { |
|
@objc func quit(sender: NSMenuItem) { |
|
NSApp.terminate(self) |
|
} |
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) { |
|
|
|
// --- create app menu items |
|
let mainMenu = NSMenu() |
|
let mainMenuFileItem = NSMenuItem(title: "File", action: nil, keyEquivalent: "") |
|
let fileMenu = NSMenu(title: "File") |
|
fileMenu.addItem(withTitle: "Quit", action: #selector(quit(sender:)), keyEquivalent: "q") |
|
mainMenuFileItem.submenu = fileMenu |
|
mainMenu.addItem(mainMenuFileItem) |
|
NSApp.mainMenu = mainMenu |
|
|
|
// --- create main app window |
|
let window = NSWindow(contentRect: NSMakeRect(274, 145, 880, 660), |
|
styleMask:[.titled, .closable, .resizable], |
|
backing: .buffered, |
|
defer: false) |
|
window.backgroundColor = NSColor(calibratedRed: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) |
|
window.title = "dotgrid" |
|
window.isMovableByWindowBackground = true |
|
window.orderFrontRegardless() |
|
window.center() |
|
mainWindow = window |
|
|
|
let url = NSURL(string : "http://chis.cloud/dotgrid") |
|
let request = URLRequest(url: url! as URL) |
|
|
|
// --- add JS and DevTools support |
|
let webConfiguration = WKWebViewConfiguration() |
|
webConfiguration.preferences.setValue(true, forKey: "developerExtrasEnabled") |
|
webConfiguration.preferences.javaScriptEnabled = true |
|
|
|
webView = WKWebView(frame: window.frame, configuration: webConfiguration) |
|
webView.load(request) |
|
|
|
// -- make WKWebView fill the entire window |
|
window.contentView = webView |
|
|
|
NSApp.activate(ignoringOtherApps: true) |
|
} |
|
|
|
func applicationWillTerminate(_ aNotification: Notification) { |
|
} |
|
|
|
func applicationShouldTerminateAfterLastWindowClosed(_ app: NSApplication) -> Bool{ |
|
return true |
|
} |
|
} |
|
|
|
let app = NSApplication.shared |
|
app.delegate = AppDelegate() |
|
|
|
app.setActivationPolicy(.regular) |
|
atexit_b { app.setActivationPolicy(.prohibited); return } |
|
app.run() |