@@ -10,7 +10,12 @@ import UIKit
1010
1111/// The Bellerophon manager.
1212public class BellerophonManager : NSObject {
13-
13+
14+ /// Determines if the killswitch or force update view is presenting.
15+ public var isDisplaying : Bool {
16+ return bellerophonWindow. isKeyWindow
17+ }
18+
1419 // MARK: - Initializers
1520
1621 /// The default initializer.
@@ -78,6 +83,30 @@ public class BellerophonManager: NSObject {
7883 }
7984 }
8085
86+ /// Updates the display with the given status.
87+ ///
88+ /// - Parameter status: Kill switch status to check if the kill switch view should be displayed.
89+ @objc public func updateDisplay( _ status: BellerophonObservable ) {
90+ if status. forceUpdate ( ) {
91+ displayForceUpdate ( )
92+ } else if status. apiInactive ( ) {
93+ displayKillSwitch ( )
94+ } else {
95+ dismissKillSwitchIfNeeded ( )
96+ }
97+ }
98+
99+ /// Dismisses the kill switch window.
100+ @objc public func dismissKillSwitchIfNeeded( ) {
101+ guard isDisplaying, let currentEvent = currentEvent else {
102+ return
103+ }
104+ config. delegate? . bellerophonWillDisengage ( self , event: currentEvent)
105+ config. allViews ( ) . forEach { $0. isHidden = true }
106+ mainWindow? . makeKeyAndVisible ( )
107+ bellerophonWindow. isHidden = true
108+ }
109+
81110 /**
82111 Use this function to retrieve and handle app status when the app has background mode enabled.
83112
@@ -101,25 +130,7 @@ public class BellerophonManager: NSObject {
101130 }
102131 }
103132
104- // MARK: internal Methods
105-
106- internal func handleAppStatus( _ status: BellerophonObservable ) {
107- if status. forceUpdate ( ) {
108- if let forceUpdateView = config. forceUpdateView {
109- displayWindow ( for: . forceUpdate( view: forceUpdateView) )
110- }
111- config. delegate? . shouldForceUpdate ( )
112- startAutoChecking ( status)
113- } else if status. apiInactive ( ) {
114- if let killSwitchView = config. killSwitchView {
115- displayWindow ( for: . killSwitch( view: killSwitchView) )
116- }
117- config. delegate? . shouldKillSwitch ( )
118- startAutoChecking ( status)
119- } else {
120- dismissKillSwitchIfNeeded ( )
121- }
122- }
133+ // MARK: Internal Methods
123134
124135 @objc internal func stopTimer( ) {
125136 retryTimer? . invalidate ( )
@@ -130,6 +141,28 @@ public class BellerophonManager: NSObject {
130141 config. delegate? . receivedError ( error: error)
131142 }
132143
144+ internal func handleAppStatus( _ status: BellerophonObservable ) {
145+ updateDisplay ( status)
146+
147+ if ( status. forceUpdate ( ) || status. apiInactive ( ) ) {
148+ startAutoChecking ( status)
149+ }
150+ }
151+
152+ internal func displayForceUpdate( ) {
153+ if let forceUpdateView = config. forceUpdateView {
154+ displayWindow ( for: . forceUpdate( view: forceUpdateView) )
155+ }
156+ config. delegate? . shouldForceUpdate ( )
157+ }
158+
159+ internal func displayKillSwitch( ) {
160+ if let killSwitchView = config. killSwitchView {
161+ displayWindow ( for: . killSwitch( view: killSwitchView) )
162+ }
163+ config. delegate? . shouldKillSwitch ( )
164+ }
165+
133166 internal func displayWindow( for event: BellerophonEvent ) {
134167 let view = event. view
135168 currentEvent = event
@@ -140,16 +173,6 @@ public class BellerophonManager: NSObject {
140173 bellerophonWindow. makeKeyAndVisible ( )
141174 }
142175
143- internal func dismissKillSwitchIfNeeded( ) {
144- guard bellerophonWindow. isKeyWindow, let currentEvent = currentEvent else {
145- return
146- }
147- config. delegate? . bellerophonWillDisengage ( self , event: currentEvent)
148- config. allViews ( ) . forEach { $0. isHidden = true }
149- mainWindow? . makeKeyAndVisible ( )
150- bellerophonWindow. isHidden = true
151- }
152-
153176 internal func startAutoChecking( _ status: BellerophonObservable ) {
154177 if retryTimer == nil {
155178 retryTimer = Timer . scheduledTimer ( timeInterval: status. retryInterval ( ) ,
@@ -159,4 +182,5 @@ public class BellerophonManager: NSObject {
159182 repeats: false )
160183 }
161184 }
185+
162186}
0 commit comments