From 28d7d91d314c36063935e8db24419b60dcc20222 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 17 Sep 2024 23:29:17 -0700 Subject: [PATCH] register an feblock wshclient --- frontend/app/view/term/term-wsh.tsx | 14 ++++++++++++++ frontend/app/view/term/term.tsx | 11 ++++++++++- pkg/wshutil/wshrouter.go | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 frontend/app/view/term/term-wsh.tsx diff --git a/frontend/app/view/term/term-wsh.tsx b/frontend/app/view/term/term-wsh.tsx new file mode 100644 index 000000000..cccf57bde --- /dev/null +++ b/frontend/app/view/term/term-wsh.tsx @@ -0,0 +1,14 @@ +// Copyright 2024, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { WshClient } from "@/app/store/wshclient"; +import { makeFeBlockRouteId } from "@/app/store/wshrouter"; + +export class TermWshClient extends WshClient { + blockId: string; + + constructor(blockId: string) { + super(makeFeBlockRouteId(blockId)); + this.blockId = blockId; + } +} diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index e15b97b8b..4cc44edb7 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -3,7 +3,9 @@ import { waveEventSubscribe } from "@/app/store/wps"; import { RpcApi } from "@/app/store/wshclientapi"; -import { WindowRpcClient } from "@/app/store/wshrpcutil"; +import { makeFeBlockRouteId } from "@/app/store/wshrouter"; +import { DefaultRouter, WindowRpcClient } from "@/app/store/wshrpcutil"; +import { TermWshClient } from "@/app/view/term/term-wsh"; import { VDomView } from "@/app/view/term/vdom"; import { NodeModel } from "@/layout/index"; import { WOS, atoms, getConnStatusAtom, globalStore, useSettingsPrefixAtom } from "@/store/global"; @@ -89,10 +91,13 @@ class TermViewModel { blockBg: jotai.Atom; manageConnection: jotai.Atom; connStatus: jotai.Atom; + termWshClient: TermWshClient; constructor(blockId: string, nodeModel: NodeModel) { this.viewType = "term"; this.blockId = blockId; + this.termWshClient = new TermWshClient(blockId); + DefaultRouter.registerRoute(makeFeBlockRouteId(blockId), this.termWshClient); this.nodeModel = nodeModel; this.blockAtom = WOS.getWaveObjectAtom(`block:${blockId}`); this.termMode = jotai.atom((get) => { @@ -132,6 +137,10 @@ class TermViewModel { }); } + dispose() { + DefaultRouter.unregisterRoute(makeFeBlockRouteId(this.blockId)); + } + giveFocus(): boolean { let termMode = globalStore.get(this.termMode); if (termMode == "term") { diff --git a/pkg/wshutil/wshrouter.go b/pkg/wshutil/wshrouter.go index 26fdb8a39..f77719e31 100644 --- a/pkg/wshutil/wshrouter.go +++ b/pkg/wshutil/wshrouter.go @@ -60,6 +60,10 @@ func MakeProcRouteId(procId string) string { return "proc:" + procId } +func MakeFeBlockRouteId(blockId string) string { + return "feblock:" + blockId +} + var DefaultRouter = NewWshRouter() func NewWshRouter() *WshRouter {