diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 5b32f7a9..4177a1a6 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -2,6 +2,7 @@ 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'; @@ -17,6 +18,9 @@ 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, @@ -39,6 +43,11 @@ 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'; 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 b5f10bf5..94e1bef6 100644 --- a/packages/neon/neon/lib/src/blocs/login_check_account.dart +++ b/packages/neon/neon/lib/src/blocs/login_check_account.dart @@ -1,11 +1,11 @@ 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:nextcloud/nextcloud.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:rxdart/rxdart.dart'; abstract interface class LoginCheckAccountBlocEvents {} @@ -18,7 +18,6 @@ abstract interface class LoginCheckAccountBlocStates { class LoginCheckAccountBloc extends InteractiveBloc implements LoginCheckAccountBlocEvents, LoginCheckAccountBlocStates { LoginCheckAccountBloc( - this._packageInfo, this.serverURL, this.loginName, this.password, @@ -26,7 +25,6 @@ class LoginCheckAccountBloc extends InteractiveBloc unawaited(refresh()); } - final PackageInfo _packageInfo; final String serverURL; final String loginName; final String password; @@ -48,7 +46,7 @@ class LoginCheckAccountBloc extends InteractiveBloc serverURL, loginName: loginName, password: password, - userAgentOverride: userAgent(_packageInfo), + userAgentOverride: neonUserAgent, ); final response = await client.provisioningApi.getCurrentUser(); @@ -58,7 +56,7 @@ class LoginCheckAccountBloc extends InteractiveBloc loginName: loginName, username: response.ocs.data.id, password: password, - userAgent: userAgent(_packageInfo), + userAgent: neonUserAgent, ); state.add(Result.success(account)); 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 2996ddb7..b29a7b78 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,11 +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:nextcloud/nextcloud.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:rxdart/rxdart.dart'; abstract interface class LoginCheckServerStatusBlocEvents {} @@ -17,14 +16,10 @@ abstract interface class LoginCheckServerStatusBlocStates { class LoginCheckServerStatusBloc extends InteractiveBloc implements LoginCheckServerStatusBlocEvents, LoginCheckServerStatusBlocStates { - LoginCheckServerStatusBloc( - this._packageInfo, - this.serverURL, - ) { + LoginCheckServerStatusBloc(this.serverURL) { unawaited(refresh()); } - final PackageInfo _packageInfo; final String serverURL; @override @@ -42,7 +37,7 @@ class LoginCheckServerStatusBloc extends InteractiveBloc try { final client = NextcloudClient( serverURL, - userAgentOverride: userAgent(_packageInfo), + userAgentOverride: neonUserAgent, ); final status = await client.core.getStatus(); diff --git a/packages/neon/neon/lib/src/blocs/login_flow.dart b/packages/neon/neon/lib/src/blocs/login_flow.dart index 4ac3ca76..185a0053 100644 --- a/packages/neon/neon/lib/src/blocs/login_flow.dart +++ b/packages/neon/neon/lib/src/blocs/login_flow.dart @@ -1,11 +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:nextcloud/nextcloud.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:rxdart/rxdart.dart'; abstract class LoginFlowBlocEvents {} @@ -17,18 +16,14 @@ abstract class LoginFlowBlocStates { } class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, LoginFlowBlocStates { - LoginFlowBloc( - this._packageInfo, - this.serverURL, - ) { + LoginFlowBloc(this.serverURL) { unawaited(refresh()); } - final PackageInfo _packageInfo; final String serverURL; late final _client = NextcloudClient( serverURL, - userAgentOverride: userAgent(_packageInfo), + userAgentOverride: neonUserAgent, ); final _resultController = StreamController(); diff --git a/packages/neon/neon/lib/src/models/account.dart b/packages/neon/neon/lib/src/models/account.dart index 5e336f72..5dbaca84 100644 --- a/packages/neon/neon/lib/src/models/account.dart +++ b/packages/neon/neon/lib/src/models/account.dart @@ -5,18 +5,9 @@ import 'package:crypto/crypto.dart'; import 'package:flutter/foundation.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:nextcloud/nextcloud.dart'; -import 'package:package_info_plus/package_info_plus.dart'; part 'account.g.dart'; -String userAgent(final PackageInfo packageInfo) { - var buildNumber = packageInfo.buildNumber; - if (buildNumber.isEmpty) { - buildNumber = '1'; - } - return 'Neon ${packageInfo.version}+$buildNumber'; -} - @JsonSerializable() @immutable class Account { diff --git a/packages/neon/neon/lib/src/pages/login_check_account.dart b/packages/neon/neon/lib/src/pages/login_check_account.dart index c425ef30..37d1d9aa 100644 --- a/packages/neon/neon/lib/src/pages/login_check_account.dart +++ b/packages/neon/neon/lib/src/pages/login_check_account.dart @@ -11,7 +11,6 @@ import 'package:neon/src/widgets/account_tile.dart'; import 'package:neon/src/widgets/exception.dart'; import 'package:neon/src/widgets/linear_progress_indicator.dart'; import 'package:neon/src/widgets/validation_tile.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:provider/provider.dart'; class LoginCheckAccountPage extends StatefulWidget { @@ -38,7 +37,6 @@ class _LoginCheckAccountPageState extends State { super.initState(); bloc = LoginCheckAccountBloc( - Provider.of(context, listen: false), widget.serverURL, widget.loginName, widget.password, diff --git a/packages/neon/neon/lib/src/pages/login_check_server_status.dart b/packages/neon/neon/lib/src/pages/login_check_server_status.dart index 205fd377..622b67f7 100644 --- a/packages/neon/neon/lib/src/pages/login_check_server_status.dart +++ b/packages/neon/neon/lib/src/pages/login_check_server_status.dart @@ -8,8 +8,6 @@ import 'package:neon/src/widgets/exception.dart'; import 'package:neon/src/widgets/linear_progress_indicator.dart'; import 'package:neon/src/widgets/validation_tile.dart'; import 'package:nextcloud/nextcloud.dart'; -import 'package:package_info_plus/package_info_plus.dart'; -import 'package:provider/provider.dart'; class LoginCheckServerStatusPage extends StatefulWidget { const LoginCheckServerStatusPage({ @@ -30,7 +28,7 @@ class _LoginCheckServerStatusPageState extends State void initState() { super.initState(); - bloc = LoginCheckServerStatusBloc(Provider.of(context, listen: false), widget.serverURL); + bloc = LoginCheckServerStatusBloc(widget.serverURL); } @override diff --git a/packages/neon/neon/lib/src/pages/login_flow.dart b/packages/neon/neon/lib/src/pages/login_flow.dart index 585cf7dc..c1cc8b52 100644 --- a/packages/neon/neon/lib/src/pages/login_flow.dart +++ b/packages/neon/neon/lib/src/pages/login_flow.dart @@ -5,8 +5,6 @@ import 'package:neon/src/blocs/login_flow.dart'; import 'package:neon/src/router.dart'; import 'package:neon/src/widgets/exception.dart'; import 'package:neon/src/widgets/linear_progress_indicator.dart'; -import 'package:package_info_plus/package_info_plus.dart'; -import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher_string.dart'; class LoginFlowPage extends StatefulWidget { @@ -28,7 +26,7 @@ class _LoginFlowPageState extends State { void initState() { super.initState(); - bloc = LoginFlowBloc(Provider.of(context, listen: false), widget.serverURL); + bloc = LoginFlowBloc(widget.serverURL); bloc.init.listen((final result) async { if (result.hasData) {