mirror of
				https://gitlab.com/famedly/fluffychat.git
				synced 2025-11-03 22:07:23 +01:00 
			
		
		
		
	feat: Set pragmas on desktop as well
This commit is contained in:
		
							parent
							
								
									9ce6743948
								
							
						
					
					
						commit
						1f01950e92
					
				@ -28,25 +28,23 @@ class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
 | 
			
		||||
  static Future<FluffyBoxDatabase> databaseBuilder(Client client) async {
 | 
			
		||||
    Logs().d('Open FluffyBox...');
 | 
			
		||||
    String? password;
 | 
			
		||||
    if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
 | 
			
		||||
      try {
 | 
			
		||||
        const secureStorage = FlutterSecureStorage();
 | 
			
		||||
        final containsEncryptionKey =
 | 
			
		||||
            await secureStorage.containsKey(key: _cipherStorageKey);
 | 
			
		||||
        if (!containsEncryptionKey) {
 | 
			
		||||
          final key = SecureRandom(_cipherStorageKeyLength).base64;
 | 
			
		||||
          await secureStorage.write(
 | 
			
		||||
            key: _cipherStorageKey,
 | 
			
		||||
            value: key,
 | 
			
		||||
          );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // workaround for if we just wrote to the key and it still doesn't exist
 | 
			
		||||
        password = await secureStorage.read(key: _cipherStorageKey);
 | 
			
		||||
        if (password == null) throw MissingPluginException();
 | 
			
		||||
      } on MissingPluginException catch (_) {
 | 
			
		||||
        Logs().i('FluffyBox encryption is not supported on this platform');
 | 
			
		||||
    try {
 | 
			
		||||
      const secureStorage = FlutterSecureStorage();
 | 
			
		||||
      final containsEncryptionKey =
 | 
			
		||||
          await secureStorage.containsKey(key: _cipherStorageKey);
 | 
			
		||||
      if (!containsEncryptionKey) {
 | 
			
		||||
        final key = SecureRandom(_cipherStorageKeyLength).base64;
 | 
			
		||||
        await secureStorage.write(
 | 
			
		||||
          key: _cipherStorageKey,
 | 
			
		||||
          value: key,
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // workaround for if we just wrote to the key and it still doesn't exist
 | 
			
		||||
      password = await secureStorage.read(key: _cipherStorageKey);
 | 
			
		||||
      if (password == null) throw MissingPluginException();
 | 
			
		||||
    } on MissingPluginException catch (_) {
 | 
			
		||||
      Logs().i('FluffyBox encryption is not supported on this platform');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    final db = FluffyBoxDatabase(
 | 
			
		||||
@ -58,6 +56,13 @@ class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
 | 
			
		||||
    return db;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static Future<void> _onConfigure(sqflite.Database db) async {
 | 
			
		||||
    await db.execute('PRAGMA page_size = 8192');
 | 
			
		||||
    await db.execute('PRAGMA cache_size = 16384');
 | 
			
		||||
    await db.execute('PRAGMA temp_store = MEMORY');
 | 
			
		||||
    await db.execute('PRAGMA journal_mode = WAL');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static Future<sqflite.Database> _openSqlDatabase(
 | 
			
		||||
    Client client,
 | 
			
		||||
    String? password,
 | 
			
		||||
@ -68,16 +73,17 @@ class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
 | 
			
		||||
        final db = await sqflite.openDatabase(
 | 
			
		||||
          path,
 | 
			
		||||
          password: password,
 | 
			
		||||
          onConfigure: (db) async {
 | 
			
		||||
            await db.execute('PRAGMA page_size = 8192');
 | 
			
		||||
            await db.execute('PRAGMA cache_size = 16384');
 | 
			
		||||
            await db.execute('PRAGMA temp_store = MEMORY');
 | 
			
		||||
            await db.rawQuery('PRAGMA journal_mode = WAL');
 | 
			
		||||
          },
 | 
			
		||||
          onConfigure: _onConfigure,
 | 
			
		||||
        );
 | 
			
		||||
        return db;
 | 
			
		||||
      }
 | 
			
		||||
      final db = await ffi.databaseFactoryFfi.openDatabase(path);
 | 
			
		||||
      final db = await ffi.databaseFactoryFfi.openDatabase(
 | 
			
		||||
        path,
 | 
			
		||||
        options: sqflite.SqlCipherOpenDatabaseOptions(
 | 
			
		||||
          password: password,
 | 
			
		||||
          onConfigure: _onConfigure,
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
      return db;
 | 
			
		||||
    } catch (_) {
 | 
			
		||||
      File(path).delete();
 | 
			
		||||
 | 
			
		||||
@ -782,7 +782,7 @@ packages:
 | 
			
		||||
    description:
 | 
			
		||||
      path: "."
 | 
			
		||||
      ref: "krille/idb"
 | 
			
		||||
      resolved-ref: "362652e6a43339ade2fb37ba02b730b7c99bf8ad"
 | 
			
		||||
      resolved-ref: "48f75edae963c7f7d29b0749c60292c8a59b6d5b"
 | 
			
		||||
      url: "https://gitlab.com/famedly/company/frontend/famedlysdk.git"
 | 
			
		||||
    source: git
 | 
			
		||||
    version: "0.7.0-nullsafety.6"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user