refactor: Remove moor
This commit is contained in:
parent
39b8876837
commit
9ef0c71f81
18 changed files with 9 additions and 501 deletions
|
|
@ -1,44 +1,9 @@
|
|||
import 'package:matrix/matrix.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:localstorage/localstorage.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:core';
|
||||
import './database/shared.dart';
|
||||
import '../config/setting_keys.dart';
|
||||
import 'package:random_string/random_string.dart';
|
||||
|
||||
Future<Database> getDatabase(Client client) async {
|
||||
while (_generateDatabaseLock) {
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
}
|
||||
_generateDatabaseLock = true;
|
||||
try {
|
||||
if (_db != null) return _db;
|
||||
final store = Store();
|
||||
var password = await store.getItem(SettingKeys.databasePassword);
|
||||
var newPassword = false;
|
||||
if (password == null || password.isEmpty) {
|
||||
newPassword = true;
|
||||
password = randomString(255);
|
||||
}
|
||||
_db = await constructDb(
|
||||
logStatements: false,
|
||||
filename: 'moor.sqlite',
|
||||
password: password,
|
||||
);
|
||||
if (newPassword) {
|
||||
await store.setItem(SettingKeys.databasePassword, password);
|
||||
}
|
||||
return _db;
|
||||
} finally {
|
||||
_generateDatabaseLock = false;
|
||||
}
|
||||
}
|
||||
|
||||
Database _db;
|
||||
bool _generateDatabaseLock = false;
|
||||
|
||||
// see https://github.com/mogol/flutter_secure_storage/issues/161#issuecomment-704578453
|
||||
class AsyncMutex {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue