install static method

void install()

Idempotent install. Safe to call multiple times within the same isolate lifetime.

Implementation

static void install() {
  if (_installed) return;
  _installed = true;
  TelescopePlugin.registerHttpAdapter(MagicHttpFacadeAdapter());
  TelescopePlugin.registerWatcher(MagicModelWatcher());
  TelescopePlugin.registerWatcher(MagicCacheWatcher());
  TelescopePlugin.registerWatcher(MagicEventWatcher());
  TelescopePlugin.registerWatcher(MagicGateWatcher());
  TelescopePlugin.registerWatcher(MagicQueryWatcher());

  // Bridge dusk's `wait_for_network_idle` poll loop to the telescope
  // in-flight count. Dusk keeps a function-pointer indirection so it
  // does not need a hard dep on telescope; we point that pointer at
  // the real source as part of the install side-effect.
  pendingHttpCountReader = () => TelescopeStore.pendingHttpCount;

  // Bridge dusk's `console` + `exceptions` tools to telescope's recent
  // ring-buffer accessors. Project telescope record shapes into the
  // dusk handler envelope (logger/type/stackHead key remap).
  recentLogsReader = ({int limit = 50, String? minLevel}) =>
      TelescopeStore.recentLogs(limit: limit, minLevel: minLevel)
          .map(
            (r) => <String, dynamic>{
              'level': r.level,
              'message': r.message,
              'time': r.time.toIso8601String(),
              'logger': r.loggerName,
              if (r.error != null) 'error': r.error,
            },
          )
          .toList();
  recentExceptionsReader = ({int limit = 20}) =>
      TelescopeStore.recentExceptions(limit: limit)
          .map(
            (r) => <String, dynamic>{
              'type': r.exceptionType,
              'message': r.message,
              'time': r.time.toIso8601String(),
              if (r.stackTrace != null)
                'stackHead': r.stackTrace!.split('\n').take(3).join('\n'),
            },
          )
          .toList();
}