forked from MSG/msg-desktop
FIX: fixed issues due to ScrollView limit and stream rate
This commit is contained in:
parent
80cddb0314
commit
4abda00033
2 changed files with 34 additions and 12 deletions
|
@ -28,7 +28,7 @@ struct ContentView: View {
|
||||||
// App icon
|
// App icon
|
||||||
let appIcon = NSImage(named: NSImage.applicationIconName)
|
let appIcon = NSImage(named: NSImage.applicationIconName)
|
||||||
Image(nsImage: appIcon ?? NSImage())
|
Image(nsImage: appIcon ?? NSImage())
|
||||||
.resizable()
|
. resizable()
|
||||||
.scaledToFit()
|
.scaledToFit()
|
||||||
.frame(maxHeight: 150)
|
.frame(maxHeight: 150)
|
||||||
.background(
|
.background(
|
||||||
|
@ -44,19 +44,18 @@ struct ContentView: View {
|
||||||
// ScrollView fills remaining height
|
// ScrollView fills remaining height
|
||||||
ScrollViewReader { proxy in
|
ScrollViewReader { proxy in
|
||||||
ScrollView {
|
ScrollView {
|
||||||
VStack(alignment: .leading) {
|
LazyVStack(alignment: .leading, spacing: 0) {
|
||||||
TextEditor(text: $appState.output)
|
let lines = appState.output.components(separatedBy: .newlines)
|
||||||
.font(.system(.body, design: .monospaced))
|
|
||||||
.frame(
|
|
||||||
width: geometry.size.width - 60,
|
|
||||||
height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding
|
|
||||||
)
|
|
||||||
.padding()
|
|
||||||
.disabled(true)
|
|
||||||
|
|
||||||
Text("")
|
ForEach(lines.indices, id: \.self) { index in
|
||||||
.id("bottom")
|
Text(lines[index])
|
||||||
|
.font(.system(.body, design: .monospaced))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
Color.clear.frame(height: 1).id("bottom")
|
||||||
}
|
}
|
||||||
|
.padding()
|
||||||
}
|
}
|
||||||
.onChange(of: appState.output) { _, _ in
|
.onChange(of: appState.output) { _, _ in
|
||||||
trimLinesIfNeeded()
|
trimLinesIfNeeded()
|
||||||
|
@ -64,6 +63,28 @@ struct ContentView: View {
|
||||||
proxy.scrollTo("bottom", anchor: .bottom)
|
proxy.scrollTo("bottom", anchor: .bottom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScrollView {
|
||||||
|
// VStack(alignment: .leading) {
|
||||||
|
// TextEditor(text: $appState.output)
|
||||||
|
// .font(.system(.body, design: .monospaced))
|
||||||
|
// .frame(
|
||||||
|
// width: geometry.size.width - 60,
|
||||||
|
// height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding
|
||||||
|
// )
|
||||||
|
// .padding()
|
||||||
|
// .disabled(true)
|
||||||
|
//
|
||||||
|
// Text("")
|
||||||
|
// .id("bottom")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// .onChange(of: appState.output) { _, _ in
|
||||||
|
// trimLinesIfNeeded()
|
||||||
|
// withAnimation {
|
||||||
|
// proxy.scrollTo("bottom", anchor: .bottom)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
|
|
|
@ -34,6 +34,7 @@ func runShellCommandAsync(command: String, outputText: Binding<String>?, showBut
|
||||||
|
|
||||||
var observer: NSObjectProtocol?
|
var observer: NSObjectProtocol?
|
||||||
|
|
||||||
|
|
||||||
observer = NotificationCenter.default.addObserver(forName: .NSFileHandleDataAvailable, object: fileHandle, queue: nil) { _ in
|
observer = NotificationCenter.default.addObserver(forName: .NSFileHandleDataAvailable, object: fileHandle, queue: nil) { _ in
|
||||||
let data = fileHandle.availableData
|
let data = fileHandle.availableData
|
||||||
if let output = String(data: data, encoding: .utf8), !output.isEmpty {
|
if let output = String(data: data, encoding: .utf8), !output.isEmpty {
|
||||||
|
|
Loading…
Add table
Reference in a new issue