macos: show warning in debug mode

This commit is contained in:
Mitchell Hashimoto
2023-09-15 15:40:41 -07:00
parent de0f71c6a1
commit f8fea2f65b
2 changed files with 86 additions and 30 deletions

View File

@ -94,6 +94,13 @@ struct PrimaryView: View {
self.appDelegate.confirmQuit = $0 self.appDelegate.confirmQuit = $0
}) })
VStack(spacing: 0) {
// If we're running in debug mode we show a warning so that users
// know that performance will be degraded.
if (ghostty.info.mode == GHOSTTY_BUILD_MODE_DEBUG) {
DebugBuildWarningView()
}
Ghostty.TerminalSplit(onClose: Self.closeWindow, baseConfig: self.baseConfig) Ghostty.TerminalSplit(onClose: Self.closeWindow, baseConfig: self.baseConfig)
.ghosttyApp(ghostty.app!) .ghosttyApp(ghostty.app!)
.ghosttyConfig(ghostty.config!) .ghosttyConfig(ghostty.config!)
@ -128,6 +135,7 @@ struct PrimaryView: View {
} }
} }
} }
}
static func closeWindow() { static func closeWindow() {
guard let currentWindow = NSApp.keyWindow else { return } guard let currentWindow = NSApp.keyWindow else { return }
@ -196,3 +204,34 @@ struct PrimaryView: View {
} }
} }
} }
struct DebugBuildWarningView: View {
@State private var isPopover = false
var body: some View {
HStack {
Spacer()
Image(systemName: "exclamationmark.triangle.fill")
.foregroundColor(.yellow)
Text("You're running a debug build of Ghostty!")
.padding(.all, 8)
.popover(isPresented: $isPopover, arrowEdge: .bottom) {
Text("""
Debug builds of Ghostty are very slow and you may experience
performance problems. Debug builds are only recommended during
development.
""")
.padding(.all)
}
Spacer()
}
.background(Color(.windowBackgroundColor))
.frame(maxWidth: .infinity)
.onTapGesture {
isPopover = true
}
}
}

View File

@ -11,6 +11,11 @@ extension Ghostty {
case loading, error, ready case loading, error, ready
} }
struct Info {
var mode: ghostty_build_mode_e
var version: String
}
/// The AppState is the global state that is associated with the Swift app. This handles initially /// The AppState is the global state that is associated with the Swift app. This handles initially
/// initializing Ghostty, loading the configuration, etc. /// initializing Ghostty, loading the configuration, etc.
class AppState: ObservableObject { class AppState: ObservableObject {
@ -46,6 +51,18 @@ extension Ghostty {
return ghostty_app_needs_confirm_quit(app) return ghostty_app_needs_confirm_quit(app)
} }
/// Build information
var info: Info {
let raw = ghostty_info()
let version = NSString(
bytes: raw.version,
length: Int(raw.version_len),
encoding: NSUTF8StringEncoding
) ?? "unknown"
return Info(mode: raw.build_mode, version: String(version))
}
/// Cached clipboard string for `read_clipboard` callback. /// Cached clipboard string for `read_clipboard` callback.
private var cached_clipboard_string: String? = nil private var cached_clipboard_string: String? = nil