Repository: CodeEditApp/CodeEdit
File: CodeEdit/AppDelegate.swift (Swift)

Code before:
    @IBAction func openWelcome(_ sender: Any) {
        if let window = NSApp.windows.filter({ window in
            return (window.contentView as? NSHostingView<WelcomeWindowView>) != nil
        }).first {
            window.makeKeyAndOrderFront(self)
            return
        }

        let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 800, height: 460),
                              styleMask: [.titled, .fullSizeContentView], backing: .buffered, defer: false)
        let windowController = NSWindowController(window: window)
        window.center()
        let contentView = WelcomeWindowView(
            openDocument: { url, opened in
                if let url = url {
                    CodeEditDocumentController.shared.openDocument(
                        withContentsOf: url,
                        display: true
                    ) { doc, _, _ in
                        if doc != nil {
                            opened()
                        }
                    }

                }
                else {
                    windowController.window?.close()
                    CodeEditDocumentController.shared.openDocument(completionHandler: { _, _ in
                        opened()
                    }, cancelHandler: {
                        self.openWelcome(self)
                    })
                }
            },
            newDocument: {
                CodeEditDocumentController.shared.newDocument(nil)
            },
            dismissWindow: {
                windowController.window?.close()
            }
        )
        window.titlebarAppearsTransparent = true
        window.isMovableByWindowBackground = true
        window.contentView = NSHostingView(rootView: contentView)
        window.makeKeyAndOrderFront(self)
    }

    @IBAction func openAbout(_ sender: Any) {
        AboutView().showWindow(width: 530, height: 220)
    }


Review comment (bug):
move the `else` statement to the previous line:

```swift
if ... { 
  ...
} else {
  …
}
```

having it on a new line fails in `SwiftLint`

Code after:
    @IBAction func openWelcome(_ sender: Any) {
        if let window = NSApp.windows.filter({ window in
            return (window.contentView as? NSHostingView<WelcomeWindowView>) != nil
        }).first {
            window.makeKeyAndOrderFront(self)
            return
        }

        let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 800, height: 460),
                              styleMask: [.titled, .fullSizeContentView], backing: .buffered, defer: false)
        let windowController = NSWindowController(window: window)
        window.center()
        let contentView = WelcomeWindowView(
            openDocument: { url, opened in
                if let url = url {
                    CodeEditDocumentController.shared.openDocument(
                        withContentsOf: url,
                        display: true
                    ) { doc, _, _ in
                        if doc != nil {
                            opened()
                        }
                    }

                } else {
                    windowController.window?.close()
                    CodeEditDocumentController.shared.openDocument(onCompletion: { _, _ in
                        opened()
                    }, onCancel: {
                        self.openWelcome(self)
                    })
                }
            },
            newDocument: {
                CodeEditDocumentController.shared.newDocument(nil)
            },
            dismissWindow: {
                windowController.window?.close()
            }
        )
        window.titlebarAppearsTransparent = true
        window.isMovableByWindowBackground = true
        window.contentView = NSHostingView(rootView: contentView)
        window.makeKeyAndOrderFront(self)
    }

    @IBAction func openAbout(_ sender: Any) {
        AboutView().showWindow(width: 530, height: 220)
    }

    // MARK: - Preferences