// Adapted from dsh-mnemon native-sidebar.tsx (MIT), see vendor/dsh-mnemon/LICENSE. // Registers the Brain panel on the two native shell seats: // sidebar.panellist -> the left-rail row (glyph only) // main -> the centre panel mounted while selected // Both are lazy seats: when the shell does not provide them the inject callback // simply never runs and the settings card fallback stays in place. import * as React from 'react' import { BrainIcon } from './brain-icon' import { BrainPanel } from './BrainPanel' export const PANEL_ID = 'dsh-brain' export const PANEL_ORDER = 30 export function registerBrainPanel(ctx: any): () => void { let stopNative: (() => void) | undefined let disposed = false try { stopNative = ctx.slots.inject('main', () => ctx.slots.inject('sidebar.panellist', () => { const icon = (props: any) => React.createElement(BrainIcon, { size: props?.size ?? 18 }) const stopMain = ctx.slots.register({ name: 'main', key: PANEL_ID }, BrainPanel as never) let stopIcon: (() => void) | undefined try { stopIcon = ctx.slots.register({ name: 'sidebar.panellist', id: PANEL_ID, order: PANEL_ORDER, label: () => 'Brain', locale: 'dsh-brain', }, icon as never) } catch (failure) { stopMain?.() throw failure } return () => { stopIcon?.() stopMain?.() } }), ) } catch (failure) { if (typeof console !== 'undefined') { console.info('[dsh-brain] sidebar panel seats unavailable; the settings card fallback stays active: ' + (failure instanceof Error ? failure.message : String(failure))) } } return () => { if (disposed) return disposed = true try { stopNative?.() } catch { /* a seat disposer must never break plugin teardown */ } stopNative = undefined } }