Compare commits

..

No commits in common. "9237bae4ff0dc773a183b5d4e4de26fc2e170c61" and "804d27a0b56634c308469aa8ca6d9e275b6faef4" have entirely different histories.

63
main.go
View File

@ -170,8 +170,7 @@ func (l *fixedHSplitLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
}
lead := objects[0].MinSize()
trail := objects[1].MinSize()
// Avoid forcing the window to expand to the sum of both sides.
return fyne.NewSize(fyne.Max(lead.Width, trail.Width), fyne.Max(lead.Height, trail.Height))
return fyne.NewSize(lead.Width+trail.Width, fyne.Max(lead.Height, trail.Height))
}
// resolveTargetAspect resolves an aspect ratio value or source aspect
@ -385,70 +384,36 @@ func (s *appState) openLogViewer(title, path string, live bool) {
d.SetOnClosed(func() { close(stop) })
d.Show()
readTail := func() string {
const maxBytes int64 = 200 * 1024
info, err := os.Stat(path)
if err != nil {
return fmt.Sprintf("Failed to read log: %v", err)
}
size := info.Size()
start := int64(0)
if size > maxBytes {
start = size - maxBytes
}
f, err := os.Open(path)
if err != nil {
return fmt.Sprintf("Failed to read log: %v", err)
}
defer f.Close()
if start > 0 {
if _, err := f.Seek(start, io.SeekStart); err != nil {
return fmt.Sprintf("Failed to read log: %v", err)
}
}
data, err := io.ReadAll(f)
if err != nil {
return fmt.Sprintf("Failed to read log: %v", err)
}
if start > 0 {
return fmt.Sprintf("... showing last %d KB ...\n%s", maxBytes/1024, string(data))
}
return string(data)
}
// Read file asynchronously to avoid blocking UI
go func() {
content := readTail()
data, err := os.ReadFile(path)
if err != nil {
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
text.SetText(fmt.Sprintf("Failed to read log: %v", err))
}, false)
return
}
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
text.SetText(content)
text.SetText(string(data))
// Auto-scroll to bottom
scroll.ScrollToBottom()
}, false)
// Start live updates if requested
if live {
ticker := time.NewTicker(2 * time.Second)
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
var lastSize int64 = -1
var lastText string
for {
select {
case <-stop:
return
case <-ticker.C:
info, err := os.Stat(path)
b, err := os.ReadFile(path)
if err != nil {
continue
b = []byte(fmt.Sprintf("failed to read log: %v", err))
}
if info.Size() == lastSize {
continue
}
lastSize = info.Size()
content := readTail()
if content == lastText {
continue
}
lastText = content
content := string(b)
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
text.SetText(content)
}, false)