mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-12-29 09:34:45 +00:00
Fixes #7643 This commit address the issue with 3 minor fixes: 1. Initialize ghostty lib before app start, or global allocator will be null. 2. `addSublayer` should be called on CALayer object, which is the property 'layer' of UIView 3. According to apple's [document](https://developer.apple.com/documentation/metal/mtlstoragemode/managed?language=objc), managed storage mode is not supported by iOS. So always use shared mode. FYI, another [fix](https://github.com/mitchellh/libxev/pull/204) in libxev is also required to make iOS app work.
51 lines
1.3 KiB
Swift
51 lines
1.3 KiB
Swift
import SwiftUI
|
|
import GhosttyKit
|
|
|
|
@main
|
|
struct Ghostty_iOSApp: App {
|
|
@StateObject private var ghostty_app: Ghostty.App
|
|
|
|
init() {
|
|
if ghostty_init(UInt(CommandLine.argc), CommandLine.unsafeArgv) != GHOSTTY_SUCCESS {
|
|
preconditionFailure("Initialize ghostty backend failed")
|
|
}
|
|
_ghostty_app = StateObject(wrappedValue: Ghostty.App())
|
|
}
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
iOS_GhosttyTerminal()
|
|
.environmentObject(ghostty_app)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct iOS_GhosttyTerminal: View {
|
|
@EnvironmentObject private var ghostty_app: Ghostty.App
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
// Make sure that our background color extends to all parts of the screen
|
|
Color(ghostty_app.config.backgroundColor).ignoresSafeArea()
|
|
|
|
Ghostty.Terminal()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct iOS_GhosttyInitView: View {
|
|
@EnvironmentObject private var ghostty_app: Ghostty.App
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Image("AppIconImage")
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fit)
|
|
.frame(maxHeight: 96)
|
|
Text("Ghostty")
|
|
Text("State: \(ghostty_app.readiness.rawValue)")
|
|
}
|
|
.padding()
|
|
}
|
|
}
|