@@ -125,16 +125,18 @@ class UI: StoreSubscriber {
125125
126126 static var mode : UIMode = . window {
127127 willSet {
128- if ( newValue == . popover) {
129- window. close ( )
130- window. contentViewController = nil
131- popover. popover. contentViewController = viewController
132- popover. show ( )
133- } else {
134- popover. hide ( )
135- popover. popover. contentViewController = nil
136- window. contentViewController = viewController
137- window. show ( )
128+ DispatchQueue . main. async {
129+ if ( newValue == . popover) {
130+ window. close ( )
131+ window. contentViewController = nil
132+ popover. popover. contentViewController = viewController
133+ popover. show ( )
134+ } else {
135+ popover. hide ( )
136+ popover. popover. contentViewController = nil
137+ window. contentViewController = viewController
138+ window. show ( )
139+ }
138140 }
139141 }
140142 }
@@ -208,34 +210,38 @@ class UI: StoreSubscriber {
208210 static var statusItemClickedListener : EventListener < Void > !
209211 static var bridge : Bridge !
210212
211- init ( ) {
212- UI . window. contentView = UI . viewController. view
213+ init ( _ completion: @escaping ( ) -> Void ) {
214+ DispatchQueue . main. async {
215+ UI . window. contentView = UI . viewController. view
213216
214- ( {
215- UI . mode = Application . store. state. ui. mode
216- UI . width = Application . store. state. ui. width
217- UI . height = Application . store. state. ui. height
218- } ) ( )
219-
220- // TODO: Fix window position state saving (need to look if the current position is still accessible, what if the monitor isn't there anymore)
221- // if let windowPosition = Application.store.state.ui.windowPosition {
222- // window.position = windowPosition
223- // }
224- setupStateListener ( )
225- UI . setupBridge ( )
226- UI . setupListeners ( )
227- UI . load ( )
228-
229- func checkIfVisible ( ) {
230- let shown = UI . isShown
231- if ( UI . cachedIsShown != shown) {
232- UI . cachedIsShown = shown
233- UI . isShownChanged. emit ( shown)
217+ ( {
218+ UI . mode = Application . store. state. ui. mode
219+ UI . width = Application . store. state. ui. width
220+ UI . height = Application . store. state. ui. height
221+ } ) ( )
222+
223+ // TODO: Fix window position state saving (need to look if the current position is still accessible, what if the monitor isn't there anymore)
224+ // if let windowPosition = Application.store.state.ui.windowPosition {
225+ // window.position = windowPosition
226+ // }
227+ self . setupStateListener ( )
228+ UI . setupBridge ( )
229+ UI . setupListeners ( )
230+ UI . load ( )
231+
232+ func checkIfVisible ( ) {
233+ let shown = UI . isShown
234+ if ( UI . cachedIsShown != shown) {
235+ UI . cachedIsShown = shown
236+ UI . isShownChanged. emit ( shown)
237+ }
238+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 1 , execute: checkIfVisible)
234239 }
235- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 1 , execute: checkIfVisible)
240+
241+ checkIfVisible ( )
242+ completion ( )
236243 }
237-
238- checkIfVisible ( )
244+
239245 }
240246
241247 static func reload ( ) {
0 commit comments