Skip to content

Commit

Permalink
Mark as read when window regains focus
Browse files Browse the repository at this point in the history
This used to be a feature, but was removed because it was (probably)
memory leaking. Now, care has been taken to make sure it does not get
memory leaked.
  • Loading branch information
diamondburned committed Dec 27, 2023
1 parent 2f8a342 commit 1877d44
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/message/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ func NewView(ctx context.Context, chID discord.ChannelID) *View {
v.LoadablePage.SetTransitionDuration(125)
v.setPageToMain()

// If the window gains focus, try to carefully mark the channel as read.
var windowSignal glib.SignalHandle
v.ConnectMap(func() {
window := app.GTKWindowFromContext(ctx)
windowSignal = window.NotifyProperty("is-active", func() {
if v.IsActive() {
v.MarkRead()
}
})
})
// Immediately disconnect the signal when the widget is unmapped.
// This should prevent v from being referenced forever.
v.ConnectUnmap(func() {
window := app.GTKWindowFromContext(ctx)
window.HandlerDisconnect(windowSignal)
windowSignal = 0
})

state := gtkcord.FromContext(v.ctx)
if ch, err := state.Cabinet.Channel(v.chID); err == nil {
v.chName = ch.Name
Expand Down

0 comments on commit 1877d44

Please sign in to comment.