mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-21 05:46:03 +00:00
Re-enable automatic AP isolation checker
This commit is contained in:
1 parent
7c18c73c82
commit
bf6093e299
4 files changed
+69
-43
No files matched your search
+38
-25
@@ -85,29 +85,29 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
|||||||
|
|
||||||
UNUserNotificationCenter.current().delegate = self
|
UNUserNotificationCenter.current().delegate = self
|
||||||
|
|
||||||
// let monitor = NWPathMonitor()
|
let monitor = NWPathMonitor()
|
||||||
// monitor.pathUpdateHandler = { path in
|
monitor.pathUpdateHandler = { path in
|
||||||
// if path.status == .satisfied {
|
if path.status == .satisfied {
|
||||||
// if path.supportsIPv4 && !path.supportsIPv6 {
|
if path.supportsIPv4 && !path.supportsIPv6 {
|
||||||
// log("Detected IPv4-only network.")
|
log("Detected IPv4-only network.")
|
||||||
// self.performDeviceToDeviceCheck()
|
self.performDeviceToDeviceCheck()
|
||||||
// } else if !path.supportsIPv4 && path.supportsIPv6 {
|
} else if !path.supportsIPv4 && path.supportsIPv6 {
|
||||||
// log("IPv6-only network, likely iPhone hotspot. Skipping device-to-device check.")
|
log("IPv6-only network, likely iPhone hotspot. Skipping device-to-device check.")
|
||||||
// } else if path.supportsIPv4 && path.supportsIPv6 {
|
} else if path.supportsIPv4 && path.supportsIPv6 {
|
||||||
// log("Detected Dual stack network.")
|
log("Detected Dual stack network.")
|
||||||
// self.performDeviceToDeviceCheck()
|
self.performDeviceToDeviceCheck()
|
||||||
// } else {
|
} else {
|
||||||
// log("Detected no IP support")
|
log("Detected no IP support")
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// log("Network unavailable")
|
log("Network unavailable")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// monitor.cancel()
|
monitor.cancel()
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// let queue = DispatchQueue(label: "NetworkMonitor")
|
let queue = DispatchQueue(label: "NetworkMonitor")
|
||||||
// monitor.start(queue: queue)
|
monitor.start(queue: queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func performDeviceToDeviceCheck() {
|
func performDeviceToDeviceCheck() {
|
||||||
@@ -117,7 +117,20 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
|||||||
log("✅ Device-to-device likely allowed (peer responded on LAN).")
|
log("✅ Device-to-device likely allowed (peer responded on LAN).")
|
||||||
self.apIsolationAlertWindow?.close()
|
self.apIsolationAlertWindow?.close()
|
||||||
} else {
|
} else {
|
||||||
self.openAlert(type: .ApIsolation)
|
|
||||||
|
log("❌ First check failed. Retrying in 10 seconds...")
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
|
||||||
|
scanner.scan { allowed in
|
||||||
|
if allowed {
|
||||||
|
log("✅ Device-to-device likely allowed (peer responded on LAN).")
|
||||||
|
self.apIsolationAlertWindow?.close()
|
||||||
|
} else {
|
||||||
|
log("❌ Second check failed. Informing user...")
|
||||||
|
self.openAlert(type: .ApIsolation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +222,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
|||||||
switch type {
|
switch type {
|
||||||
case .ApIsolation:
|
case .ApIsolation:
|
||||||
apIsolationAlertWindow = alertWindow
|
apIsolationAlertWindow = alertWindow
|
||||||
alertWindow.contentView = NSHostingView(rootView: ApIsolationIssueView())
|
alertWindow.contentView = NSHostingView(rootView: ApIsolationIssueView(closeView: { self.apIsolationAlertWindow?.close() }))
|
||||||
case .NetworkFilter:
|
case .NetworkFilter:
|
||||||
networkFilterAlertWindow = alertWindow
|
networkFilterAlertWindow = alertWindow
|
||||||
alertWindow.contentView = NSHostingView(rootView: NetworkFilterIssueView())
|
alertWindow.contentView = NSHostingView(rootView: NetworkFilterIssueView())
|
||||||
|
|||||||
@@ -13,12 +13,38 @@ import Network
|
|||||||
struct ApIsolationIssueView: View {
|
struct ApIsolationIssueView: View {
|
||||||
|
|
||||||
@Environment(\.colorScheme) var colorScheme
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
let closeView : () -> Void
|
||||||
|
|
||||||
|
let scanner = DeviceToDeviceHeuristicScanner()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
||||||
IssueView(image: .router, header: "ApIsolationHeader".localized(), description: "ApIsolationDescription".localized(), actionLabel: "ApIsolationAction".localized()) {
|
IssueView(image: .router, header: "ApIsolationHeader".localized(), description: "ApIsolationDescription".localized(), actionLabel: "ApIsolationAction".localized()) {
|
||||||
await openRouterSettingsPage()
|
await openRouterSettingsPage()
|
||||||
}
|
}
|
||||||
|
.onAppear {
|
||||||
|
checkIfApIsolationStillEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkIfApIsolationStillEnabled() {
|
||||||
|
scanner.scan { isConnectionAllowed in
|
||||||
|
if isConnectionAllowed {
|
||||||
|
|
||||||
|
log("AP Isolation is no longer enabled. Exiting...")
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
closeView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log("AP Isolation is still enabled. Checking again in 10 seconds...")
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
|
||||||
|
checkIfApIsolationStillEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +147,7 @@ func isHostReachable(_ host: String) -> Bool {
|
|||||||
|
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
ApIsolationIssueView()
|
ApIsolationIssueView(closeView: {})
|
||||||
.frame(width: issueViewWidth, height: issueViewHeight)
|
.frame(width: issueViewWidth, height: issueViewHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,7 +11,6 @@ import Network
|
|||||||
class DeviceToDeviceHeuristicScanner {
|
class DeviceToDeviceHeuristicScanner {
|
||||||
private let scanQueue = DispatchQueue(label: "DeviceToDeviceScanQueue")
|
private let scanQueue = DispatchQueue(label: "DeviceToDeviceScanQueue")
|
||||||
private var reachableIPs = [String]()
|
private var reachableIPs = [String]()
|
||||||
private var scannedCount = 0
|
|
||||||
private var totalToScan = 0
|
private var totalToScan = 0
|
||||||
private var completion: ((Bool) -> Void)?
|
private var completion: ((Bool) -> Void)?
|
||||||
|
|
||||||
@@ -30,10 +29,8 @@ class DeviceToDeviceHeuristicScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Timeout fallback
|
// Timeout fallback
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 6.0) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
|
||||||
if self.scannedCount < self.totalToScan {
|
self.finish()
|
||||||
self.finish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,11 +42,10 @@ class DeviceToDeviceHeuristicScanner {
|
|||||||
switch state {
|
switch state {
|
||||||
case .ready:
|
case .ready:
|
||||||
self.reachableIPs.append(ip)
|
self.reachableIPs.append(ip)
|
||||||
|
self.finish()
|
||||||
connection.cancel()
|
connection.cancel()
|
||||||
self.hostFinished()
|
|
||||||
case .failed, .cancelled:
|
case .failed, .cancelled:
|
||||||
connection.cancel()
|
connection.cancel()
|
||||||
self.hostFinished()
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -58,15 +54,9 @@ class DeviceToDeviceHeuristicScanner {
|
|||||||
connection.start(queue: scanQueue)
|
connection.start(queue: scanQueue)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func hostFinished() {
|
|
||||||
scannedCount += 1
|
|
||||||
if scannedCount == totalToScan {
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func finish() {
|
private func finish() {
|
||||||
completion?(reachableIPs.count > 0)
|
completion?(reachableIPs.count > 0)
|
||||||
|
completion = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to detect the local subnet prefix (e.g., "192.168.0")
|
/// Attempts to detect the local subnet prefix (e.g., "192.168.0")
|
||||||
|
|||||||
@@ -93,9 +93,6 @@ struct WelcomeScreen: View {
|
|||||||
|
|
||||||
case .troubleshooting:
|
case .troubleshooting:
|
||||||
TutorialView(title: "Troubleshooting", text: "TroubleshootingDescription", showsLicense: false, openIAP: openPlusScreen)
|
TutorialView(title: "Troubleshooting", text: "TroubleshootingDescription", showsLicense: false, openIAP: openPlusScreen)
|
||||||
.onAppear {
|
|
||||||
checkForNetworkIssues()
|
|
||||||
}
|
|
||||||
|
|
||||||
case .app:
|
case .app:
|
||||||
TutorialView(title: "AndroidApp", text: "AndroidAppDescription", showsLicense: false, showsBetaJoinButton: true, openIAP: openPlusScreen)
|
TutorialView(title: "AndroidApp", text: "AndroidAppDescription", showsLicense: false, showsBetaJoinButton: true, openIAP: openPlusScreen)
|
||||||
|
|||||||
Reference in new issue
Block a user