tokenary/Encrypted Ink/AppDelegate.swift

69 lines
2.4 KiB
Swift
Raw Normal View History

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
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-07-11 18:21:20 +03:00
private let networkMonitor = NetworkMonitor.shared
2021-08-01 13:53:13 +03:00
private let walletsManager = WalletsManager.shared
private var didFinishLaunching = false
private var initialInputLink: String?
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) {
2021-07-07 22:53:28 +03:00
processInput(url: event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue, prefix: "encryptedink://wc?uri=")
2021-07-07 20:50:09 +03:00
}
2021-06-12 13:32:27 +03:00
func applicationDidFinishLaunching(_ aNotification: Notification) {
agent.start()
2021-06-28 16:20:08 +03:00
gasService.start()
2021-07-04 18:05:50 +03:00
priceService.start()
2021-07-11 18:21:20 +03:00
networkMonitor.start()
2021-08-01 13:53:13 +03:00
walletsManager.start()
didFinishLaunching = true
if let link = initialInputLink {
initialInputLink = nil
agent.processInputLink(link)
}
2021-06-12 13:32:27 +03:00
}
2021-06-12 21:15:32 +03:00
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
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-07-07 22:53:28 +03:00
processInput(url: userActivity.webpageURL?.absoluteString, prefix: "https://encrypted.ink/wc?uri=")
return true
}
private func processInput(url: String?, prefix: String) {
if let url = url, url.hasPrefix(prefix),
let link = url.dropFirst(prefix.count).removingPercentEncoding {
if didFinishLaunching {
agent.processInputLink(link)
} else {
initialInputLink = link
}
2021-06-15 00:08:26 +03:00
}
}
2021-06-12 18:48:23 +03:00
}