signalDartSession method

void signalDartSession(
  1. Map<String, int> portMap
)

Signal the running Python program that a new Dart VM session is active. On a fresh start where Python isn't loaded yet, this is a cheap no-op inside libdart_bridge. On Android process reuse it fires every Python callback registered via dart_bridge.add_session_restart_handler(...), carrying the new native port numbers as a {label: port} map.

portMap keys are arbitrary labels — current callers use "protocol" and "exit" to match flet's build template wiring.

No-op when running against a pre-1.3.0 libdart_bridge.

Implementation

void signalDartSession(Map<String, int> portMap) {
  final f = _signalDartSession;
  if (f == null || portMap.isEmpty) return;
  using((Arena arena) {
    final labels = arena<Pointer<Utf8>>(portMap.length);
    final ports = arena<Int64>(portMap.length);
    var i = 0;
    for (final entry in portMap.entries) {
      labels[i] = entry.key.toNativeUtf8(allocator: arena);
      ports[i] = entry.value;
      i++;
    }
    f(portMap.length, labels, ports);
  });
}