1
1
import 'dart:convert' ;
2
2
import 'dart:io' ;
3
3
4
+ import 'package:device_info_plus/device_info_plus.dart' ;
4
5
import 'package:http/http.dart' as http;
6
+ import 'package:package_info_plus/package_info_plus.dart' ;
5
7
6
8
import '../log.dart' ;
7
9
import '../model/localizations.dart' ;
@@ -69,6 +71,28 @@ class ApiConnection {
69
71
}
70
72
}
71
73
74
+ Future <void > addUserAgent (http.BaseRequest request) async {
75
+ final packageInfo = await PackageInfo .fromPlatform ();
76
+ final deviceInfoPlugin = DeviceInfoPlugin ();
77
+
78
+ final String applicationVersion = packageInfo.version;
79
+ final String systemName;
80
+ final String systemVersion;
81
+ if (Platform .isIOS) {
82
+ final deviceInfo = await deviceInfoPlugin.iosInfo;
83
+ systemName = deviceInfo.systemName;
84
+ systemVersion = deviceInfo.systemVersion;
85
+ } else if (Platform .isAndroid) {
86
+ final deviceInfo = await deviceInfoPlugin.androidInfo;
87
+ systemName = "Android" ;
88
+ systemVersion = deviceInfo.version.release;
89
+ } else {
90
+ systemName = "Desktop" ;
91
+ systemVersion = "?" ;
92
+ }
93
+ request.headers['User-Agent' ] = 'ZulipMobile/$applicationVersion ($systemName $systemVersion )' ;
94
+ }
95
+
72
96
final http.Client _client;
73
97
74
98
bool _isOpen = true ;
@@ -80,6 +104,7 @@ class ApiConnection {
80
104
assert (debugLog ("${request .method } ${request .url }" ));
81
105
82
106
addAuth (request);
107
+ await addUserAgent (request);
83
108
84
109
final http.StreamedResponse response;
85
110
try {
0 commit comments