From 66a0e044894282debc8aeaa564861be3784d2386 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Mon, 1 Sep 2025 00:16:00 -0400 Subject: [PATCH] custom user agent --- .../repositories/network.repository.dart | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mobile/lib/infrastructure/repositories/network.repository.dart b/mobile/lib/infrastructure/repositories/network.repository.dart index 1639f1515d..26cce95456 100644 --- a/mobile/lib/infrastructure/repositories/network.repository.dart +++ b/mobile/lib/infrastructure/repositories/network.repository.dart @@ -3,14 +3,19 @@ import 'dart:io'; import 'package:cronet_http/cronet_http.dart'; import 'package:cupertino_http/cupertino_http.dart'; import 'package:http/http.dart' as http; +import 'package:immich_mobile/utils/user_agent.dart'; import 'package:path_provider/path_provider.dart'; class NetworkRepository { static late Directory _cachePath; + static late String _userAgent; static final _clients = {}; - static Future init() async { - _cachePath = await getTemporaryDirectory(); + static Future init() { + return ( + getTemporaryDirectory().then((cachePath) => _cachePath = cachePath), + getUserAgentString().then((userAgent) => _userAgent = userAgent), + ).wait; } static void reset() { @@ -38,7 +43,12 @@ class NetworkRepository { final directory = Directory('${_cachePath.path}/$directoryName'); directory.createSync(recursive: true); 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, + userAgent: _userAgent, + ); return _clients[directoryName] = CronetClient.fromCronetEngine(engine, closeEngine: true); } @@ -48,7 +58,8 @@ class NetworkRepository { diskCapacity: diskCapacity, memoryCapacity: memoryCapacity, directory: directory.uri, - ); + ) + ..httpAdditionalHeaders = {'User-Agent': _userAgent}; return _clients[directoryName] = CupertinoClient.fromSessionConfiguration(config); } }