From 152f8c9519ac1b7b35c3789b03f3d1cc3b1e8881 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Mon, 29 Jul 2019 10:50:02 -0400 Subject: Ring bell when new messages arrive Add a "new-message-bell" option to the UI section of aerc.conf. A new hook into the message store allows the msglist widget to detect new messages being added to the displayed list. When new messages are delivered, and the new-message-bell option is enabled (as it is by default), the terminal will beep. --- lib/msgstore.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/msgstore.go') diff --git a/lib/msgstore.go b/lib/msgstore.go index 48a105e..b346129 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -33,12 +33,14 @@ type MessageStore struct { pendingHeaders map[uint32]interface{} worker *types.Worker - triggerNewEmail func(*models.MessageInfo) + triggerNewEmail func(*models.MessageInfo) + triggerDirectoryChange func() } func NewMessageStore(worker *types.Worker, dirInfo *models.DirectoryInfo, - triggerNewEmail func(*models.MessageInfo)) *MessageStore { + triggerNewEmail func(*models.MessageInfo), + triggerDirectoryChange func()) *MessageStore { return &MessageStore{ Deleted: make(map[uint32]interface{}), @@ -52,7 +54,8 @@ func NewMessageStore(worker *types.Worker, pendingHeaders: make(map[uint32]interface{}), worker: worker, - triggerNewEmail: triggerNewEmail, + triggerNewEmail: triggerNewEmail, + triggerDirectoryChange: triggerDirectoryChange, } } @@ -147,6 +150,7 @@ func merge(to *models.MessageInfo, from *models.MessageInfo) { func (store *MessageStore) Update(msg types.WorkerMessage) { update := false + directoryChange := false switch msg := msg.(type) { case *types.DirectoryInfo: store.DirInfo = *msg.Info @@ -159,6 +163,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { newMap[uid] = msg } else { newMap[uid] = nil + directoryChange = true } } store.Messages = newMap @@ -225,6 +230,10 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { if update { store.update() } + + if directoryChange && store.triggerDirectoryChange != nil { + store.triggerDirectoryChange() + } } func (store *MessageStore) OnUpdate(fn func(store *MessageStore)) { -- cgit 1.4.1-2-gfad0