ios: more responsive UI, especially during app start (#2942)

* ios: more responsive UI, especially during app start

* move terminal items to actor

* fix for iOS 15/16
This commit is contained in:
Evgeny Poberezkin
2023-08-17 18:21:05 +01:00
committed by GitHub
parent 45b7d09f83
commit 01a95f88bb
4 changed files with 320 additions and 199 deletions
+20 -3
View File
@@ -22,10 +22,28 @@ struct TerminalView: View {
@State var authorized = !UserDefaults.standard.bool(forKey: DEFAULT_PERFORM_LA)
@State private var terminalItem: TerminalItem?
@State private var scrolled = false
@State private var showing = false
var body: some View {
if authorized {
terminalView()
.onAppear {
if showing { return }
showing = true
Task {
let items = await TerminalItems.shared.items()
await MainActor.run {
chatModel.terminalItems = items
chatModel.showingTerminal = true
}
}
}
.onDisappear {
if terminalItem == nil {
chatModel.showingTerminal = false
chatModel.terminalItems = []
}
}
} else {
Button(action: runAuth) { Label("Unlock", systemImage: "lock") }
.onAppear(perform: runAuth)
@@ -118,9 +136,8 @@ struct TerminalView: View {
let cmd = ChatCommand.string(composeState.message)
if composeState.message.starts(with: "/sql") && (!prefPerformLA || !developerTools) {
let resp = ChatResponse.chatCmdError(user_: nil, chatError: ChatError.error(errorType: ChatErrorType.commandError(message: "Failed reading: empty")))
DispatchQueue.main.async {
ChatModel.shared.addTerminalItem(.cmd(.now, cmd))
ChatModel.shared.addTerminalItem(.resp(.now, resp))
Task {
await TerminalItems.shared.addCommand(.now, cmd, resp)
}
} else {
DispatchQueue.global().async {
@@ -299,6 +299,10 @@ struct SettingsView: View {
}
.navigationTitle("Your settings")
}
.onDisappear {
chatModel.showingTerminal = false
chatModel.terminalItems = []
}
}
private func chatDatabaseRow() -> some View {