Skip to content

Commit 5f3c9a6

Browse files
committed
Don't trigger the timer if no networks for auto join were stored
1 parent 261499b commit 5f3c9a6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

HeliPort/NetworkManager.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,23 @@ final class NetworkManager {
111111

112112
class func scanSavedNetworks() {
113113
DispatchQueue.global(qos: .background).async {
114+
let savedNetworks: [NetworkInfo] = CredentialsManager.instance.getSavedNetworks()
115+
guard savedNetworks.count > 0 else {
116+
Log.debug("No network saved for auto join")
117+
return
118+
}
119+
var targetNetworks: [NetworkInfo]?
120+
let dispatchSemaphore = DispatchSemaphore(value: 0)
114121
let scanTimer: Timer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { timer in
115-
let dispatchSemaphore = DispatchSemaphore(value: 0)
116-
var targetNetworks: [NetworkInfo]?
117122
NetworkManager.scanNetwork { networkList in
118-
targetNetworks = CredentialsManager.instance.getSavedNetworks().filter { networkList.contains($0) }
123+
targetNetworks = savedNetworks.filter { networkList.contains($0) }
119124
dispatchSemaphore.signal()
120125
}
121126
dispatchSemaphore.wait()
122127
if targetNetworks != nil, targetNetworks!.count > 0 {
123128
// This will stop the timer completely
124129
timer.invalidate()
125-
Log.debug("Auto connect timer stopped")
130+
Log.debug("Auto join timer stopped")
126131
connectSavedNetworks(networks: targetNetworks!)
127132
}
128133
}

0 commit comments

Comments
 (0)