Gemini/Gemini/AppDelegate.swift

54 lines
1.7 KiB
Swift
Raw Normal View History

2020-07-13 01:35:00 +00:00
//
// AppDelegate.swift
// Gemini
//
// Created by Shadowfacts on 7/12/20.
//
import Cocoa
import SwiftUI
2020-07-13 22:22:36 +00:00
import GeminiProtocol
2020-07-13 01:35:00 +00:00
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
2020-07-15 02:39:38 +00:00
var task: GeminiDataTask!
2020-07-13 22:22:36 +00:00
let url = URL(string: "gemini://localhost:1965/overview.gmi")!
2020-07-13 01:35:00 +00:00
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
// Create the window and set the content view.
window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
window.center()
window.setFrameAutosaveName("Main Window")
window.contentView = NSHostingView(rootView: contentView)
2020-07-13 22:12:04 +00:00
window.title = "Gemini"
2020-07-13 01:35:00 +00:00
window.makeKeyAndOrderFront(nil)
2020-07-13 22:22:36 +00:00
2020-07-15 02:39:38 +00:00
task = try! GeminiDataTask(url: url, completion: { (result) in
switch result {
case let .success(response):
print("Received response header: \(response.header)")
print("Received data: \(String(describing: response.body))")
print(response.bodyText.debugDescription)
case let .failure(error):
print("Error: \(error)")
}
})
task.resume()
2020-07-13 01:35:00 +00:00
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
2020-07-13 22:22:36 +00:00
}