2022-01-29 11:10:04 +00:00
|
|
|
//
|
|
|
|
// TerminalView.swift
|
|
|
|
// SimpleX
|
|
|
|
//
|
|
|
|
// Created by Evgeny Poberezkin on 27/01/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct TerminalView: View {
|
|
|
|
@EnvironmentObject var chatModel: ChatModel
|
|
|
|
@State var inProgress: Bool = false
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
|
|
|
ScrollView {
|
|
|
|
LazyVStack {
|
2022-01-29 23:37:02 +00:00
|
|
|
ForEach(chatModel.terminalItems) { item in
|
2022-01-29 11:10:04 +00:00
|
|
|
NavigationLink {
|
|
|
|
ScrollView {
|
2022-01-29 23:37:02 +00:00
|
|
|
Text(item.details)
|
2022-02-01 17:34:06 +00:00
|
|
|
.textSelection(.enabled)
|
2022-01-29 11:10:04 +00:00
|
|
|
}
|
|
|
|
} label: {
|
2022-01-29 23:37:02 +00:00
|
|
|
Text(item.label)
|
2022-01-29 11:10:04 +00:00
|
|
|
.frame(width: 360, height: 30, alignment: .leading)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationViewStyle(.stack)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
2022-01-29 23:37:02 +00:00
|
|
|
SendMessageView(sendMessage: sendMessage, inProgress: inProgress)
|
2022-01-29 11:10:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 23:37:02 +00:00
|
|
|
func sendMessage(_ cmdStr: String) {
|
|
|
|
let cmd = ChatCommand.string(cmdStr)
|
|
|
|
chatModel.terminalItems.append(.cmd(Date.now, cmd))
|
|
|
|
|
2022-01-29 11:10:04 +00:00
|
|
|
DispatchQueue.global().async {
|
|
|
|
inProgress = true
|
2022-01-29 23:37:02 +00:00
|
|
|
do {
|
|
|
|
let r = try chatSendCmd(cmd)
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
chatModel.terminalItems.append(.resp(Date.now, r))
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
print(error)
|
|
|
|
}
|
2022-01-29 11:10:04 +00:00
|
|
|
inProgress = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TerminalView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
let chatModel = ChatModel()
|
2022-01-29 23:37:02 +00:00
|
|
|
chatModel.terminalItems = [
|
|
|
|
.resp(Date.now, ChatResponse.response(type: "contactSubscribed", json: "{}")),
|
|
|
|
.resp(Date.now, ChatResponse.response(type: "newChatItem", json: "{}"))
|
2022-01-29 11:10:04 +00:00
|
|
|
]
|
|
|
|
return NavigationView {
|
|
|
|
TerminalView()
|
|
|
|
.environmentObject(chatModel)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|