Notifications will now show up more often
MODIFY
config/config.go
config/config.go
@@ -2,11 +2,12 @@ package config
import (
"encoding/json"
- "github.com/Bios-Marcel/cordless/util/files"
"io"
"io/ioutil"
"os"
"path/filepath"
+
+ "github.com/Bios-Marcel/cordless/util/files"
)
const (
@@ -52,6 +53,8 @@ var (
ShortenWithExtension: false,
ShortenerPort: 63212,
DesktopNotifications: true,
+ DesktopNotificationsUserInactivityThreshold: 10,
+ DesktopNotificationsForLoadedChannel: true,
ShowPlaceholderForBlockedMessages: true,
DontShowUpdateNotificationFor: "",
ShowUpdateNotifications: true,
@@ -115,6 +118,15 @@ type Config struct {
// system when a notification needs to be sent.
DesktopNotifications bool
+ // DesktopNotificationsUserInactivityThreshold defines how many seconds
+ // have to pass between now and the last user input (key stroke) in order
+ // for a notification to be sent.
+ DesktopNotificationsUserInactivityThreshold int
+
+ // DesktopNotificationsForLoadedChannel Defines whether notifications are
+ // also sent for the currently selected (loaded) channel.
+ DesktopNotificationsForLoadedChannel bool
+
// ShowPlaceholderForBlockedMessages will cause blocked message to shown
// as a placeholder message, replacing user and message with generic text.
// The time of the message will still be correct in order to not mess up

MODIFY
ui/window.go
ui/window.go
@@ -37,8 +37,6 @@ import (
"github.com/Bios-Marcel/cordless/util/maths"
)
-const userInactiveTime = 10 * time.Second
-
var (
shortcutsDialogShortcut = tcell.NewEventKey(tcell.KeyCtrlK, rune(tcell.KeyCtrlK), tcell.ModCtrl)
)
@@ -111,16 +109,18 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
app: app,
activeView: Guilds,
extensionEngines: []scripting.Engine{js.New()},
- userActiveTimer: time.NewTimer(userInactiveTime),
messageLoader: discordutil.CreateMessageLoader(session),
}
+ if config.Current.DesktopNotificationsUserInactivityThreshold > 0 {
+ window.userActiveTimer = time.NewTimer(time.Duration(config.Current.DesktopNotificationsUserInactivityThreshold) * time.Second)
go func() {
for {
<-window.userActiveTimer.C
window.userActive = false
}
}()
+ }
window.commandView = NewCommandView(window.ExecuteCommand)
log.SetOutput(window.commandView)
@@ -1827,12 +1827,14 @@ func (window *Window) startMessageHandlerRoutines(input, edit, delete chan *disc
continue
}
- if window.selectedChannel == nil || message.ChannelID != window.selectedChannel.ID {
+ isCurrentChannel := window.selectedChannel == nil || message.ChannelID != window.selectedChannel.ID
mentionsCurrentUser := discordutil.MentionsCurrentUserExplicitly(window.session.State, message)
- if !window.userActive && config.Current.DesktopNotifications {
- if mentionsCurrentUser ||
+ if config.Current.DesktopNotifications &&
+ (mentionsCurrentUser ||
//Always show notification for private messages
- channel.Type == discordgo.ChannelTypeDM || channel.Type == discordgo.ChannelTypeGroupDM {
+ channel.Type == discordgo.ChannelTypeDM || channel.Type == discordgo.ChannelTypeGroupDM) &&
+ (!isCurrentChannel ||
+ (config.Current.DesktopNotificationsForLoadedChannel && !window.userActive)) {
var notificationLocation string
if channel.Type == discordgo.ChannelTypeDM {
@@ -1864,8 +1866,8 @@ func (window *Window) startMessageHandlerRoutines(input, edit, delete chan *disc
log.Printf("["+tviewutil.ColorToHex(config.GetTheme().ErrorColor)+"]Error sending notification:\n\t[%s]%s\n", tviewutil.ColorToHex(config.GetTheme().ErrorColor), notifyError)
}
}
- }
+ if isCurrentChannel {
if channel.Type == discordgo.ChannelTypeDM || channel.Type == discordgo.ChannelTypeGroupDM {
if !readstate.IsPrivateChannelMuted(channel) {
window.app.QueueUpdateDraw(func() {
@@ -2204,8 +2206,10 @@ func (window *Window) handleGlobalShortcuts(event *tcell.EventKey) *tcell.EventK
}
// Maybe compare directly to table?
+ if config.Current.DesktopNotificationsUserInactivityThreshold > 0 {
window.userActive = true
- window.userActiveTimer.Reset(userInactiveTime)
+ window.userActiveTimer.Reset(time.Duration(config.Current.DesktopNotificationsUserInactivityThreshold) * time.Second)
+ }
if shortcuts.ToggleBareChat.Equals(event) {
window.toggleBareChat()

Notifications will now show up more often