NAME

Developer::Dashboard::SystemMenu::Runner - opt-in native indicator menu lifecycle

PURPOSE

This module maps the configured Dashboard indicators for one operating system and runs the native System Menu adapter in its own worker process. It keeps the blocking native event loop out of the command's main execution path and out of the GoRoutine engine: the menu worker is a plain process, so the foreground web service never has to pump an engine while it blocks in its server loop.

WHY IT EXISTS

System Menu's run method owns a blocking native event loop. Running that loop directly would prevent the Dashboard process from continuing its normal work. This runner starts no native adapter when the current platform has no enabled indicator, and it retains one explicit stop-and-wait lifecycle for enabled menus. The worker is a separate process because the foreground callback blocks in the web server (Starman for plain HTTP, the SSL frontend for HTTPS), and neither server loop pumps the GoRoutine engine: a timer routine driving the menu would never fire. The menu items are plain data (name and icon only, no code references), so they travel to the worker as JSON on its stdin.

WHEN TO USE

Use this runner from the private web-foreground runtime after configuration layers and current indicator state have been loaded. Do not instantiate it from lightweight CLI commands. Native desktop visibility and shutdown still require hosted checks on each supported operating system.

HOW TO USE

my $runner = Developer::Dashboard::SystemMenu::Runner->new(
    config   => $config,
    store    => $indicator_store,
    platform => 'macos',
);
my $worker = $runner->start;
# ... normal Dashboard runtime ...
$runner->stop if $worker;

start returns undef and does not load the native adapter when there are no visible configured indicators. When enabled, it projects current states in configuration order, writes them as JSON to a temporary file, and spawns the private system-menu-foreground helper with that file as the worker's stdin. stop terminates the worker, waits for it to exit, and removes the items file.

run_with($callback) owns the common foreground-service lifecycle. It starts the menu, invokes the callback, then requests and waits for menu shutdown after either a normal callback return or an exception. The callback must be a code reference. Its scalar result is returned unchanged; service errors are re-thrown, and shutdown errors remain visible (including alongside a service error).

EXAMPLES

An opt-in macOS configuration can select the build indicator:

{
    indicators => [
        { name => 'build', indicator => { macos => 1 } },
    ],
}

The same runner accepts windows or ubuntu as its platform key. Tests may pass a worker_command array reference to substitute a fake worker process instead of the private helper; production callers omit it. A disabled configuration returns no worker and does not spawn a process.

The foreground web service uses the wrapper form:

my $status = $runner->run_with(sub { $server->run });

WHAT USES IT

The runtime menu integration uses this class to connect merged configuration, IndicatorStore state, the pure SystemMenu projection, and the native event loop. The focused Docker regression test injects a fake worker command to verify selection and lifecycle without claiming native UI behavior.