more message container improvements
This commit is contained in:
parent
2f64bb509a
commit
d921470f00
|
@ -37,6 +37,9 @@ type Container interface {
|
||||||
|
|
||||||
// Thread-unsafe methods.
|
// Thread-unsafe methods.
|
||||||
|
|
||||||
|
// Reset resets the message container to its original state.
|
||||||
|
Reset()
|
||||||
|
|
||||||
// CreateMessageUnsafe creates a new message and returns the index that is
|
// CreateMessageUnsafe creates a new message and returns the index that is
|
||||||
// the location the message is added to.
|
// the location the message is added to.
|
||||||
CreateMessageUnsafe(cchat.MessageCreate)
|
CreateMessageUnsafe(cchat.MessageCreate)
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package cozy
|
package cozy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"runtime/pprof"
|
||||||
|
|
||||||
"github.com/diamondburned/cchat"
|
"github.com/diamondburned/cchat"
|
||||||
"github.com/diamondburned/cchat-gtk/internal/gts"
|
"github.com/diamondburned/cchat-gtk/internal/gts"
|
||||||
"github.com/diamondburned/cchat-gtk/internal/ui/messages/container"
|
"github.com/diamondburned/cchat-gtk/internal/ui/messages/container"
|
||||||
|
@ -126,8 +129,12 @@ func (c *Container) lastMessageIsAuthor(id string, offset int) bool {
|
||||||
return last != nil && last.AuthorID() == id
|
return last != nil && last.AuthorID() == id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var createMessageLabel = pprof.Labels("cozy", "createMessage")
|
||||||
|
|
||||||
func (c *Container) CreateMessage(msg cchat.MessageCreate) {
|
func (c *Container) CreateMessage(msg cchat.MessageCreate) {
|
||||||
gts.ExecAsync(func() {
|
gts.ExecAsync(func() {
|
||||||
|
pprof.Do(context.Background(), createMessageLabel, func(context.Context) {
|
||||||
|
|
||||||
// Create the message in the parent's handler. This handler will also
|
// Create the message in the parent's handler. This handler will also
|
||||||
// wipe old messages.
|
// wipe old messages.
|
||||||
c.GridContainer.CreateMessageUnsafe(msg)
|
c.GridContainer.CreateMessageUnsafe(msg)
|
||||||
|
@ -163,6 +170,7 @@ func (c *Container) CreateMessage(msg cchat.MessageCreate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) UpdateMessage(msg cchat.MessageUpdate) {
|
func (c *Container) UpdateMessage(msg cchat.MessageUpdate) {
|
||||||
|
|
|
@ -17,6 +17,8 @@ type GridStore struct {
|
||||||
Construct Constructor
|
Construct Constructor
|
||||||
Controller Controller
|
Controller Controller
|
||||||
|
|
||||||
|
resetMe bool
|
||||||
|
|
||||||
messages map[string]*gridMessage
|
messages map[string]*gridMessage
|
||||||
messageList *list.List
|
messageList *list.List
|
||||||
}
|
}
|
||||||
|
@ -35,11 +37,17 @@ func NewGridStore(constr Constructor, ctrl Controller) *GridStore {
|
||||||
Grid: grid,
|
Grid: grid,
|
||||||
Construct: constr,
|
Construct: constr,
|
||||||
Controller: ctrl,
|
Controller: ctrl,
|
||||||
messages: map[string]*gridMessage{},
|
messages: make(map[string]*gridMessage, BacklogLimit+1),
|
||||||
messageList: list.New(),
|
messageList: list.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *GridStore) Reset() {
|
||||||
|
primitives.RemoveChildren(c.Grid)
|
||||||
|
c.messages = make(map[string]*gridMessage, BacklogLimit+1)
|
||||||
|
c.messageList = list.New()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *GridStore) MessagesLen() int {
|
func (c *GridStore) MessagesLen() int {
|
||||||
return c.messageList.Len()
|
return c.messageList.Len()
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ func New(parent gtk.IWidget, placeholder gtk.IWidget) *FaceView {
|
||||||
|
|
||||||
stack, _ := gtk.StackNew()
|
stack, _ := gtk.StackNew()
|
||||||
stack.SetTransitionType(gtk.STACK_TRANSITION_TYPE_CROSSFADE)
|
stack.SetTransitionType(gtk.STACK_TRANSITION_TYPE_CROSSFADE)
|
||||||
stack.SetTransitionDuration(75)
|
|
||||||
stack.AddNamed(parent, "main")
|
stack.AddNamed(parent, "main")
|
||||||
stack.AddNamed(placeholder, "placeholder")
|
stack.AddNamed(placeholder, "placeholder")
|
||||||
stack.AddNamed(c, "face")
|
stack.AddNamed(c, "face")
|
||||||
|
@ -45,21 +44,21 @@ func New(parent gtk.IWidget, placeholder gtk.IWidget) *FaceView {
|
||||||
|
|
||||||
// Reset brings the view to an empty box.
|
// Reset brings the view to an empty box.
|
||||||
func (v *FaceView) Reset() {
|
func (v *FaceView) Reset() {
|
||||||
v.ensurePlaceholderDestroyed()
|
|
||||||
v.Loading.Spinner.Stop()
|
v.Loading.Spinner.Stop()
|
||||||
v.Stack.SetVisibleChildName("empty")
|
v.Stack.SetVisibleChildName("empty")
|
||||||
|
v.ensurePlaceholderDestroyed()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *FaceView) SetMain() {
|
func (v *FaceView) SetMain() {
|
||||||
v.ensurePlaceholderDestroyed()
|
|
||||||
v.Loading.Spinner.Stop()
|
v.Loading.Spinner.Stop()
|
||||||
v.Stack.SetVisibleChildName("main")
|
v.Stack.SetVisibleChildName("main")
|
||||||
|
v.ensurePlaceholderDestroyed()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *FaceView) SetLoading() {
|
func (v *FaceView) SetLoading() {
|
||||||
v.ensurePlaceholderDestroyed()
|
|
||||||
v.Loading.Spinner.Start()
|
v.Loading.Spinner.Start()
|
||||||
v.Stack.SetVisibleChildName("loading")
|
v.Stack.SetVisibleChildName("loading")
|
||||||
|
v.ensurePlaceholderDestroyed()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *FaceView) SetError(err error) {
|
func (v *FaceView) SetError(err error) {
|
||||||
|
|
|
@ -93,7 +93,11 @@ var messageStack = primitives.PrepareClassCSS("message-stack", `
|
||||||
var messageScroller = primitives.PrepareClassCSS("message-scroller", ``)
|
var messageScroller = primitives.PrepareClassCSS("message-scroller", ``)
|
||||||
|
|
||||||
func NewView(c Controller) *View {
|
func NewView(c Controller) *View {
|
||||||
view := &View{ctrl: c}
|
view := &View{
|
||||||
|
ctrl: c,
|
||||||
|
contType: -1, // force recreate
|
||||||
|
}
|
||||||
|
|
||||||
view.Typing = typing.New()
|
view.Typing = typing.New()
|
||||||
view.Typing.Show()
|
view.Typing.Show()
|
||||||
|
|
||||||
|
@ -188,6 +192,13 @@ func NewView(c Controller) *View {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *View) createMessageContainer() {
|
func (v *View) createMessageContainer() {
|
||||||
|
// If we still want the same type of message container, then we don't need
|
||||||
|
// to remake a new one.
|
||||||
|
if v.contType == msgIndex {
|
||||||
|
v.Container.Reset()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the old message container.
|
// Remove the old message container.
|
||||||
if v.Container != nil {
|
if v.Container != nil {
|
||||||
v.MsgBox.Remove(v.Container)
|
v.MsgBox.Remove(v.Container)
|
||||||
|
|
|
@ -172,12 +172,12 @@ func (app *App) GoBack() {
|
||||||
func (app *App) OnMessageBusy() {
|
func (app *App) OnMessageBusy() {
|
||||||
// Disable the server list because we don't want the user to switch around
|
// Disable the server list because we don't want the user to switch around
|
||||||
// while we're loading.
|
// while we're loading.
|
||||||
gts.App.Window.SetSensitive(false)
|
app.Services.SetSensitive(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) OnMessageDone() {
|
func (app *App) OnMessageDone() {
|
||||||
// Re-enable the server list.
|
// Re-enable the server list.
|
||||||
gts.App.Window.SetSensitive(true)
|
app.Services.SetSensitive(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) AuthenticateSession(list *service.List, ssvc *service.Service) {
|
func (app *App) AuthenticateSession(list *service.List, ssvc *service.Service) {
|
||||||
|
|
5
main.go
5
main.go
|
@ -11,9 +11,6 @@ import (
|
||||||
_ "github.com/diamondburned/cchat-mock"
|
_ "github.com/diamondburned/cchat-mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// destructor is used for debugging and profiling.
|
|
||||||
var destructor = func() {}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
gts.Main(func() gts.MainApplication {
|
gts.Main(func() gts.MainApplication {
|
||||||
var app = ui.NewApplication()
|
var app = ui.NewApplication()
|
||||||
|
@ -36,6 +33,4 @@ func main() {
|
||||||
|
|
||||||
return app
|
return app
|
||||||
})
|
})
|
||||||
|
|
||||||
destructor()
|
|
||||||
}
|
}
|
||||||
|
|
48
profile.go
48
profile.go
|
@ -1,51 +1,15 @@
|
||||||
// +build prof
|
// Code generated by goprofiler. DO NOT EDIT.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
|
||||||
_ "github.com/ianlancetaylor/cgosymbolizer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
const ProfileAddr = "localhost:49583"
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
C.HeapProfilerStart()
|
go func() {
|
||||||
destructor = func() { C.HeapProfilerStop() }
|
println("Serving HTTP at 127.0.0.1:48574 for profiler at /debug/pprof")
|
||||||
|
panic(http.ListenAndServe("127.0.0.1:48574", nil))
|
||||||
// runtime.SetBlockProfileRate(1)
|
}()
|
||||||
|
|
||||||
// go func() {
|
|
||||||
// log.Println("Listening to profiler at", ProfileAddr)
|
|
||||||
|
|
||||||
// if err := http.ListenAndServe(ProfileAddr, nil); err != nil {
|
|
||||||
// log.Error(errors.Wrap(err, "Failed to start profiling HTTP server"))
|
|
||||||
// }
|
|
||||||
// }()
|
|
||||||
|
|
||||||
// f, _ := os.Create("/tmp/cchat.pprof")
|
|
||||||
// p := pprof.Lookup("block")
|
|
||||||
|
|
||||||
// destructor = func() {
|
|
||||||
// log.Println("==destructor==")
|
|
||||||
|
|
||||||
// if err := p.WriteTo(f, 2); err != nil {
|
|
||||||
// log.Println("Profile writeTo error:", err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// f.Close()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// f, _ := os.Create("/tmp/cchat.pprof")
|
|
||||||
// if err := pprof.StartCPUProfile(f); err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// destructor = func() {
|
|
||||||
// pprof.StopCPUProfile()
|
|
||||||
// f.Close()
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue