restoreState method
Implementation
Future<void> restoreState() async {
if (await _isWorkingDirectoryWriteable()) {
statePath = '.';
} else {
await StorageMapper.initDatabaseExpander();
statePath ??= StorageMapper.expandDbFileName('');
}
try {
GeigerApi.logger.log(Level.INFO, 'loading state from $statePath');
final file = File('$statePath/GeigerApi.$id.state');
final ByteStream stream = ByteStream(null, await file.readAsBytes());
await StorableHashMap.fromByteArrayStream(stream, plugins);
// set all ports to 0
for (final entry in plugins.entries) {
plugins[entry.key] = PluginInformation(
entry.value.id,
entry.value.executable,
0,
entry.value.declaration,
entry.value.secret,
);
}
await StorableHashMap.fromByteArrayStream(stream, menuItems);
} catch (e) {
GeigerApi.logger.log(Level.WARNING,
'unable to read state file from $statePath... rewriting', e);
await storeState();
}
}