mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Fix reopening db on web
This commit is contained in:
parent
75eb8e860e
commit
5074498444
1 changed files with 13 additions and 5 deletions
|
@ -3,10 +3,13 @@ import 'dart:isolate';
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:drift/isolate.dart';
|
import 'package:drift/isolate.dart';
|
||||||
import 'package:flutter/foundation.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/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/entity/sqlite_table.dart';
|
||||||
import 'package:nc_photos/mobile/platform.dart'
|
import 'package:nc_photos/mobile/platform.dart'
|
||||||
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
|
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
|
||||||
|
import 'package:nc_photos/platform/k.dart' as platform_k;
|
||||||
|
|
||||||
typedef ComputeWithDbCallback<T, U> = Future<U> Function(
|
typedef ComputeWithDbCallback<T, U> = Future<U> Function(
|
||||||
SqliteDb db, T message);
|
SqliteDb db, T message);
|
||||||
|
@ -23,12 +26,17 @@ Future<SqliteDb> createDb() async {
|
||||||
|
|
||||||
Future<U> computeWithDb<T, U>(
|
Future<U> computeWithDb<T, U>(
|
||||||
ComputeWithDbCallback<T, U> callback, T args) async {
|
ComputeWithDbCallback<T, U> callback, T args) async {
|
||||||
|
if (platform_k.isWeb) {
|
||||||
|
final c = KiwiContainer().resolve<DiContainer>();
|
||||||
|
return await callback(c.sqliteDb, args);
|
||||||
|
} else {
|
||||||
return await compute(
|
return await compute(
|
||||||
_computeWithDbImpl<T, U>,
|
_computeWithDbImpl<T, U>,
|
||||||
_ComputeWithDbMessage(
|
_ComputeWithDbMessage(
|
||||||
await platform.getSqliteConnectionArgs(), callback, args),
|
await platform.getSqliteConnectionArgs(), callback, args),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class _IsolateStartRequest {
|
class _IsolateStartRequest {
|
||||||
const _IsolateStartRequest(this.sendDriftIsolate, this.platformArgs);
|
const _IsolateStartRequest(this.sendDriftIsolate, this.platformArgs);
|
||||||
|
|
Loading…
Reference in a new issue