Fix crash when MongoController connection fails
This commit is contained in:
parent
98179767ca
commit
bb695fbf53
|
@ -28,21 +28,23 @@ class DatabaseWindowController: NSWindowController {
|
|||
override func windowDidLoad() {
|
||||
super.windowDidLoad()
|
||||
|
||||
if mongoController == nil {
|
||||
let setupMongo = mongoController == nil
|
||||
if setupMongo {
|
||||
mongoController = MongoController(connectionString: "mongodb://localhost:27017")
|
||||
mongoController.setup()
|
||||
}
|
||||
mongoController.statusDidChange.append({ [weak self] (status) in
|
||||
guard let self = self else { return }
|
||||
self.updateStatusText(status)
|
||||
|
||||
if status == .success {
|
||||
DispatchQueue.main.async {
|
||||
self.initializeUI()
|
||||
}
|
||||
}
|
||||
})
|
||||
self.updateStatusText(mongoController.status)
|
||||
|
||||
databaseViewController = DatabaseViewController(mongoController: mongoController)
|
||||
contentViewController = databaseViewController
|
||||
|
||||
if let initialCollection = initialCollection {
|
||||
databaseViewController.showCollection(initialCollection)
|
||||
if setupMongo {
|
||||
mongoController.setup()
|
||||
}
|
||||
|
||||
titleObservation = observe(\.contentViewController?.title) { [unowned self] (_, _) in
|
||||
|
@ -60,7 +62,7 @@ class DatabaseWindowController: NSWindowController {
|
|||
}
|
||||
|
||||
private func updateWindowTitle() {
|
||||
window?.title = databaseViewController.title ?? "MongoView"
|
||||
window?.title = databaseViewController?.title ?? "MongoView"
|
||||
}
|
||||
|
||||
private func updateStatusText(_ status: MongoController.Status) {
|
||||
|
@ -75,6 +77,15 @@ class DatabaseWindowController: NSWindowController {
|
|||
}
|
||||
}
|
||||
|
||||
private func initializeUI() {
|
||||
databaseViewController = DatabaseViewController(mongoController: mongoController)
|
||||
contentViewController = databaseViewController
|
||||
|
||||
if let initialCollection = initialCollection {
|
||||
databaseViewController.showCollection(initialCollection)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension NSToolbarItem.Identifier {
|
||||
|
|
Loading…
Reference in New Issue