From 507449844425bac3183c1c5931061c21806b5297 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 13 Aug 2022 03:09:08 +0800 Subject: [PATCH] Fix reopening db on web --- app/lib/entity/sqlite_table_isolate.dart | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/lib/entity/sqlite_table_isolate.dart b/app/lib/entity/sqlite_table_isolate.dart index 21b32254..eb828811 100644 --- a/app/lib/entity/sqlite_table_isolate.dart +++ b/app/lib/entity/sqlite_table_isolate.dart @@ -3,10 +3,13 @@ import 'dart:isolate'; import 'package:drift/drift.dart'; import 'package:drift/isolate.dart'; import 'package:flutter/foundation.dart'; +import 'package:kiwi/kiwi.dart'; import 'package:nc_photos/app_init.dart' as app_init; +import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/sqlite_table.dart'; import 'package:nc_photos/mobile/platform.dart' if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform; +import 'package:nc_photos/platform/k.dart' as platform_k; typedef ComputeWithDbCallback = Future Function( SqliteDb db, T message); @@ -23,11 +26,16 @@ Future createDb() async { Future computeWithDb( ComputeWithDbCallback callback, T args) async { - return await compute( - _computeWithDbImpl, - _ComputeWithDbMessage( - await platform.getSqliteConnectionArgs(), callback, args), - ); + if (platform_k.isWeb) { + final c = KiwiContainer().resolve(); + return await callback(c.sqliteDb, args); + } else { + return await compute( + _computeWithDbImpl, + _ComputeWithDbMessage( + await platform.getSqliteConnectionArgs(), callback, args), + ); + } } class _IsolateStartRequest {