@@ -705,6 +705,7 @@ final class WorkerRunner {
705705
706706 var supportsOpfs = false ;
707707 var opfsSupportsReadWriteUnsafe = false ;
708+ final databaseName = check.databaseName;
708709 if (check.shouldCheckOpfsCompatibility) {
709710 (
710711 basicSupport: supportsOpfs,
@@ -717,14 +718,15 @@ final class WorkerRunner {
717718 : false ;
718719
719720 var sharedCanSpawnDedicated = false ;
721+ final existingDatabases = < ExistingDatabase > {};
720722
721723 if (check.type == MessageType .sharedCompatibilityCheck) {
722724 if (globalContext.has ('Worker' )) {
723725 sharedCanSpawnDedicated = true ;
724726
725727 final worker = useOrSpawnInnerWorker ();
726728 CompatibilityCheck (
727- databaseName: check. databaseName,
729+ databaseName: databaseName,
728730 type: MessageType .dedicatedInSharedCompatibilityCheck,
729731 requestId: 0 ,
730732 ).sendToWorker (worker);
@@ -735,11 +737,23 @@ final class WorkerRunner {
735737
736738 supportsOpfs = result.canUseOpfs;
737739 opfsSupportsReadWriteUnsafe = result.opfsSupportsReadWriteUnsafe;
740+ existingDatabases.addAll (result.existingDatabases);
741+ }
742+ }
743+
744+ if (supportsOpfs) {
745+ for (final database in await opfsDatabases ()) {
746+ existingDatabases.add ((StorageMode .opfs, database));
747+ }
748+ }
749+ if (supportsIndexedDb && databaseName != null ) {
750+ if (await checkIndexedDbExists (databaseName)) {
751+ existingDatabases.add ((StorageMode .indexedDb, databaseName));
738752 }
739753 }
740754
741755 return CompatibilityResult (
742- existingDatabases: const [], // todo
756+ existingDatabases: existingDatabases. toList (),
743757 sharedCanSpawnDedicated: sharedCanSpawnDedicated,
744758 canUseOpfs: supportsOpfs,
745759 opfsSupportsReadWriteUnsafe: opfsSupportsReadWriteUnsafe,
@@ -878,44 +892,3 @@ Future<(bool, FileSystemSyncAccessHandle)> _tryOpeningWithReadWriteUnsafe(
878892 return (false , sync );
879893 }
880894}
881-
882- /// Collects all drift OPFS databases.
883- Future <List <String >> opfsDatabases () async {
884- final storage = storageManager;
885- if (storage == null ) return const [];
886-
887- var directory = await storage.directory;
888- try {
889- directory = await directory.getDirectory ('drift_db' );
890- } on Object {
891- // The drift_db folder doesn't exist, so there aren't any databases.
892- return const [];
893- }
894-
895- return [
896- await for (final entry in directory.list ())
897- if (entry.isDirectory) entry.name,
898- ];
899- }
900-
901- /// Constructs the path used by drift to store a database in the origin-private
902- /// section of the agent's file system.
903- String pathForOpfs (String databaseName) {
904- return 'drift_db/$databaseName ' ;
905- }
906-
907- /// Deletes the OPFS folder storing a database with the given [databaseName] if
908- /// such folder exists.
909- Future <void > deleteDatabaseInOpfs (String databaseName) async {
910- final storage = storageManager;
911- if (storage == null ) return ;
912-
913- var directory = await storage.directory;
914- try {
915- directory = await directory.getDirectory ('drift_db' );
916- await directory.remove (databaseName, recursive: true );
917- } on Object {
918- // fine, an error probably means that the database didn't exist in the first
919- // place.
920- }
921- }
0 commit comments