mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-19 12:56:06 +00:00
Fix: Firewall alert would open two alerts
This commit is contained in:
1 parent
dc32e92d9a
commit
e638479203
5 files changed
+7
-54
No files matched your search
@@ -99,10 +99,8 @@ class NearbyConnection {
|
||||
|
||||
// If the error is a connection reset, it could be due to firewall issues.
|
||||
if err == .posix(.ENOTCONN) {
|
||||
log("[NearbyConnection \(self.id)] Network not connected error detected.")
|
||||
ConnectionFailureTracker.shared.recordFailure {
|
||||
NearbyConnectionManager.shared.mainAppDelegate?.showFirewallAlert()
|
||||
}
|
||||
log("[NearbyConnection \(self.id)] Network not connected error detected (firewall likely).")
|
||||
self.lastError = NearbyError.firewallError
|
||||
}
|
||||
|
||||
if err == .posix(.ENETDOWN) {
|
||||
|
||||
@@ -27,7 +27,6 @@ protocol OutboundNearbyConnectionDelegate {
|
||||
public protocol MainAppDelegate {
|
||||
func obtainUserConsent(for transfer: TransferMetadata, from device: RemoteDeviceInfo)
|
||||
func incomingTransfer(id: String, didFinishWith error: Error?)
|
||||
func showFirewallAlert()
|
||||
func showCopiedToClipboardAlert()
|
||||
func showUnsupportedFileAlert(for: RemoteDeviceInfo?)
|
||||
}
|
||||
@@ -164,6 +163,7 @@ public enum NearbyError: Error {
|
||||
case requiredFieldMissing(_ message: String)
|
||||
case ukey2
|
||||
case packetFilterError
|
||||
case firewallError
|
||||
case inputOutput
|
||||
case canceled(reason: CancellationReason)
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user