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-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
|
2021-06-15 00:42:21 +03:00
|
|
|
|
2021-07-30 01:39:31 +03:00
|
|
|
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) {
|
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-07-11 18:21:20 +03:00
|
|
|
networkMonitor.start()
|
2021-08-01 13:53:13 +03:00
|
|
|
walletsManager.start()
|
2021-07-30 01:39:31 +03:00
|
|
|
|
|
|
|
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 {
|
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-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),
|
2021-06-15 00:42:21 +03:00
|
|
|
let link = url.dropFirst(prefix.count).removingPercentEncoding {
|
2021-07-30 01:39:31 +03:00
|
|
|
if didFinishLaunching {
|
|
|
|
agent.processInputLink(link)
|
|
|
|
} else {
|
|
|
|
initialInputLink = link
|
|
|
|
}
|
2021-06-15 00:08:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-12 18:48:23 +03:00
|
|
|
}
|