From b57df6de103eba6b71de4715d56514ce849c1c65 Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Mon, 11 Nov 2024 18:02:40 -0500 Subject: [PATCH 1/2] feat: add a button to rerun in widget with cmd --- docs/docs/customwidgets.mdx | 2 +- frontend/app/view/term/term.tsx | 42 +++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/docs/docs/customwidgets.mdx b/docs/docs/customwidgets.mdx index 899a8d26d3..8056377d81 100644 --- a/docs/docs/customwidgets.mdx +++ b/docs/docs/customwidgets.mdx @@ -88,7 +88,7 @@ The `WidgetConfigType` takes the usual options common to all widgets. The `MetaT | Key | Description | | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | "view" | A string that specifies the general type of widget. In the case of custom terminal widgets, this must be set to `"term"`. | -| "controller" | A string that specifies the type of command being used. For more persistent shell sessions, set it to "shell". For one off commands, set it to "cmd". Note that it is often possible to achieve the same result through each depending on the command being used. | +| "controller" | A string that specifies the type of command being used. For more persistent shell sessions, set it to "shell". For one off commands, set it to `"cmd"`. When `"cmd"` is set, the widget has an additional refresh button in its header that allows the command to be re-run. | | "cmd" | (optional) When the `"controller"` is set to `"cmd"`, this option provides the actual command to be run. Note that because it is run as a command, there is no shell session unless you are launching a command that contains a shell session itself. Defaults to an empty string. | | "cmd:interactive" | (optional) When the `"controller"` is set to `"term", this boolean adds the interactive flag to the launched terminal. Defaults to false. | | "cmd:login" | (optional) When the `"controller"` is set to `"term"`, this boolean adds the login flag to the term command. Defaults to false. | diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index 23c2333cfb..0775f0b574 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -61,6 +61,7 @@ class TermViewModel { fontSizeAtom: jotai.Atom; termThemeNameAtom: jotai.Atom; noPadding: jotai.PrimitiveAtom; + endIconButtons: jotai.Atom; constructor(blockId: string, nodeModel: BlockNodeModel) { this.viewType = "term"; @@ -176,6 +177,19 @@ class TermViewModel { }); }); this.noPadding = jotai.atom(true); + this.endIconButtons = jotai.atom((get) => { + const blockData = get(this.blockAtom); + if (blockData?.meta?.["controller"] != "cmd") { + return []; + } + return [ + { + elemtype: "iconbutton", + icon: "refresh", + click: this.forceRestartController.bind(this), + }, + ]; + }); } setTermMode(mode: "term" | "vdom") { @@ -296,6 +310,20 @@ class TermViewModel { }); } + forceRestartController() { + const termsize = { + rows: this.termRef.current?.terminal?.rows, + cols: this.termRef.current?.terminal?.cols, + }; + const prtn = RpcApi.ControllerResyncCommand(TabRpcClient, { + tabid: globalStore.get(atoms.staticTabId), + blockid: this.blockId, + forcerestart: true, + rtopts: { termsize: termsize }, + }); + prtn.catch((e) => console.log("error controller resync (force restart)", e)); + } + getSettingsMenuItems(): ContextMenuItem[] { const fullConfig = globalStore.get(atoms.fullConfigAtom); const termThemes = fullConfig?.termthemes ?? {}; @@ -354,19 +382,7 @@ class TermViewModel { fullMenu.push({ type: "separator" }); fullMenu.push({ label: "Force Restart Controller", - click: () => { - const termsize = { - rows: this.termRef.current?.terminal?.rows, - cols: this.termRef.current?.terminal?.cols, - }; - const prtn = RpcApi.ControllerResyncCommand(TabRpcClient, { - tabid: globalStore.get(atoms.staticTabId), - blockid: this.blockId, - forcerestart: true, - rtopts: { termsize: termsize }, - }); - prtn.catch((e) => console.log("error controller resync (force restart)", e)); - }, + click: this.forceRestartController.bind(this), }); if (blockData?.meta?.["term:vdomtoolbarblockid"]) { fullMenu.push({ type: "separator" }); From f9b4a331fa370cdd483cfaf9866db58ec073d7d6 Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Mon, 11 Nov 2024 18:15:45 -0500 Subject: [PATCH 2/2] fix: add Force Restart Controller tooltip --- frontend/app/view/term/term.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index 0775f0b574..c5914258ec 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -187,6 +187,7 @@ class TermViewModel { elemtype: "iconbutton", icon: "refresh", click: this.forceRestartController.bind(this), + title: "Force Restart Controller", }, ]; });