Skip to content

Commit

Permalink
prevent saving unloaded data
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlezucc committed Jul 22, 2022
1 parent 578acc7 commit de6f824
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ServerData {
static final _manualSaveWatch = Stopwatch();
static final directory = Directory('database');
static final file = File(path.join(directory.path, 'data.json'));
static bool _isInitialized = false;

final histogram = PlayingHistogram(path.join(directory.path, 'histogram'));
final accounts = <Account>[];
Expand All @@ -34,6 +35,7 @@ class ServerData {
await histogram.load();
histogram.startTracking();
_manualSaveWatch.start();
_isInitialized = true;
}

Account getAccount(String email, {bool alreadyEncrypted = false}) {
Expand Down Expand Up @@ -81,6 +83,8 @@ class ServerData {
}

Future<void> save() async {
if (!_isInitialized) return print('Not initialized, skipped save.');

var json = JsonEncoder.withIndent(' ').convert(toJson());
// print(json);
await file.writeAsString(json);
Expand Down

0 comments on commit de6f824

Please sign in to comment.