storeState method

Future<void> storeState()

Implementation

Future<void> storeState() async {
  await StorageMapper.initDatabaseExpander();
  statePath ??= StorageMapper.expandDbFileName('');
  try {
    GeigerApi.logger.log(Level.INFO, 'storing state to $statePath');

    final ByteSink out = ByteSink();
    plugins.toByteArrayStream(out);
    menuItems.toByteArrayStream(out);
    out.close();

    final IOSink file = File('$statePath/GeigerApi.$id.state').openWrite();
    file.add(await out.bytes);
    await file.close();
  } catch (ioe) {
    GeigerApi.logger
        .log(Level.SEVERE, 'unable to write state file to $statePath', ioe);
  }
}