Skip to content

Commit

Permalink
emit callhistory availability event in the UI thread
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Sep 14, 2024
1 parent 0225b9c commit 8b09ef0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (c *Controller) Startup() {

c.ServiceStatus = newServiceStatus(c.asyncRunner)

c.callHistoryFinder = callhistory.New(c.ServiceStatus.StatusChanged)
c.callHistoryFinder = callhistory.New(c.ServiceStatus.StatusChanged, c.asyncRunner)
c.Settings = settings.New(
c.OpenConfigurationFile,
c.openWithExternalApplication,
Expand Down
15 changes: 10 additions & 5 deletions core/callhistory/callhistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ const (
Exch1Field = "Exch1"
)

func New(availabilityCallback AvailabilityCallback) *Finder {
func New(availabilityCallback AvailabilityCallback, asyncRunner core.AsyncRunner) *Finder {
return &Finder{
dataLock: new(sync.Mutex),
availabilityCallback: availabilityCallback,
asyncRunner: asyncRunner,
}
}

type Finder struct {
database *scp.Database
cache map[string][]scp.Match
dataLock *sync.Mutex
database *scp.Database
cache map[string][]scp.Match
dataLock *sync.Mutex

availabilityCallback AvailabilityCallback
asyncRunner core.AsyncRunner

listeners []any

Expand Down Expand Up @@ -114,7 +117,9 @@ func (f *Finder) findInDatabase(s string) ([]scp.Match, error) {
func (f *Finder) emitAvailableCallHistoryFieldNames(fieldNames []string) {
for _, listener := range f.listeners {
if fieldNamesListener, ok := listener.(AvailableFieldNamesListener); ok {
fieldNamesListener.SetAvailableCallHistoryFieldNames(fieldNames)
f.asyncRunner(func() {
fieldNamesListener.SetAvailableCallHistoryFieldNames(fieldNames)
})
}
}
}
Expand Down

0 comments on commit 8b09ef0

Please sign in to comment.