fetchHistory method

Future<List<History>> fetchHistory({
  1. List<String>? historyPaths,
})

Implementation

Future<List<History>> fetchHistory({List<String>? historyPaths}) async {
  historyPaths ??= paths(profileFile: historyFile);

  List<History> histories = [];

  for (var historyPath in historyPaths) {
    var size = await File(historyPath).length();
    if (size == 0) continue;

    var dir = await Directory.systemTemp.createTemp();
    var f = File('${dir.path}/$historyFile');
    await f.create();
    String tmpFile = f.path;

    await copyFile(File(historyPath), tmpFile);

    var conn =
        sqlite3.open('file:$tmpFile?mode=ro&immutable=1&nolock=1', uri: true);
    var result = conn.select(historySQL);
    for (var e in result) {
      histories.add(History.fromJson(e));
    }
    conn.dispose();
  }

  return histories;
}