/**
 * widget-safe.js - tolerant widget registration for mixed SF runtimes.
 *
 * Purpose: keep bundled SF extensions loadable when the installed host is older
 * than the source extension and does not expose widget APIs yet.
 *
 * Consumer: ambient SF widgets that are useful in TUI hosts but optional in
 * headless, RPC, or stale extension hosts.
 */

/**
 * Set or clear a widget when the active host supports widgets.
 *
 * Purpose: prevent optional UI registration from aborting extension startup
 * when ctx.ui.setWidget is missing or throws in a partially upgraded runtime.
 *
 * Consumer: SF health, notification, and auto-progress widgets.
 */
export function safeSetWidget(ctx, key, content, options) {
	try {
		if (typeof ctx?.ui?.setWidget !== "function") return false;
		ctx.ui.setWidget(key, content, options);
		return true;
	} catch {
		return false;
	}
}
