diff --git a/MongoView/AppDelegate.swift b/MongoView/AppDelegate.swift index a8fa5ef..db16343 100644 --- a/MongoView/AppDelegate.swift +++ b/MongoView/AppDelegate.swift @@ -16,9 +16,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { var serverConnectWindowController: ServerConnectWindowController? func applicationDidFinishLaunching(_ aNotification: Notification) { - let wc = DatabaseWindowController() - windowControllers.append(wc) - wc.showWindow(nil) + newWindow(mongoController: nil) } func applicationWillTerminate(_ aNotification: Notification) { @@ -31,7 +29,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { windowControllers.append(wc) if addToTabGroup, - let tabGroup = windowControllers.first(where: { $0.window!.isKeyWindow })?.window?.tabGroup { + let existing = windowControllers.first(where: { $0.window!.isKeyWindow })?.window, + let tabGroup = existing.tabGroup { tabGroup.addWindow(wc.window!) tabGroup.selectedWindow = wc.window! } else { diff --git a/MongoView/Windows/DatabaseWindowController.swift b/MongoView/Windows/DatabaseWindowController.swift index d08b082..8fde203 100644 --- a/MongoView/Windows/DatabaseWindowController.swift +++ b/MongoView/Windows/DatabaseWindowController.swift @@ -41,10 +41,14 @@ class DatabaseWindowController: NSWindowController { .receive(on: DispatchQueue.main) .sink { self.updateStatusText(manager: $0) } - connectionStatusChangeHandler = mongoController.$status - .receive(on: DispatchQueue.main) - .filter { $0 == .connected } - .sink { (_) in self.initializeUI() } + if mongoController.client != nil { + initializeUI() + } else { + connectionStatusChangeHandler = mongoController.$status + .receive(on: DispatchQueue.main) + .filter { $0 == .connected } + .sink { (_) in self.initializeUI() } + } if setupMongo { mongoController.setup() @@ -89,8 +93,10 @@ class DatabaseWindowController: NSWindowController { private func initializeUI() { databaseViewController = DatabaseViewController(mongoController: mongoController) + // otherwise the VC size uses the size from the nib, potentially changing the window size + databaseViewController.view.frame = CGRect(origin: .zero, size: window!.frame.size) contentViewController = databaseViewController - + if let initialCollection = initialCollection { databaseViewController.showCollection(initialCollection) }