stopApplication method

Future<void> stopApplication()
inherited

the SimpleFrameApp subclass can override with application-specific code if necessary

Implementation

Future<void> stopApplication() async {
  currentState = ApplicationState.stopping;
  if (mounted) setState(() {});

  // send a break to stop the Lua app loop on Frame
  await frame!.sendBreakSignal();
  await Future.delayed(const Duration(milliseconds: 500));

  // only if there are lua files uploaded to Frame (e.g. frame_app.lua companion app, other helper functions, minified versions)
  List<String> luaFiles = _filterLuaFiles(
      (await AssetManifest.loadFromAssetBundle(rootBundle)).listAssets());

  if (luaFiles.isNotEmpty) {
    // clean up by deregistering any handler
    await frame!.sendString('frame.bluetooth.receive_callback(nil);print(0)',
        awaitResponse: true);

    for (var file in luaFiles) {
      // delete any prior scripts
      await frame!.sendString(
          'frame.file.remove("${file.split('/').last}");print(0)',
          awaitResponse: true);
    }
  }

  currentState = ApplicationState.connected;
  if (mounted) setState(() {});
}