Showing
3 changed files
with
15 additions
and
10 deletions
| @@ -16,6 +16,7 @@ class AutoTrackConfigManager { | @@ -16,6 +16,7 @@ class AutoTrackConfigManager { | ||
| 16 | DeviceInfoPlugin().deviceInfo.then((value) { | 16 | DeviceInfoPlugin().deviceInfo.then((value) { |
| 17 | _deviceInfo = value.data; | 17 | _deviceInfo = value.data; |
| 18 | _baseDeviceInfo = value; | 18 | _baseDeviceInfo = value; |
| 19 | + _updateDeviceId(); | ||
| 19 | }); | 20 | }); |
| 20 | } | 21 | } |
| 21 | 22 | ||
| @@ -23,8 +24,8 @@ class AutoTrackConfigManager { | @@ -23,8 +24,8 @@ class AutoTrackConfigManager { | ||
| 23 | String get appVersion => _appVersion; | 24 | String get appVersion => _appVersion; |
| 24 | 25 | ||
| 25 | BaseDeviceInfo? _baseDeviceInfo; | 26 | BaseDeviceInfo? _baseDeviceInfo; |
| 26 | - String _deviceId = ''; | ||
| 27 | - String get deviceId => _deviceId; | 27 | + String? _deviceId; |
| 28 | + String? get deviceId => _deviceId; | ||
| 28 | 29 | ||
| 29 | Map<String, dynamic> _deviceInfo = {}; | 30 | Map<String, dynamic> _deviceInfo = {}; |
| 30 | Map<String, dynamic> get deviceInfo => _deviceInfo; | 31 | Map<String, dynamic> get deviceInfo => _deviceInfo; |
| @@ -37,6 +38,15 @@ class AutoTrackConfigManager { | @@ -37,6 +38,15 @@ class AutoTrackConfigManager { | ||
| 37 | 38 | ||
| 38 | void updateConfig(AutoTrackConfig config) { | 39 | void updateConfig(AutoTrackConfig config) { |
| 39 | _config = config; | 40 | _config = config; |
| 41 | + _updateDeviceId(); | ||
| 42 | + if (config.enableUpload) { | ||
| 43 | + AutoTrackQueue.instance.start(); | ||
| 44 | + } else { | ||
| 45 | + AutoTrackQueue.instance.stop(); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + void _updateDeviceId() { | ||
| 40 | if (_baseDeviceInfo is IosDeviceInfo) { | 50 | if (_baseDeviceInfo is IosDeviceInfo) { |
| 41 | _deviceId = md5.convert(utf8.encode('${(_baseDeviceInfo as IosDeviceInfo).identifierForVendor}#${config.appKey}')).toString(); | 51 | _deviceId = md5.convert(utf8.encode('${(_baseDeviceInfo as IosDeviceInfo).identifierForVendor}#${config.appKey}')).toString(); |
| 42 | } else if (_baseDeviceInfo is AndroidDeviceInfo) { | 52 | } else if (_baseDeviceInfo is AndroidDeviceInfo) { |
| @@ -44,12 +54,7 @@ class AutoTrackConfigManager { | @@ -44,12 +54,7 @@ class AutoTrackConfigManager { | ||
| 44 | } else if (_baseDeviceInfo is MacOsDeviceInfo) { | 54 | } else if (_baseDeviceInfo is MacOsDeviceInfo) { |
| 45 | _deviceId = '${(_baseDeviceInfo as MacOsDeviceInfo).hostName}-${(_baseDeviceInfo as MacOsDeviceInfo).computerName}'; | 55 | _deviceId = '${(_baseDeviceInfo as MacOsDeviceInfo).hostName}-${(_baseDeviceInfo as MacOsDeviceInfo).computerName}'; |
| 46 | } else { | 56 | } else { |
| 47 | - _deviceId = ''; | ||
| 48 | - } | ||
| 49 | - if (config.enableUpload) { | ||
| 50 | - AutoTrackQueue.instance.start(); | ||
| 51 | - } else { | ||
| 52 | - AutoTrackQueue.instance.stop(); | 57 | + _deviceId = null; |
| 53 | } | 58 | } |
| 54 | } | 59 | } |
| 55 | 60 |
| @@ -40,7 +40,7 @@ class AutoTrackQueue { | @@ -40,7 +40,7 @@ class AutoTrackQueue { | ||
| 40 | final config = AutoTrackConfigManager.instance.config; | 40 | final config = AutoTrackConfigManager.instance.config; |
| 41 | final host = config.host; | 41 | final host = config.host; |
| 42 | if (host != null) { | 42 | if (host != null) { |
| 43 | - final t = DateTime.now().millisecond; | 43 | + final t = DateTime.now().millisecondsSinceEpoch; |
| 44 | dio.post(host, data: { | 44 | dio.post(host, data: { |
| 45 | 'app_key': config.appKey ?? '', | 45 | 'app_key': config.appKey ?? '', |
| 46 | 'signature': config.signature!(t), | 46 | 'signature': config.signature!(t), |
-
Please register or login to post a comment