Skip to content

Commit

Permalink
brclient: alert current window on completed download
Browse files Browse the repository at this point in the history
Better ux.
  • Loading branch information
miki authored and miki-totefu committed Feb 14, 2023
1 parent 5e477c9 commit fdad19d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion brclient/appstate.go
Expand Up @@ -641,6 +641,18 @@ func (as *appState) activeWindowMsgs() string {
return msgs
}

// activeChatWindow returns the currently active chat window or nil if the
// active window is _not_ a chat window.
func (as *appState) activeChatWindow() *chatWindow {
var res *chatWindow
as.chatWindowsMtx.Lock()
if as.activeCW >= 0 {
res = as.chatWindows[as.activeCW]
}
as.chatWindowsMtx.Unlock()
return res
}

func (as *appState) rmqLen() int {
as.qlenMtx.Lock()
l := as.qlen
Expand Down Expand Up @@ -2649,7 +2661,12 @@ func newAppState(sendMsg func(tea.Msg), lndLogLines *sloglinesbuffer.Buffer,
}
as.contentMtx.Unlock()

as.repaintIfActive(cw)
activeCW := as.activeChatWindow()
as.sendMsg(msgDownloadCompleted(fid))
if activeCW != nil && activeCW != cw {
activeCW.newHelpMsg("Download completed: %s", diskPath)
as.repaintIfActive(activeCW)
}
},

FileDownloadProgress: func(user *client.RemoteUser, fm rpc.FileMetadata,
Expand Down
3 changes: 3 additions & 0 deletions brclient/mainwindow.go
Expand Up @@ -363,6 +363,9 @@ func (mws mainWindowState) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
mws.escStr = ""
mws.escMode = false

case msgDownloadCompleted:
mws.updateViewportContent()

default:
// Handle other messages.
mws.textArea, cmd = mws.textArea.Update(msg)
Expand Down
3 changes: 3 additions & 0 deletions brclient/messages.go
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/atotto/clipboard"
tea "github.com/charmbracelet/bubbletea"
"github.com/companyzero/bisonrelay/client/clientdb"
"github.com/companyzero/bisonrelay/client/clientintf"
"github.com/companyzero/bisonrelay/zkidentity"
"github.com/decred/dcrd/dcrutil/v4"
Expand Down Expand Up @@ -63,6 +64,8 @@ type msgShowSharedFilesForLink struct{}

type msgProcessEsc struct{}

type msgDownloadCompleted clientdb.FileID

func paste() tea.Msg {
str, err := clipboard.ReadAll()
if err != nil {
Expand Down

0 comments on commit fdad19d

Please sign in to comment.