diff options
Diffstat (limited to 'xA/xA.go')
-rw-r--r-- | xA/xA.go | 156 |
1 files changed, 88 insertions, 68 deletions
@@ -281,7 +281,11 @@ func beep() { } go func() { <-otoReady - otoContext.NewPlayer(bytes.NewReader(beepSample)).Play() + p := otoContext.NewPlayer(bytes.NewReader(beepSample)) + p.Play() + for p.IsPlaying() { + time.Sleep(time.Second) + } }() } @@ -363,16 +367,18 @@ func bufferByName(name string) *buffer { return nil } -func bufferActivate(name string) { - relaySend(RelayCommandData{ - Variant: &RelayCommandDataBufferActivate{BufferName: name}, - }, nil) +func bufferAtBottom() bool { + return wRichScroll.Offset.Y >= + wRichScroll.Content.Size().Height-wRichScroll.Size().Height } -func bufferToggleUnimportant(name string) { - relaySend(RelayCommandData{ - Variant: &RelayCommandDataBufferToggleUnimportant{BufferName: name}, - }, nil) +func bufferScrollToBottom() { + // XXX: Doing it once is not reliable, something's amiss. + // (In particular, nothing happens when we switch from an empty buffer + // to a buffer than needs scrolling.) + wRichScroll.ScrollToBottom() + wRichScroll.ScrollToBottom() + refreshStatus() } func bufferPushLine(b *buffer, line bufferLine) { @@ -386,68 +392,20 @@ func bufferPushLine(b *buffer, line bufferLine) { } } -// --- Current buffer ---------------------------------------------------------- - -func bufferToggleLogFinish(err string, response *RelayResponseDataBufferLog) { - if response == nil { - showErrorMessage(err) - return - } - - wLog.SetText(string(response.Log)) - wLog.Show() - wRichScroll.Hide() -} - -func bufferToggleLog() { - if wLog.Visible() { - wRichScroll.Show() - wLog.Hide() - wLog.SetText("") - return - } - - name := bufferCurrent - relaySend(RelayCommandData{Variant: &RelayCommandDataBufferLog{ - BufferName: name, - }}, func(err string, response *RelayResponseData) { - if bufferCurrent == name { - bufferToggleLogFinish( - err, response.Variant.(*RelayResponseDataBufferLog)) - } - }) -} - -func bufferAtBottom() bool { - return wRichScroll.Offset.Y >= - wRichScroll.Content.Size().Height-wRichScroll.Size().Height -} - -func bufferScrollToBottom() { - // XXX: Doing it once is not reliable, something's amiss. - // (In particular, nothing happens when we switch from an empty buffer - // to a buffer than needs scrolling.) - wRichScroll.ScrollToBottom() - wRichScroll.ScrollToBottom() - refreshStatus() -} - // --- UI state refresh -------------------------------------------------------- func refreshIcon() { - highlighted := false + resource := resourceIconNormal for _, b := range buffers { if b.highlighted { - highlighted = true + resource = resourceIconHighlighted break } } - if highlighted { - wWindow.SetIcon(resourceIconHighlighted) - } else { - wWindow.SetIcon(resourceIconNormal) - } + // Prevent deadlocks (though it might have a race condition). + // https://github.com/fyne-io/fyne/issues/5266 + go func() { wWindow.SetIcon(resource) }() } func refreshTopic(topic []bufferLineItem) { @@ -515,6 +473,63 @@ func refreshStatus() { wStatus.SetText(status) } +func recheckHighlighted() { + // Corresponds to the logic toggling the bool on. + if b := bufferByName(bufferCurrent); b != nil && + b.highlighted && bufferAtBottom() && + inForeground && !wLog.Visible() { + b.highlighted = false + refreshIcon() + refreshBufferList() + } +} + +// --- Buffer actions ---------------------------------------------------------- + +func bufferActivate(name string) { + relaySend(RelayCommandData{ + Variant: &RelayCommandDataBufferActivate{BufferName: name}, + }, nil) +} + +func bufferToggleUnimportant(name string) { + relaySend(RelayCommandData{ + Variant: &RelayCommandDataBufferToggleUnimportant{BufferName: name}, + }, nil) +} + +func bufferToggleLogFinish(err string, response *RelayResponseDataBufferLog) { + if response == nil { + showErrorMessage(err) + return + } + + wLog.SetText(string(response.Log)) + wLog.Show() + wRichScroll.Hide() +} + +func bufferToggleLog() { + if wLog.Visible() { + wRichScroll.Show() + wLog.Hide() + wLog.SetText("") + + recheckHighlighted() + return + } + + name := bufferCurrent + relaySend(RelayCommandData{Variant: &RelayCommandDataBufferLog{ + BufferName: name, + }}, func(err string, response *RelayResponseData) { + if bufferCurrent == name { + bufferToggleLogFinish( + err, response.Variant.(*RelayResponseDataBufferLog)) + } + }) +} + // --- RichText formatting ----------------------------------------------------- func defaultBufferLineItem() bufferLineItem { return bufferLineItem{} } @@ -756,6 +771,7 @@ func refreshBuffer(b *buffer) { bufferPrintAndWatchTrailingDateChanges() wRichText.Refresh() bufferScrollToBottom() + recheckHighlighted() } // --- Event processing -------------------------------------------------------- @@ -921,11 +937,11 @@ func relayProcessMessage(m *RelayEventMessage) { b.bufferName = data.New - refreshBufferList() if data.BufferName == bufferCurrent { bufferCurrent = data.New refreshStatus() } + refreshBufferList() if data.BufferName == bufferLast { bufferLast = data.New } @@ -1374,6 +1390,9 @@ func (l *customLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) { } if toBottom { bufferScrollToBottom() + } else { + recheckHighlighted() + refreshStatus() } } @@ -1490,16 +1509,14 @@ func main() { a := app.New() a.Settings().SetTheme(&customTheme{}) + a.SetIcon(resourceIconNormal) wWindow = a.NewWindow(projectName) wWindow.Resize(fyne.NewSize(640, 480)) a.Lifecycle().SetOnEnteredForeground(func() { // TODO(p): Does this need locking? inForeground = true - if b := bufferByName(bufferCurrent); b != nil { - b.highlighted = false - refreshIcon() - } + recheckHighlighted() }) a.Lifecycle().SetOnExitedForeground(func() { inForeground = false @@ -1540,7 +1557,10 @@ func main() { wRichText = widget.NewRichText() wRichText.Wrapping = fyne.TextWrapWord wRichScroll = container.NewVScroll(wRichText) - wRichScroll.OnScrolled = func(position fyne.Position) { refreshStatus() } + wRichScroll.OnScrolled = func(position fyne.Position) { + recheckHighlighted() + refreshStatus() + } wLog = newLogEntry() wLog.Wrapping = fyne.TextWrapWord wLog.Hide() |