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