@@ -329,7 +329,7 @@ class HomeViewController: BaseViewController, AwesomeSpotlightViewDelegate, Load
329
329
@objc func tunnelStatusDidChange( _ notification: Notification ) {
330
330
// Firewall
331
331
if let tunnelProviderSession = notification. object as? NETunnelProviderSession {
332
- DDLogInfo ( " VPNStatusDidChange as NETunnelProviderSession with status: \( tunnelProviderSession. status. rawValue ) " ) ;
332
+ DDLogInfo ( " VPNStatusDidChange as NETunnelProviderSession with status: \( tunnelProviderSession. status. description ) " ) ;
333
333
if ( !getUserWantsFirewallEnabled( ) ) {
334
334
updateFirewallButtonWithStatus ( status: . disconnected)
335
335
}
@@ -346,7 +346,7 @@ class HomeViewController: BaseViewController, AwesomeSpotlightViewDelegate, Load
346
346
}
347
347
// VPN
348
348
else if let neVPNConnection = notification. object as? NEVPNConnection {
349
- DDLogInfo ( " VPNStatusDidChange as NEVPNConnection with status: \( neVPNConnection. status. rawValue ) " ) ;
349
+ DDLogInfo ( " VPNStatusDidChange as NEVPNConnection with status: \( neVPNConnection. status. description ) " ) ;
350
350
updateVPNButtonWithStatus ( status: neVPNConnection. status) ;
351
351
updateVPNRegionLabel ( )
352
352
if NEVPNManager . shared ( ) . connection. status == . connected || NEVPNManager . shared ( ) . connection. status == . disconnected {
@@ -505,9 +505,11 @@ class HomeViewController: BaseViewController, AwesomeSpotlightViewDelegate, Load
505
505
switch FirewallController . shared. status ( ) {
506
506
case . invalid:
507
507
FirewallController . shared. setEnabled ( true , isUserExplicitToggle: true )
508
+ ensureFirewallWorkingAfterEnabling ( waitingSeconds: 3.0 )
508
509
case . disconnected:
509
510
updateFirewallButtonWithStatus ( status: . connecting)
510
511
FirewallController . shared. setEnabled ( true , isUserExplicitToggle: true )
512
+ ensureFirewallWorkingAfterEnabling ( waitingSeconds: 3.0 )
511
513
512
514
checkForAskRating ( )
513
515
case . connected:
@@ -518,6 +520,35 @@ class HomeViewController: BaseViewController, AwesomeSpotlightViewDelegate, Load
518
520
}
519
521
}
520
522
523
+ func ensureFirewallWorkingAfterEnabling( waitingSeconds: TimeInterval ) {
524
+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + waitingSeconds) {
525
+ DDLogInfo ( " \( waitingSeconds) seconds passed, checking if Firewall is enabled " )
526
+ guard getUserWantsFirewallEnabled ( ) else {
527
+ // firewall shouldn't be enabled, no need to act
528
+ DDLogInfo ( " User doesn't want Firewall enabled, no action " )
529
+ return
530
+ }
531
+
532
+ let status = FirewallController . shared. status ( )
533
+ switch status {
534
+ case . connecting, . disconnecting, . reasserting:
535
+ // check again in three seconds
536
+ DDLogInfo ( " Firewall is in transient state, will check again in 3 seconds " )
537
+ self . ensureFirewallWorkingAfterEnabling ( waitingSeconds: 3.0 )
538
+ case . connected:
539
+ // all good
540
+ DDLogInfo ( " Firewall is connected, no action " )
541
+ break
542
+ case . disconnected, . invalid:
543
+ // we suppose that the connection is somehow broken, trying to fix
544
+ DDLogInfo ( " Firewall is not connected even though it should be, attempting to fix " )
545
+ self . showFixFirewallConnectionDialog {
546
+ FirewallController . shared. deleteConfigurationAndAddAgain ( )
547
+ }
548
+ }
549
+ }
550
+ }
551
+
521
552
func updateFirewallButtonWithStatus( status: NEVPNStatus ) {
522
553
DDLogInfo ( " UpdateFirewallButton " )
523
554
switch status {
@@ -1008,3 +1039,24 @@ final class DynamicButton: PopupDialogButton {
1008
1039
}
1009
1040
}
1010
1041
}
1042
+
1043
+ extension NEVPNStatus : CustomStringConvertible {
1044
+
1045
+ public var description : String {
1046
+ switch self {
1047
+ case . invalid:
1048
+ return " invalid "
1049
+ case . disconnected:
1050
+ return " disconnected "
1051
+ case . connecting:
1052
+ return " connecting "
1053
+ case . connected:
1054
+ return " connected "
1055
+ case . reasserting:
1056
+ return " reasserting "
1057
+ case . disconnecting:
1058
+ return " disconnecting "
1059
+ }
1060
+ }
1061
+
1062
+ }
0 commit comments