mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
code to restore indicator state on refresh (#260)
* code to restore indicator state on refresh * fix style
This commit is contained in:
parent
8f64d6a589
commit
198de02a65
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,8 +326,8 @@ type ModelUpdateType = {
|
||||
remoteview?: RemoteViewType;
|
||||
openaicmdinfochat?: OpenAICmdInfoChatMessageType[];
|
||||
alertmessage?: AlertMessageType;
|
||||
screenstatusindicator?: ScreenStatusIndicatorUpdateType;
|
||||
screennumrunningcommands?: ScreenNumRunningCommandsUpdateType;
|
||||
screenstatusindicators?: ScreenStatusIndicatorUpdateType[];
|
||||
screennumrunningcommands?: ScreenNumRunningCommandsUpdateType[];
|
||||
};
|
||||
|
||||
type HistoryViewDataType = {
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user