import { brainKernel, VERSION } from "../kernel.js"; import { createCoreRoutes, legacyAliases } from "../routes.js"; import { createSettingsUiRoutes } from "../settings-ui/routes.js"; export const name = 'dsh-brain-ui'; /** Services required before `apply` runs. */ export const inject = ['webServer']; /** The pre-rename row id; only used to point a stale profile at the new row. */ const LEGACY_BUNDLE_ID = 'dsh-brain-settings-ui'; function profileMentionsLegacyId(ctx) { try { const face = ctx; return [face.config, face.settings].some((value) => value !== undefined && JSON.stringify(value).includes(LEGACY_BUNDLE_ID)); } catch { return false; } } /** Register the sub-plugin with the host. */ export function apply(ctx, config) { const logger = ctx.logger('dsh-brain'); const kernel = brainKernel(config, logger); kernel.activate('ui'); kernel.logEvent('boot.entry', { bundle: 'ui' }); ctx.effect(() => () => kernel.deactivate('ui'), 'dsh-brain-ui: activation'); // We never rewrite host files: if the old row is visible in the live config // face, tell the user which row to re-toggle after the rename. if (profileMentionsLegacyId(ctx)) { logger.info('detected the old plugin id ' + LEGACY_BUNDLE_ID + '; re-apply the plugin toggle under dsh-brain-ui in Settings → Plugins'); } const webServer = ctx.webServer; if (webServer === undefined) { logger.warn('webServer service unavailable; the configuration page stays disabled'); return; } const routes = [ ...createSettingsUiRoutes({ version: VERSION, store: kernel.store }), ...createCoreRoutes(kernel.routeDeps()), ]; routes.push(...legacyAliases(routes)); for (const route of routes) { ctx.effect(() => webServer.register(route), `dsh-brain-ui: route ${route.path}`); } }