Skip to content

Commit

Permalink
Don't trigger the timer if no networks for auto join were stored
Browse files Browse the repository at this point in the history
  • Loading branch information
williambj1 committed Mar 2, 2021
1 parent 261499b commit 5f3c9a6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions HeliPort/NetworkManager.swift
Expand Up @@ -111,18 +111,23 @@ final class NetworkManager {

class func scanSavedNetworks() {
DispatchQueue.global(qos: .background).async {
let savedNetworks: [NetworkInfo] = CredentialsManager.instance.getSavedNetworks()
guard savedNetworks.count > 0 else {
Log.debug("No network saved for auto join")
return
}
var targetNetworks: [NetworkInfo]?
let dispatchSemaphore = DispatchSemaphore(value: 0)
let scanTimer: Timer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { timer in
let dispatchSemaphore = DispatchSemaphore(value: 0)
var targetNetworks: [NetworkInfo]?
NetworkManager.scanNetwork { networkList in
targetNetworks = CredentialsManager.instance.getSavedNetworks().filter { networkList.contains($0) }
targetNetworks = savedNetworks.filter { networkList.contains($0) }
dispatchSemaphore.signal()
}
dispatchSemaphore.wait()
if targetNetworks != nil, targetNetworks!.count > 0 {
// This will stop the timer completely
timer.invalidate()
Log.debug("Auto connect timer stopped")
Log.debug("Auto join timer stopped")
connectSavedNetworks(networks: targetNetworks!)
}
}
Expand Down

0 comments on commit 5f3c9a6

Please sign in to comment.