From 014908a8d7a02774b0455899dd52d26f4d968aaf Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Wed, 29 Jul 2026 13:05:48 -0400 Subject: [PATCH] feat(tui): reload config file changes --- packages/tui/src/config/index.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/tui/src/config/index.tsx b/packages/tui/src/config/index.tsx index faebe44f406..09ed747b098 100644 --- a/packages/tui/src/config/index.tsx +++ b/packages/tui/src/config/index.tsx @@ -2,8 +2,10 @@ export * as Config from "." import { createBindingLookup } from "@opentui/keymap/extras" import { Schema } from "effect" -import { createContext, type JSX, useContext } from "solid-js" +import { createContext, onCleanup, type JSX, useContext } from "solid-js" import { createStore, reconcile } from "solid-js/store" +import { watch } from "fs" +import path from "path" import { TuiKeybind } from "./keybind" export interface Interface { @@ -238,12 +240,23 @@ export function ConfigProvider(props: { }) { const [config, setConfig] = createStore(props.config) const host = props.service + const apply = (info: Info) => setConfig(reconcile(resolve(info, props.options ?? { terminalSuspend: true }))) const update = async (update: (draft: any) => void) => { if (!host) throw new Error("Config updates are not available") const info = await host.update(update) - setConfig(reconcile(resolve(info, props.options ?? { terminalSuspend: true }))) + apply(info) return info } + let reload = Promise.resolve() + const watcher = host?.path + ? watch(path.dirname(host.path), () => { + reload = reload + .then(() => host.get()) + .then(apply) + .catch(() => {}) + }) + : undefined + onCleanup(() => watcher?.close()) return ( {props.children} )