load static method

Future<MountStore> load({
  1. String? home,
})

Loads the store, returning an empty one when no file exists yet.

Implementation

static Future<MountStore> load({String? home}) async {
  final file = File(path(home: home));
  if (!await file.exists()) return MountStore(home: home);
  final json = jsonDecode(await file.readAsString()) as Map<String, dynamic>;
  final mounts = <String, MountRecord>{};
  final raw = json['mounts'];
  if (raw is Map) {
    raw.forEach((id, value) {
      mounts[id.toString()] = MountRecord.fromJson(
        (value as Map).cast<String, dynamic>(),
      );
    });
  }
  return MountStore(mounts: mounts, home: home);
}