mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-21 22:05:59 +00:00
Add detection of firewall
This commit is contained in:
1 parent
11a66d0f8a
commit
4c6c7cbd6a
23 files changed
+132
-3
No files matched your search
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// ConnectionFailureTracker.swift
|
||||
// QuickDrop
|
||||
//
|
||||
// Created by Leon Böttger on 15.05.25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class ConnectionFailureTracker {
|
||||
static let shared = ConnectionFailureTracker()
|
||||
|
||||
private var failureTimestamps: [Date] = []
|
||||
private var lastAlertShownAt: Date?
|
||||
|
||||
private let queue = DispatchQueue(label: "ConnectionFailureTrackerQueue")
|
||||
|
||||
private init() {}
|
||||
|
||||
func recordFailure(onTrigger: @escaping () -> Void) {
|
||||
queue.async {
|
||||
let now = Date()
|
||||
|
||||
// Remove old timestamps older than 10 seconds
|
||||
self.failureTimestamps = self.failureTimestamps.filter { now.timeIntervalSince($0) < 10 }
|
||||
self.failureTimestamps.append(now)
|
||||
|
||||
// Check if alert can be shown
|
||||
let canShowAlert = self.failureTimestamps.count >= 2 &&
|
||||
(self.lastAlertShownAt == nil || now.timeIntervalSince(self.lastAlertShownAt!) >= 60)
|
||||
|
||||
if canShowAlert {
|
||||
self.lastAlertShownAt = now
|
||||
self.failureTimestamps.removeAll()
|
||||
DispatchQueue.main.async {
|
||||
onTrigger()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,11 @@ class NearbyConnection {
|
||||
} else if case let .failed(err) = state {
|
||||
self.lastError = err
|
||||
log("Error opening socket: \(err)")
|
||||
|
||||
ConnectionFailureTracker.shared.recordFailure {
|
||||
NearbyConnectionManager.shared.mainAppDelegate?.showFirewallAlert()
|
||||
}
|
||||
|
||||
self.handleConnectionClosure()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ struct EndpointInfo {
|
||||
public protocol MainAppDelegate {
|
||||
func obtainUserConsent(for transfer: TransferMetadata, from device: RemoteDeviceInfo)
|
||||
func incomingTransfer(id: String, didFinishWith error: Error?)
|
||||
func showFirewallAlert()
|
||||
}
|
||||
|
||||
public protocol ShareExtensionDelegate: AnyObject {
|
||||
|
||||
Reference in new issue
Block a user