From d802d7df0ced6f890b5c8768542a15c2156e5608 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 10 Aug 2023 15:24:30 +0200 Subject: [PATCH] refactor(neon): User agent handling Signed-off-by: jld3103 --- packages/neon/neon/lib/neon.dart | 11 ++--------- .../neon/lib/src/blocs/login_check_account.dart | 2 +- .../lib/src/blocs/login_check_server_status.dart | 2 +- packages/neon/neon/lib/src/blocs/login_flow.dart | 2 +- packages/neon/neon/lib/src/utils/user_agent.dart | 15 +++++++++++++++ 5 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 packages/neon/neon/lib/src/utils/user_agent.dart diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 7ce1372c..de2bc329 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_native_splash/flutter_native_splash.dart'; -import 'package:meta/meta.dart'; import 'package:neon/src/app.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/first_launch.dart'; @@ -14,13 +13,11 @@ import 'package:neon/src/platform/platform.dart'; import 'package:neon/src/theme/neon.dart'; import 'package:neon/src/utils/global_options.dart'; import 'package:neon/src/utils/request_manager.dart'; +import 'package:neon/src/utils/user_agent.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; -@internal -late final String neonUserAgent; - Future runNeon({ required final Iterable Function(SharedPreferences, RequestManager, NeonPlatform) getAppImplementations, @@ -43,11 +40,7 @@ Future runNeon({ final allAppImplementations = getAppImplementations(sharedPreferences, requestManager, platform); final packageInfo = await PackageInfo.fromPlatform(); - var buildNumber = packageInfo.buildNumber; - if (buildNumber.isEmpty) { - buildNumber = '1'; - } - neonUserAgent = 'Neon ${packageInfo.version}+$buildNumber'; + buildUserAgent(packageInfo); final globalOptions = GlobalOptions( sharedPreferences, diff --git a/packages/neon/neon/lib/src/blocs/login_check_account.dart b/packages/neon/neon/lib/src/blocs/login_check_account.dart index 5608dd0a..3fcc2be0 100644 --- a/packages/neon/neon/lib/src/blocs/login_check_account.dart +++ b/packages/neon/neon/lib/src/blocs/login_check_account.dart @@ -1,10 +1,10 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; -import 'package:neon/neon.dart'; import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/result.dart'; import 'package:neon/src/models/account.dart'; +import 'package:neon/src/utils/user_agent.dart'; import 'package:nextcloud/nextcloud.dart'; import 'package:rxdart/rxdart.dart'; diff --git a/packages/neon/neon/lib/src/blocs/login_check_server_status.dart b/packages/neon/neon/lib/src/blocs/login_check_server_status.dart index 5a4877e6..81acbd08 100644 --- a/packages/neon/neon/lib/src/blocs/login_check_server_status.dart +++ b/packages/neon/neon/lib/src/blocs/login_check_server_status.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; -import 'package:neon/neon.dart'; import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/result.dart'; +import 'package:neon/src/utils/user_agent.dart'; import 'package:nextcloud/nextcloud.dart'; import 'package:rxdart/rxdart.dart'; diff --git a/packages/neon/neon/lib/src/blocs/login_flow.dart b/packages/neon/neon/lib/src/blocs/login_flow.dart index 18426321..374478af 100644 --- a/packages/neon/neon/lib/src/blocs/login_flow.dart +++ b/packages/neon/neon/lib/src/blocs/login_flow.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; -import 'package:neon/neon.dart'; import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/result.dart'; +import 'package:neon/src/utils/user_agent.dart'; import 'package:nextcloud/nextcloud.dart'; import 'package:rxdart/rxdart.dart'; diff --git a/packages/neon/neon/lib/src/utils/user_agent.dart b/packages/neon/neon/lib/src/utils/user_agent.dart new file mode 100644 index 00000000..4612edcc --- /dev/null +++ b/packages/neon/neon/lib/src/utils/user_agent.dart @@ -0,0 +1,15 @@ +import 'package:meta/meta.dart'; +import 'package:package_info_plus/package_info_plus.dart'; + +late String? _userAgent; + +void buildUserAgent(final PackageInfo packageInfo) { + var buildNumber = packageInfo.buildNumber; + if (buildNumber.isEmpty) { + buildNumber = '1'; + } + _userAgent = 'Neon ${packageInfo.version}+$buildNumber'; +} + +@internal +String get neonUserAgent => _userAgent!;