mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Improve cross platform support
This commit is contained in:
parent
f99b79b6b7
commit
d6d866774c
3 changed files with 19 additions and 7 deletions
|
@ -188,10 +188,12 @@ void _initVisibilityDetector() {
|
|||
|
||||
Future<NpDb> _createDb(InitIsolateType isolateType) async {
|
||||
final npDb = NpDb();
|
||||
final androidSdk =
|
||||
getRawPlatform() == NpPlatform.android ? AndroidInfo().sdkInt : null;
|
||||
if (isolateType == InitIsolateType.main) {
|
||||
await npDb.initMainIsolate(androidSdk: AndroidInfo().sdkInt);
|
||||
await npDb.initMainIsolate(androidSdk: androidSdk);
|
||||
} else {
|
||||
await npDb.initBackgroundIsolate(androidSdk: AndroidInfo().sdkInt);
|
||||
await npDb.initBackgroundIsolate(androidSdk: androidSdk);
|
||||
}
|
||||
return npDb;
|
||||
}
|
||||
|
|
|
@ -100,12 +100,22 @@ class DbLocationGroupResult {
|
|||
abstract class NpDb {
|
||||
factory NpDb() => NpDbSqlite();
|
||||
|
||||
/// Initialize the db for the main isolate
|
||||
///
|
||||
/// If running on android, you must pass the current SDK int to [androidSdk].
|
||||
/// If running on other platforms, this value will be ignored, you can pass
|
||||
/// null in such case
|
||||
Future<void> initMainIsolate({
|
||||
required int androidSdk,
|
||||
required int? androidSdk,
|
||||
});
|
||||
|
||||
/// Initialize the db for a background isolate
|
||||
///
|
||||
/// If running on android, you must pass the current SDK int to [androidSdk].
|
||||
/// If running on other platforms, this value will be ignored, you can pass
|
||||
/// null in such case
|
||||
Future<void> initBackgroundIsolate({
|
||||
required int androidSdk,
|
||||
required int? androidSdk,
|
||||
});
|
||||
|
||||
/// Dispose the db
|
||||
|
|
|
@ -26,10 +26,10 @@ class NpDbSqlite implements NpDb {
|
|||
|
||||
@override
|
||||
Future<void> initMainIsolate({
|
||||
required int androidSdk,
|
||||
required int? androidSdk,
|
||||
}) async {
|
||||
initDrift();
|
||||
if (getRawPlatform() == NpPlatform.android && androidSdk < 24) {
|
||||
if (getRawPlatform() == NpPlatform.android && androidSdk! < 24) {
|
||||
_log.info("[initMainIsolate] Workaround Android 6- bug");
|
||||
// see: https://github.com/flutter/flutter/issues/73318 and
|
||||
// https://github.com/simolus3/drift/issues/895
|
||||
|
@ -47,7 +47,7 @@ class NpDbSqlite implements NpDb {
|
|||
|
||||
@override
|
||||
Future<void> initBackgroundIsolate({
|
||||
required int androidSdk,
|
||||
required int? androidSdk,
|
||||
}) async {
|
||||
initDrift();
|
||||
// service already runs in an isolate
|
||||
|
|
Loading…
Reference in a new issue