startOnBoot static method

void startOnBoot()

Starts the playbooks named in PLAYBOOK_ON_BOOT (comma separated) at PLAYBOOK_SPEED, once the app's first frame is on screen.

Nylo.init calls this in debug and profile builds.

Implementation

static void startOnBoot() {
  final String names = '${getEnv('PLAYBOOK_ON_BOOT', defaultValue: '') ?? ''}'
      .trim();
  if (names.isEmpty) return;
  final String speedName =
      '${getEnv('PLAYBOOK_SPEED', defaultValue: '') ?? ''}'.trim();
  final PlaybookSpeed? speed = speedName.isEmpty
      ? null
      : PlaybookSpeed.named(speedName);
  if (speedName.isNotEmpty && speed == null) {
    NyLogger.error(
      '[Playbook] PLAYBOOK_SPEED "$speedName" isn\'t a speed. Use '
      '${PlaybookSpeed.presets.keys.join(', ')}.',
    );
  }

  unawaited(() async {
    await WidgetsBinding.instance.waitUntilFirstFrameRasterized;
    await Future<void>.delayed(const Duration(milliseconds: 500));
    try {
      start([
        for (final String name in names.split(','))
          if (name.trim().isNotEmpty) name.trim(),
      ], speed: speed);
    } on LiveException catch (e) {
      NyLogger.error('[Playbook] PLAYBOOK_ON_BOOT: ${e.message}');
    }
  }());
}