diff --git a/src/model/model.ts b/src/model/model.ts index 2a9f3af57..38ab71213 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -4100,15 +4100,15 @@ class Model { if ("openaicmdinfochat" in update) { this.inputModel.setOpenAICmdInfoChat(update.openaicmdinfochat); } - if ("screenstatusindicator" in update) { - this.getScreenById_single(update.screenstatusindicator.screenid)?.setStatusIndicator( - update.screenstatusindicator.status - ); + if ("screenstatusindicators" in update) { + for (const indicator of update.screenstatusindicators) { + this.getScreenById_single(indicator.screenid)?.setStatusIndicator(indicator.status); + } } if ("screennumrunningcommands" in update) { - this.getScreenById_single(update.screennumrunningcommands.screenid)?.setNumRunningCmds( - update.screennumrunningcommands.num - ); + for (const snc of update.screennumrunningcommands) { + this.getScreenById_single(snc.screenid)?.setNumRunningCmds(snc.num); + } } } diff --git a/src/types/types.ts b/src/types/types.ts index f0f775979..53a18fbe7 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -326,8 +326,8 @@ type ModelUpdateType = { remoteview?: RemoteViewType; openaicmdinfochat?: OpenAICmdInfoChatMessageType[]; alertmessage?: AlertMessageType; - screenstatusindicator?: ScreenStatusIndicatorUpdateType; - screennumrunningcommands?: ScreenNumRunningCommandsUpdateType; + screenstatusindicators?: ScreenStatusIndicatorUpdateType[]; + screennumrunningcommands?: ScreenNumRunningCommandsUpdateType[]; }; type HistoryViewDataType = { diff --git a/wavesrv/pkg/scws/scws.go b/wavesrv/pkg/scws/scws.go index 1ffb2331b..88895888c 100644 --- a/wavesrv/pkg/scws/scws.go +++ b/wavesrv/pkg/scws/scws.go @@ -158,6 +158,7 @@ func (ws *WSState) ReplaceShell(shell *wsshell.WSShell) { return } +// returns all state required to display current UI func (ws *WSState) handleConnection() error { ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second) defer cancelFn() @@ -167,6 +168,8 @@ func (ws *WSState) handleConnection() error { } remotes := remote.GetAllRemoteRuntimeState() update.Remotes = remotes + // restore status indicators + update.ScreenStatusIndicators, update.ScreenNumRunningCommands = sstore.GetCurrentIndicatorState() update.Connect = true err = ws.Shell.WriteJson(update) if err != nil { diff --git a/wavesrv/pkg/sstore/memops.go b/wavesrv/pkg/sstore/memops.go index 18eb8b0ea..476d1ec40 100644 --- a/wavesrv/pkg/sstore/memops.go +++ b/wavesrv/pkg/sstore/memops.go @@ -190,6 +190,22 @@ func ScreenMemSetIndicatorLevel(screenId string, level StatusIndicatorLevel) { ScreenMemStore[screenId].StatusIndicator = StatusIndicatorLevel_None } +func GetCurrentIndicatorState() ([]*ScreenStatusIndicatorType, []*ScreenNumRunningCommandsType) { + MemLock.Lock() + defer MemLock.Unlock() + indicators := []*ScreenStatusIndicatorType{} + numRunningCommands := []*ScreenNumRunningCommandsType{} + for screenId, screenMem := range ScreenMemStore { + if screenMem.StatusIndicator > 0 { + indicators = append(indicators, &ScreenStatusIndicatorType{ScreenId: screenId, Status: screenMem.StatusIndicator}) + } + if screenMem.NumRunningCommands > 0 { + numRunningCommands = append(numRunningCommands, &ScreenNumRunningCommandsType{ScreenId: screenId, Num: screenMem.NumRunningCommands}) + } + } + return indicators, numRunningCommands +} + // safe because we return a copy func GetScreenMemState(screenId string) *ScreenMemState { MemLock.Lock() diff --git a/wavesrv/pkg/sstore/sstore.go b/wavesrv/pkg/sstore/sstore.go index 5038272d9..863e97f54 100644 --- a/wavesrv/pkg/sstore/sstore.go +++ b/wavesrv/pkg/sstore/sstore.go @@ -1506,10 +1506,10 @@ func SetStatusIndicatorLevel_Update(ctx context.Context, update *ModelUpdate, sc } } - update.ScreenStatusIndicator = &ScreenStatusIndicatorType{ + update.ScreenStatusIndicators = []*ScreenStatusIndicatorType{{ ScreenId: screenId, Status: newStatus, - } + }} return nil } @@ -1539,10 +1539,10 @@ func ResetStatusIndicator(screenId string) error { func IncrementNumRunningCmds_Update(update *ModelUpdate, screenId string, delta int) { newNum := ScreenMemIncrementNumRunningCommands(screenId, delta) log.Printf("IncrementNumRunningCmds_Update: screenId=%s, newNum=%d\n", screenId, newNum) - update.ScreenNumRunningCommands = &ScreenNumRunningCommandsType{ + update.ScreenNumRunningCommands = []*ScreenNumRunningCommandsType{{ ScreenId: screenId, Num: newNum, - } + }} } func IncrementNumRunningCmds(screenId string, delta int) { diff --git a/wavesrv/pkg/sstore/updatebus.go b/wavesrv/pkg/sstore/updatebus.go index f15c885a2..51d8aa472 100644 --- a/wavesrv/pkg/sstore/updatebus.go +++ b/wavesrv/pkg/sstore/updatebus.go @@ -63,8 +63,8 @@ type ModelUpdate struct { SessionTombstones []*SessionTombstoneType `json:"sessiontombstones,omitempty"` OpenAICmdInfoChat []*packet.OpenAICmdInfoChatMessage `json:"openaicmdinfochat,omitempty"` AlertMessage *AlertMessageType `json:"alertmessage,omitempty"` - ScreenStatusIndicator *ScreenStatusIndicatorType `json:"screenstatusindicator,omitempty"` - ScreenNumRunningCommands *ScreenNumRunningCommandsType `json:"screennumrunningcommands,omitempty"` + ScreenStatusIndicators []*ScreenStatusIndicatorType `json:"screenstatusindicators,omitempty"` + ScreenNumRunningCommands []*ScreenNumRunningCommandsType `json:"screennumrunningcommands,omitempty"` } func (*ModelUpdate) UpdateType() string {