@@ -255,16 +255,10 @@ final class DatabaseClient implements WebSqlite {
255
255
256
256
Future <void > _startDedicated () async {
257
257
if (globalContext.has ('Worker' )) {
258
- final Worker dedicated;
259
- try {
260
- dedicated = Worker (
261
- workerUri.toString ().toJS,
262
- WorkerOptions (name: 'sqlite3_worker' ),
263
- );
264
- } on Object {
265
- _missingFeatures.add (MissingBrowserFeature .dedicatedWorkers);
266
- return ;
267
- }
258
+ final dedicated = Worker (
259
+ workerUri.toString ().toJS,
260
+ WorkerOptions (name: 'sqlite3_worker' ),
261
+ );
268
262
269
263
final (endpoint, channel) = await createChannel ();
270
264
ConnectRequest (endpoint: endpoint, requestId: 0 ).sendToWorker (dedicated);
@@ -278,14 +272,8 @@ final class DatabaseClient implements WebSqlite {
278
272
279
273
Future <void > _startShared () async {
280
274
if (globalContext.has ('SharedWorker' )) {
281
- final SharedWorker shared;
282
- try {
283
- shared = SharedWorker (workerUri.toString ().toJS);
284
- shared.port.start ();
285
- } on Object {
286
- _missingFeatures.add (MissingBrowserFeature .sharedWorkers);
287
- return ;
288
- }
275
+ final shared = SharedWorker (workerUri.toString ().toJS);
276
+ shared.port.start ();
289
277
290
278
final (endpoint, channel) = await createChannel ();
291
279
ConnectRequest (endpoint: endpoint, requestId: 0 ).sendToPort (shared.port);
@@ -348,15 +336,22 @@ final class DatabaseClient implements WebSqlite {
348
336
final available = < (StorageMode , AccessMode )> [];
349
337
var workersReportedIndexedDbSupport = false ;
350
338
351
- if (_connectionToDedicated case final connection? ) {
352
- final response = await connection.sendRequest (
353
- CompatibilityCheck (
354
- requestId: 0 ,
355
- type: MessageType .dedicatedCompatibilityCheck,
356
- databaseName: databaseName,
357
- ),
358
- MessageType .simpleSuccessResponse,
359
- );
339
+ Future <void > dedicatedCompatibilityCheck (
340
+ WorkerConnection connection) async {
341
+ SimpleSuccessResponse response;
342
+ try {
343
+ response = await connection.sendRequest (
344
+ CompatibilityCheck (
345
+ requestId: 0 ,
346
+ type: MessageType .dedicatedCompatibilityCheck,
347
+ databaseName: databaseName,
348
+ ),
349
+ MessageType .simpleSuccessResponse,
350
+ );
351
+ } on Object {
352
+ return ;
353
+ }
354
+
360
355
final result = CompatibilityResult .fromJS (response.response as JSObject );
361
356
existing.addAll (result.existingDatabases);
362
357
available.add ((StorageMode .inMemory, AccessMode .throughDedicatedWorker));
@@ -390,15 +385,21 @@ final class DatabaseClient implements WebSqlite {
390
385
}
391
386
}
392
387
393
- if (_connectionToShared case final connection? ) {
394
- final response = await connection.sendRequest (
395
- CompatibilityCheck (
396
- requestId: 0 ,
397
- type: MessageType .sharedCompatibilityCheck,
398
- databaseName: databaseName,
399
- ),
400
- MessageType .simpleSuccessResponse,
401
- );
388
+ Future <void > sharedCompatibilityCheck (WorkerConnection connection) async {
389
+ SimpleSuccessResponse response;
390
+ try {
391
+ response = await connection.sendRequest (
392
+ CompatibilityCheck (
393
+ requestId: 0 ,
394
+ type: MessageType .sharedCompatibilityCheck,
395
+ databaseName: databaseName,
396
+ ),
397
+ MessageType .simpleSuccessResponse,
398
+ );
399
+ } on Object {
400
+ return ;
401
+ }
402
+
402
403
final result = CompatibilityResult .fromJS (response.response as JSObject );
403
404
404
405
if (result.canUseIndexedDb) {
@@ -423,6 +424,13 @@ final class DatabaseClient implements WebSqlite {
423
424
}
424
425
}
425
426
427
+ if (_connectionToDedicated case final dedicated? ) {
428
+ await dedicatedCompatibilityCheck (dedicated);
429
+ }
430
+ if (_connectionToShared case final shared? ) {
431
+ await sharedCompatibilityCheck (shared);
432
+ }
433
+
426
434
available.add ((StorageMode .inMemory, AccessMode .inCurrentContext));
427
435
if (workersReportedIndexedDbSupport || await checkIndexedDbSupport ()) {
428
436
// If the workers can use IndexedDb, so can we.
0 commit comments