mirror of
https://github.com/immich-app/immich.git
synced 2026-02-11 03:17:59 +03:00
fix hot reload
This commit is contained in:
@@ -7,11 +7,20 @@ import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class NetworkRepository {
|
||||
static late Directory _cachePath;
|
||||
static final _clients = <String, http.Client>{};
|
||||
|
||||
static Future<void> init() async {
|
||||
_cachePath = await getTemporaryDirectory();
|
||||
}
|
||||
|
||||
static void reset() {
|
||||
Future.microtask(init);
|
||||
for (final client in _clients.values) {
|
||||
client.close();
|
||||
}
|
||||
_clients.clear();
|
||||
}
|
||||
|
||||
const NetworkRepository();
|
||||
|
||||
http.Client getHttpClient({
|
||||
@@ -21,11 +30,16 @@ class NetworkRepository {
|
||||
required int maxConnections,
|
||||
required CacheMode cacheMode,
|
||||
}) {
|
||||
final cachedClient = _clients[directoryName];
|
||||
if (cachedClient != null) {
|
||||
return cachedClient;
|
||||
}
|
||||
|
||||
final directory = Directory('${_cachePath.path}/$directoryName');
|
||||
directory.createSync(recursive: true);
|
||||
if (Platform.isAndroid) {
|
||||
final engine = CronetEngine.build(cacheMode: cacheMode, cacheMaxSize: diskCapacity, storagePath: directory.path);
|
||||
return CronetClient.fromCronetEngine(engine, closeEngine: true);
|
||||
return _clients[directoryName] = CronetClient.fromCronetEngine(engine, closeEngine: true);
|
||||
}
|
||||
|
||||
final config = URLSessionConfiguration.defaultSessionConfiguration()
|
||||
@@ -35,6 +49,6 @@ class NetworkRepository {
|
||||
memoryCapacity: memoryCapacity,
|
||||
directory: directory.uri,
|
||||
);
|
||||
return CupertinoClient.fromSessionConfiguration(config);
|
||||
return _clients[directoryName] = CupertinoClient.fromSessionConfiguration(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +228,14 @@ class ImmichAppState extends ConsumerState<ImmichApp> with WidgetsBindingObserve
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void reassemble() {
|
||||
if (kDebugMode) {
|
||||
NetworkRepository.reset();
|
||||
}
|
||||
super.reassemble();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final router = ref.watch(appRouterProvider);
|
||||
|
||||
Reference in New Issue
Block a user