Skip to content

Commit

Permalink
register an feblock wshclient
Browse files Browse the repository at this point in the history
  • Loading branch information
sawka committed Sep 18, 2024
1 parent 85f03eb commit 28d7d91
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
14 changes: 14 additions & 0 deletions frontend/app/view/term/term-wsh.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 10 additions & 1 deletion frontend/app/view/term/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -89,10 +91,13 @@ class TermViewModel {
blockBg: jotai.Atom<MetaType>;
manageConnection: jotai.Atom<boolean>;
connStatus: jotai.Atom<ConnStatus>;
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>(`block:${blockId}`);
this.termMode = jotai.atom((get) => {
Expand Down Expand Up @@ -132,6 +137,10 @@ class TermViewModel {
});
}

dispose() {
DefaultRouter.unregisterRoute(makeFeBlockRouteId(this.blockId));
}

giveFocus(): boolean {
let termMode = globalStore.get(this.termMode);
if (termMode == "term") {
Expand Down
4 changes: 4 additions & 0 deletions pkg/wshutil/wshrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 28d7d91

Please sign in to comment.