onLaunch method

Future<DeferredEntry> onLaunch()

Call once at launch, before anything decides what to show.

The launch is marked as seen either way: a recovery offered twice is a nag, and a code recovered twice would open the same entry again on a launch the viewer did not connect to it.

Implementation

Future<DeferredEntry> onLaunch() async {
  if (!await _store.isFirstLaunch()) {
    return const DeferredEntry(DeferredEntryOutcome.none);
  }
  await _store.markLaunched();

  final source = _source;
  if (source == null) {
    // No mechanism on this platform. Silence here is the failure the
    // standard names; an offer costs one dismissible affordance.
    return const DeferredEntry(DeferredEntryOutcome.offerRecovery);
  }

  try {
    final code = await source.pendingCode();
    if (code == null || code.isEmpty) {
      // The platform answered and said this install did not come from an
      // entry. Offering recovery here would be a prompt about something
      // that never happened.
      return const DeferredEntry(DeferredEntryOutcome.none);
    }
    return DeferredEntry(DeferredEntryOutcome.recovered, code);
  } catch (e) {
    // A mechanism that failed is a mechanism we do not have.
    _logger.warn('entry.deferred.source_failed', {'error': e.toString()});
    return const DeferredEntry(DeferredEntryOutcome.offerRecovery);
  }
}