tryScanAndConnectAndStart method
Suitable for inclusion in initState or other startup code, this function will attempt connection, start app (loading Lua, sprites) and optionally call run() (unawaited) to save a few connect/start/(run) steps
Implementation
Future<void> tryScanAndConnectAndStart({required bool andRun}) async {
if (currentState == ApplicationState.disconnected) {
_log.fine('calling scanOrReconnectFrame');
await scanOrReconnectFrame();
if (currentState == ApplicationState.connected) {
_log.fine('calling startApplication');
await startApplication();
if (currentState == ApplicationState.ready && andRun) {
// don't await this one for run() functions that keep running a main loop, so initState() can complete
_log.fine('calling run');
run();
}
else {
_log.fine('not ready or andRun is false - not calling run');
}
}
else {
// connection didn't succeed, decide what you want to do if the app starts and the user doesn't tap Frame to wake it up
_log.fine('not connected - finishing start attempt');
}
}
else {
_log.fine('not in disconnected state - not attempting scan/connect');
}
}