mirror of
https://github.com/lil-org/wallet.git
synced 2025-01-04 02:24:39 +03:00
Add network monitor
This commit is contained in:
parent
6ac6e66fb7
commit
45bdb393bc
@ -22,6 +22,8 @@
|
||||
0DB7291E2674E2DB0011F7A1 /* EIP712Signable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB7290F2674E2DB0011F7A1 /* EIP712Signable.swift */; };
|
||||
0DB7291F2674E2DB0011F7A1 /* EIP712Representable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB729102674E2DB0011F7A1 /* EIP712Representable.swift */; };
|
||||
0DB729202674E2DB0011F7A1 /* EIP712Domain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB729112674E2DB0011F7A1 /* EIP712Domain.swift */; };
|
||||
2C03D1D2269B407900EF10EA /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C03D1D1269B407900EF10EA /* NetworkMonitor.swift */; };
|
||||
2C03D1D5269B428C00EF10EA /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C03D1D4269B428C00EF10EA /* Notification.swift */; };
|
||||
2C1995402674C4B900A8E370 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C19953F2674C4B900A8E370 /* AppDelegate.swift */; };
|
||||
2C1995422674C4B900A8E370 /* ImportViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C1995412674C4B900A8E370 /* ImportViewController.swift */; };
|
||||
2C1995442674C4BA00A8E370 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2C1995432674C4BA00A8E370 /* Assets.xcassets */; };
|
||||
@ -69,6 +71,8 @@
|
||||
0DB729102674E2DB0011F7A1 /* EIP712Representable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EIP712Representable.swift; sourceTree = "<group>"; };
|
||||
0DB729112674E2DB0011F7A1 /* EIP712Domain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EIP712Domain.swift; sourceTree = "<group>"; };
|
||||
100FF49FA53ACCE128D86D88 /* Pods_Encrypted_Ink.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Encrypted_Ink.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2C03D1D1269B407900EF10EA /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = "<group>"; };
|
||||
2C03D1D4269B428C00EF10EA /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
|
||||
2C19953C2674C4B900A8E370 /* Encrypted Ink.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Encrypted Ink.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2C19953F2674C4B900A8E370 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
2C1995412674C4B900A8E370 /* ImportViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportViewController.swift; sourceTree = "<group>"; };
|
||||
@ -199,6 +203,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2C6706A4267A6BFE006AAEF2 /* Bundle.swift */,
|
||||
2C03D1D4269B428C00EF10EA /* Notification.swift */,
|
||||
2CC89470269A334A00879245 /* UserDefaults.swift */,
|
||||
);
|
||||
path = Extensions;
|
||||
@ -243,6 +248,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2C8A09B42675101300993638 /* AccountsService.swift */,
|
||||
2C03D1D1269B407900EF10EA /* NetworkMonitor.swift */,
|
||||
2C901C4C268A033100D0926A /* GasService.swift */,
|
||||
2CC0CDBD2692027E0072922A /* PriceService.swift */,
|
||||
2CC8946E269A2E8C00879245 /* SessionStorage.swift */,
|
||||
@ -412,6 +418,7 @@
|
||||
0DB729162674E2DB0011F7A1 /* EIP712SimpleValue.swift in Sources */,
|
||||
0DB729122674E2DB0011F7A1 /* EIP712ParameterEncoder.swift in Sources */,
|
||||
2C8A09D726751A0C00993638 /* WalletConnect.swift in Sources */,
|
||||
2C03D1D2269B407900EF10EA /* NetworkMonitor.swift in Sources */,
|
||||
2C8A09E326757FC000993638 /* AccountCellView.swift in Sources */,
|
||||
0DB729202674E2DB0011F7A1 /* EIP712Domain.swift in Sources */,
|
||||
0DB729182674E2DB0011F7A1 /* EIP712Signer.swift in Sources */,
|
||||
@ -437,6 +444,7 @@
|
||||
0DB7291E2674E2DB0011F7A1 /* EIP712Signable.swift in Sources */,
|
||||
0DB7291C2674E2DB0011F7A1 /* EIP712Value.swift in Sources */,
|
||||
2C8A09EB2675964700993638 /* ApproveViewController.swift in Sources */,
|
||||
2C03D1D5269B428C00EF10EA /* Notification.swift in Sources */,
|
||||
2C1995562674D0F300A8E370 /* Ethereum.swift in Sources */,
|
||||
2C8A09DF267579EA00993638 /* AccountsListViewController.swift in Sources */,
|
||||
2C917429267D2A6E00049075 /* Keychain.swift in Sources */,
|
||||
|
@ -8,6 +8,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private let agent = Agent.shared
|
||||
private let gasService = GasService.shared
|
||||
private let priceService = PriceService.shared
|
||||
private let networkMonitor = NetworkMonitor.shared
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
@ -29,6 +30,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
agent.start()
|
||||
gasService.start()
|
||||
priceService.start()
|
||||
networkMonitor.start()
|
||||
}
|
||||
|
||||
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
||||
|
7
Encrypted Ink/Extensions/Notification.swift
Normal file
7
Encrypted Ink/Extensions/Notification.swift
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Notification.Name {
|
||||
static let connectionAppeared = Notification.Name("connectionAppeared")
|
||||
}
|
31
Encrypted Ink/Services/NetworkMonitor.swift
Normal file
31
Encrypted Ink/Services/NetworkMonitor.swift
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import CoreTelephony
|
||||
import Network
|
||||
|
||||
class NetworkMonitor {
|
||||
|
||||
var hasConnection = true
|
||||
static let shared = NetworkMonitor()
|
||||
|
||||
private let nwPathMonitor = NWPathMonitor()
|
||||
private init() {}
|
||||
|
||||
func start() {
|
||||
let queue = DispatchQueue(label: "NetworkMonitor")
|
||||
nwPathMonitor.start(queue: queue)
|
||||
nwPathMonitor.pathUpdateHandler = { [weak self] path in
|
||||
let hasConnectionNow = path.status == .satisfied
|
||||
if self?.hasConnection != hasConnectionNow {
|
||||
DispatchQueue.main.async {
|
||||
self?.hasConnection = hasConnectionNow
|
||||
if hasConnectionNow {
|
||||
NotificationCenter.default.post(name: Notification.Name.connectionAppeared, object: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user