mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
@ -248,8 +248,8 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp
|
||||
|
||||
// If we have configuration errors, we need to show them.
|
||||
let c = ConfigurationErrorsController.sharedInstance
|
||||
c.model.errors = state.configErrors()
|
||||
if (c.model.errors.count > 0) {
|
||||
c.errors = state.configErrors()
|
||||
if (c.errors.count > 0) {
|
||||
if (c.window == nil || !c.window!.isVisible) {
|
||||
c.showWindow(self)
|
||||
}
|
||||
|
@ -3,43 +3,31 @@ import Cocoa
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
class ConfigurationErrorsController: NSWindowController, NSWindowDelegate {
|
||||
class ConfigurationErrorsController: NSWindowController, NSWindowDelegate, ConfigurationErrorsViewModel {
|
||||
/// Singleton for the errors view.
|
||||
static let sharedInstance = ConfigurationErrorsController()
|
||||
|
||||
override var windowNibName: NSNib.Name? { "ConfigurationErrors" }
|
||||
|
||||
/// The data model for this view. Update this directly and the associated view will be updated, too.
|
||||
let model = ConfigurationErrorsView.Model()
|
||||
|
||||
private var cancellable: AnyCancellable?
|
||||
@Published var errors: [String] = [] {
|
||||
didSet {
|
||||
if (errors.count == 0) {
|
||||
self.window?.performClose(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - NSWindowController
|
||||
|
||||
override func windowWillLoad() {
|
||||
shouldCascadeWindows = false
|
||||
|
||||
if let c = cancellable { c.cancel() }
|
||||
cancellable = model.$errors.sink { newValue in
|
||||
if (newValue.count == 0) {
|
||||
self.window?.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func windowDidLoad() {
|
||||
guard let window = window else { return }
|
||||
window.center()
|
||||
window.level = .popUpMenu
|
||||
window.contentView = NSHostingView(rootView: ConfigurationErrorsView(model: model))
|
||||
}
|
||||
|
||||
//MARK: - NSWindowDelegate
|
||||
|
||||
func windowWillClose(_ notification: Notification) {
|
||||
if let cancellable = cancellable {
|
||||
cancellable.cancel()
|
||||
self.cancellable = nil
|
||||
}
|
||||
window.contentView = NSHostingView(rootView: ConfigurationErrorsView(model: self))
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ConfigurationErrorsView: View {
|
||||
class Model: ObservableObject {
|
||||
@Published var errors: [String] = []
|
||||
}
|
||||
|
||||
@ObservedObject var model: Model
|
||||
protocol ConfigurationErrorsViewModel: ObservableObject {
|
||||
var errors: [String] { get set }
|
||||
}
|
||||
|
||||
struct ConfigurationErrorsView<ViewModel: ConfigurationErrorsViewModel>: View {
|
||||
@ObservedObject var model: ViewModel
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
|
Reference in New Issue
Block a user