Skip to content

Commit

Permalink
Update StatusMenu.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyvoxi committed Jul 9, 2024
1 parent d640709 commit d9ebfd9
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions HeliPort/Appearance/StatusMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
private var networkListUpdateTimer: Timer?
private var statusUpdateTimer: Timer?

private var isDisconnecting: Bool = false

// One instance at a time
private lazy var preferenceWindow = PrefsWindow()

private var previousStatus: itl_80211_state = ITL80211_S_INIT
private var status: itl_80211_state = ITL80211_S_INIT {
didSet {
/* Only allow if network card is enabled or if the network card does not load
Expand All @@ -50,15 +47,6 @@ final class StatusMenu: NSMenu, NSMenuDelegate {

statusItem.title = NSLocalizedString(status.description)

// if status changes while connected, it will
// disconnect to ensure Auto Join functionality
// (i.e., preventing it from reconnecting to a network with Auto Join disabled)
if previousStatus == ITL80211_S_RUN && status != ITL80211_S_RUN && !isDisconnecting {
Log.debug("Status changed while connected to a network")
disassociateSSID(disconnectItem)
NetworkManager.scanSavedNetworks()
}

switch status {
case ITL80211_S_INIT:
StatusBarIcon.disconnected()
Expand All @@ -84,7 +72,6 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
default:
StatusBarIcon.error()
}
previousStatus = status
}
}

Expand Down Expand Up @@ -452,7 +439,11 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
}
case .turnWiFiOn:
power_on()
NetworkManager.scanSavedNetworks()
case .turnWiFiOff:
if status == ITL80211_S_RUN {
disassociateSSID(disconnectItem)
}
power_off()
case .joinNetworks:
let joinPop = WiFiConfigWindow()
Expand Down Expand Up @@ -624,16 +615,9 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
let ssid = String(sender.title).replacingOccurrences(of: String.disconnectNet, with: "",
options: .regularExpression,
range: nil)

Log.debug("Temporary disabling line 56 for 2 seconds")
isDisconnecting = true
DispatchQueue.global().async {
dis_associate_ssid(ssid)
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.isDisconnecting = false
Log.debug("Disconnected from \(ssid)")
Log.debug("Line 56 re-enabled after 2 seconds")
}
Log.debug("Disconnected from \(ssid)")
}
}

Expand Down

0 comments on commit d9ebfd9

Please sign in to comment.