mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +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 {
|
Future<NpDb> _createDb(InitIsolateType isolateType) async {
|
||||||
final npDb = NpDb();
|
final npDb = NpDb();
|
||||||
|
final androidSdk =
|
||||||
|
getRawPlatform() == NpPlatform.android ? AndroidInfo().sdkInt : null;
|
||||||
if (isolateType == InitIsolateType.main) {
|
if (isolateType == InitIsolateType.main) {
|
||||||
await npDb.initMainIsolate(androidSdk: AndroidInfo().sdkInt);
|
await npDb.initMainIsolate(androidSdk: androidSdk);
|
||||||
} else {
|
} else {
|
||||||
await npDb.initBackgroundIsolate(androidSdk: AndroidInfo().sdkInt);
|
await npDb.initBackgroundIsolate(androidSdk: androidSdk);
|
||||||
}
|
}
|
||||||
return npDb;
|
return npDb;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,12 +100,22 @@ class DbLocationGroupResult {
|
||||||
abstract class NpDb {
|
abstract class NpDb {
|
||||||
factory NpDb() => NpDbSqlite();
|
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({
|
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({
|
Future<void> initBackgroundIsolate({
|
||||||
required int androidSdk,
|
required int? androidSdk,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Dispose the db
|
/// Dispose the db
|
||||||
|
|
|
@ -26,10 +26,10 @@ class NpDbSqlite implements NpDb {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> initMainIsolate({
|
Future<void> initMainIsolate({
|
||||||
required int androidSdk,
|
required int? androidSdk,
|
||||||
}) async {
|
}) async {
|
||||||
initDrift();
|
initDrift();
|
||||||
if (getRawPlatform() == NpPlatform.android && androidSdk < 24) {
|
if (getRawPlatform() == NpPlatform.android && androidSdk! < 24) {
|
||||||
_log.info("[initMainIsolate] Workaround Android 6- bug");
|
_log.info("[initMainIsolate] Workaround Android 6- bug");
|
||||||
// see: https://github.com/flutter/flutter/issues/73318 and
|
// see: https://github.com/flutter/flutter/issues/73318 and
|
||||||
// https://github.com/simolus3/drift/issues/895
|
// https://github.com/simolus3/drift/issues/895
|
||||||
|
@ -47,7 +47,7 @@ class NpDbSqlite implements NpDb {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> initBackgroundIsolate({
|
Future<void> initBackgroundIsolate({
|
||||||
required int androidSdk,
|
required int? androidSdk,
|
||||||
}) async {
|
}) async {
|
||||||
initDrift();
|
initDrift();
|
||||||
// service already runs in an isolate
|
// service already runs in an isolate
|
||||||
|
|
Loading…
Reference in a new issue