registerExtensions method

void registerExtensions()

Registers the extension. Call once, before runApp.

Implementation

void registerExtensions() {
  GuestExtensions.register('ext.flutterware.imagesSettled', (_, _) async {
    // A frame first, then the count, in that order on purpose. The frame is
    // what *starts* the loads: a fresh guest has built nothing, and a count
    // taken before the first build reads zero for the wrong reason. It is
    // also what paints anything delivered since the last one, so a zero
    // describes pixels on screen rather than bytes in a cache.
    //
    // Bounded because this is an RPC the capture waits on — same reasoning
    // as `setParameters`: a guest that has stopped drawing should make the
    // caller late, not stuck.
    SchedulerBinding.instance.scheduleFrame();
    await SchedulerBinding.instance.endOfFrame.timeout(
      const Duration(seconds: 2),
      onTimeout: () {},
    );
    return developer.ServiceExtensionResponse.result(
      jsonEncode({
        'pending': PaintingBinding.instance.imageCache.pendingImageCount,
        'transient': SchedulerBinding.instance.transientCallbackCount,
      }),
    );
  });
}