mirror of
https://github.com/immich-app/immich.git
synced 2026-10-20 06:19:19 +02:00
* chore(mobile): static Store to unify and streamline reactivity * Add tests of caching and new stores * Don't instantiate PeopleDbRepository * Slight DB rename and fix throwing store methods * chore(mobile): shared DataController for management of data sources * chore(mobile): shared DataController for management of data sources * Fix lint with removed dependency * Re-order Store bootstrap * Remove extra import
62 lines
2.0 KiB
Dart
62 lines
2.0 KiB
Dart
import 'dart:async';
|
|
import 'dart:ui';
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/data/store.dart';
|
|
import 'package:immich_mobile/domain/services/log.service.dart';
|
|
// ignore: library_prefixes
|
|
import 'package:immich_mobile/entities/store.entity.dart' as dbStore;
|
|
import 'package:immich_mobile/providers/infrastructure/cancel.provider.dart';
|
|
import 'package:immich_mobile/utils/bootstrap.dart';
|
|
import 'package:immich_mobile/wm_executor.dart';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:worker_manager/worker_manager.dart' show Cancelable;
|
|
|
|
class InvalidIsolateUsageException implements Exception {
|
|
const InvalidIsolateUsageException();
|
|
|
|
@override
|
|
String toString() => "IsolateHelper should only be used from the root isolate";
|
|
}
|
|
|
|
// !! Should be used only from the root isolate
|
|
Cancelable<T?> runInIsolateGentle<T>({
|
|
required Future<T> Function(ProviderContainer ref) computation,
|
|
String? debugLabel,
|
|
}) {
|
|
final token = RootIsolateToken.instance;
|
|
if (token == null) {
|
|
throw const InvalidIsolateUsageException();
|
|
}
|
|
|
|
return workerManagerPatch.executeGentle((onCancel) async {
|
|
BackgroundIsolateBinaryMessenger.ensureInitialized(token);
|
|
DartPluginRegistrant.ensureInitialized();
|
|
|
|
final log = Logger("IsolateLogger");
|
|
final (dataController, apiService) = await Bootstrap.initDomain(
|
|
shouldBufferLogs: false,
|
|
disableStoreWatching: true,
|
|
);
|
|
final ref = ProviderContainer(
|
|
overrides: [
|
|
cancellationProvider.overrideWithValue(onCancel),
|
|
...Store.overrideWith(dataController: dataController, apiService: apiService),
|
|
],
|
|
);
|
|
|
|
try {
|
|
return await computation(ref);
|
|
} catch (error, stack) {
|
|
log.severe("Error in runInIsolateGentle${debugLabel == null ? '' : ' for $debugLabel'}", error, stack);
|
|
return null;
|
|
} finally {
|
|
ref.dispose();
|
|
await dbStore.Store.dispose();
|
|
await LogService.I.dispose();
|
|
await dataController.close();
|
|
}
|
|
});
|
|
}
|