@@ -63,19 +63,23 @@ class UI: StoreSubscriber {
6363 return Application . supportPath. appendingPathComponent ( " ui " )
6464 }
6565
66- static let storyboard = NSStoryboard ( name: " Main " , bundle: Bundle . main)
6766 static let statusItem = StatusItem ( image: NSImage ( named: " statusBarIcon " ) !)
68-
69- static var windowController : NSWindowController = ( storyboard. instantiateController ( withIdentifier: " EQMWindowController " ) as! NSWindowController )
70- static var window : Window = ( windowController. window! as! Window )
71- static var viewController = ( storyboard. instantiateController ( withIdentifier: " EQMViewController " ) as! ViewController )
7267
68+ static let storyboard = NSStoryboard ( name: " Main " , bundle: Bundle . main)
69+
70+ static var windowController : NSWindowController = (
71+ storyboard. instantiateController (
72+ withIdentifier: " EQMWindowController "
73+ ) as! NSWindowController )
74+ static var window : Window = ( windowController. window! as! Window )
7375 static var popover = Popover ( statusItem)
7476
75-
76- static let loadingWindowController = storyboard. instantiateController ( withIdentifier: " LoadingWindow " ) as! NSWindowController
77- // var popover: Popover!
78-
77+ static var viewController = (
78+ storyboard. instantiateController (
79+ withIdentifier: " EQMViewController "
80+ ) as! ViewController )
81+
82+
7983 static var cachedIsShown : Bool = false
8084 static var isShownChanged = Event < Bool > ( )
8185 static var isShown : Bool {
@@ -129,16 +133,15 @@ class UI: StoreSubscriber {
129133 window. resignFirstResponder ( )
130134 window. contentViewController = nil
131135 popover. popover. contentViewController = viewController
132- popover. show ( )
133136 popover. popover. becomeFirstResponder ( )
134137 } else {
135138 popover. hide ( )
136139 popover. popover. resignFirstResponder ( )
137140 popover. popover. contentViewController = nil
138141 window. contentViewController = viewController
139- window. show ( )
140142 window. becomeFirstResponder ( )
141143 }
144+ UI . show ( )
142145 }
143146 }
144147 }
@@ -202,32 +205,46 @@ class UI: StoreSubscriber {
202205
203206 init ( _ completion: @escaping ( ) -> Void ) {
204207 DispatchQueue . main. async {
205- ( {
206- UI . mode = Application . store. state. ui. mode
207- UI . width = Application . store. state. ui. width
208- UI . height = Application . store. state. ui. height
209- } ) ( )
210208
211- // TODO: Fix window position state saving (need to look if the current position is still accessible, what if the monitor isn't there anymore)
212- // if let windowPosition = Application.store.state.ui.windowPosition {
213- // window.position = windowPosition
214- // }
215- self . setupStateListener ( )
216- UI . setupBridge ( )
217- UI . setupListeners ( )
218- UI . load ( )
209+ func setup ( ) {
210+ ( {
211+ UI . mode = Application . store. state. ui. mode
212+ UI . width = Application . store. state. ui. width
213+ UI . height = Application . store. state. ui. height
214+ } ) ( )
219215
220- func checkIfVisible ( ) {
221- let shown = UI . isShown
222- if ( UI . cachedIsShown != shown) {
223- UI . cachedIsShown = shown
224- UI . isShownChanged. emit ( shown)
216+ // TODO: Fix window position state saving (need to look if the current position is still accessible, what if the monitor isn't there anymore)
217+ // if let windowPosition = Application.store.state.ui.windowPosition {
218+ // window.position = windowPosition
219+ // }
220+ self . setupStateListener ( )
221+ UI . setupBridge ( )
222+ UI . setupListeners ( )
223+ UI . load ( )
224+
225+ func checkIfVisible ( ) {
226+ let shown = UI . isShown
227+ if ( UI . cachedIsShown != shown) {
228+ UI . cachedIsShown = shown
229+ UI . isShownChanged. emit ( shown)
230+ }
231+ Utilities . delay ( 1000 ) { checkIfVisible ( ) }
225232 }
226- Utilities . delay ( 1000 ) { checkIfVisible ( ) }
233+
234+ checkIfVisible ( )
235+ completion ( )
227236 }
228237
229- checkIfVisible ( )
230- completion ( )
238+ if ( !UI. viewController. isViewLoaded) {
239+ UI . viewController. loaded. once {
240+ setup ( )
241+ }
242+ let _ = UI . viewController. view
243+ } else {
244+ setup ( )
245+ }
246+
247+
231248 }
232249
233250 }
0 commit comments