2021-06-12 13:48:29 +03:00
|
|
|
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
2021-06-12 13:32:27 +03:00
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
2021-06-12 18:22:02 +03:00
|
|
|
@NSApplicationMain
|
2021-06-12 13:32:27 +03:00
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
2021-06-12 18:48:23 +03:00
|
|
|
|
2021-06-15 00:42:21 +03:00
|
|
|
private let agent = Agent.shared
|
2021-06-28 16:20:08 +03:00
|
|
|
private let gasService = GasService.shared
|
2021-07-04 18:05:50 +03:00
|
|
|
private let priceService = PriceService.shared
|
2021-06-15 00:42:21 +03:00
|
|
|
|
2021-07-07 20:50:09 +03:00
|
|
|
override init() {
|
|
|
|
super.init()
|
|
|
|
let manager = NSAppleEventManager.shared()
|
|
|
|
manager.setEventHandler(self, andSelector: #selector(self.getUrl(_:withReplyEvent:)),
|
|
|
|
forEventClass: AEEventClass(kInternetEventClass),
|
|
|
|
andEventID: AEEventID(kAEGetURL))
|
|
|
|
}
|
|
|
|
|
2021-06-13 01:35:24 +03:00
|
|
|
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-07-07 20:50:09 +03:00
|
|
|
@objc private func getUrl(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
|
|
|
|
if let url = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue {
|
|
|
|
// TODO: handle all kinds of deep link
|
|
|
|
// TODO: do something if could not parse input link
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-12 13:32:27 +03:00
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
2021-06-15 00:42:21 +03:00
|
|
|
agent.start()
|
2021-06-28 16:20:08 +03:00
|
|
|
gasService.start()
|
2021-07-04 18:05:50 +03:00
|
|
|
priceService.start()
|
2021-06-12 13:32:27 +03:00
|
|
|
}
|
|
|
|
|
2021-06-12 21:15:32 +03:00
|
|
|
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
2021-06-15 00:42:21 +03:00
|
|
|
agent.reopen()
|
2021-06-12 21:15:32 +03:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-06-15 00:08:26 +03:00
|
|
|
func application(_ application: NSApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void) -> Bool {
|
2021-06-15 00:42:21 +03:00
|
|
|
let prefix = "https://encrypted.ink/wc?uri="
|
|
|
|
if let url = userActivity.webpageURL?.absoluteString, url.hasPrefix(prefix),
|
|
|
|
let link = url.dropFirst(prefix.count).removingPercentEncoding {
|
|
|
|
agent.processInputLink(link)
|
2021-06-15 00:08:26 +03:00
|
|
|
}
|
2021-06-15 00:42:21 +03:00
|
|
|
// TODO: do something if could not parse input link
|
2021-06-15 00:08:26 +03:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-06-12 18:48:23 +03:00
|
|
|
}
|