Browse Source

neon: Cache user agent

pull/452/head
jld3103 1 year ago
parent
commit
2e91007767
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 9
      packages/neon/neon/lib/neon.dart
  2. 8
      packages/neon/neon/lib/src/blocs/login_check_account.dart
  3. 11
      packages/neon/neon/lib/src/blocs/login_check_server_status.dart
  4. 11
      packages/neon/neon/lib/src/blocs/login_flow.dart
  5. 9
      packages/neon/neon/lib/src/models/account.dart
  6. 2
      packages/neon/neon/lib/src/pages/login_check_account.dart
  7. 4
      packages/neon/neon/lib/src/pages/login_check_server_status.dart
  8. 4
      packages/neon/neon/lib/src/pages/login_flow.dart

9
packages/neon/neon/lib/neon.dart

@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.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/app.dart';
import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/blocs/first_launch.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:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@internal
late final String neonUserAgent;
Future runNeon({ Future runNeon({
required final Iterable<AppImplementation> Function(SharedPreferences, RequestManager, NeonPlatform) required final Iterable<AppImplementation> Function(SharedPreferences, RequestManager, NeonPlatform)
getAppImplementations, getAppImplementations,
@ -39,6 +43,11 @@ Future runNeon({
final allAppImplementations = getAppImplementations(sharedPreferences, requestManager, platform); final allAppImplementations = getAppImplementations(sharedPreferences, requestManager, platform);
final packageInfo = await PackageInfo.fromPlatform(); final packageInfo = await PackageInfo.fromPlatform();
var buildNumber = packageInfo.buildNumber;
if (buildNumber.isEmpty) {
buildNumber = '1';
}
neonUserAgent = 'Neon ${packageInfo.version}+$buildNumber';
final globalOptions = GlobalOptions( final globalOptions = GlobalOptions(
sharedPreferences, sharedPreferences,

8
packages/neon/neon/lib/src/blocs/login_check_account.dart

@ -1,11 +1,11 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:neon/neon.dart';
import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/bloc/result.dart'; import 'package:neon/src/bloc/result.dart';
import 'package:neon/src/models/account.dart'; import 'package:neon/src/models/account.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
abstract interface class LoginCheckAccountBlocEvents {} abstract interface class LoginCheckAccountBlocEvents {}
@ -18,7 +18,6 @@ abstract interface class LoginCheckAccountBlocStates {
class LoginCheckAccountBloc extends InteractiveBloc class LoginCheckAccountBloc extends InteractiveBloc
implements LoginCheckAccountBlocEvents, LoginCheckAccountBlocStates { implements LoginCheckAccountBlocEvents, LoginCheckAccountBlocStates {
LoginCheckAccountBloc( LoginCheckAccountBloc(
this._packageInfo,
this.serverURL, this.serverURL,
this.loginName, this.loginName,
this.password, this.password,
@ -26,7 +25,6 @@ class LoginCheckAccountBloc extends InteractiveBloc
unawaited(refresh()); unawaited(refresh());
} }
final PackageInfo _packageInfo;
final String serverURL; final String serverURL;
final String loginName; final String loginName;
final String password; final String password;
@ -48,7 +46,7 @@ class LoginCheckAccountBloc extends InteractiveBloc
serverURL, serverURL,
loginName: loginName, loginName: loginName,
password: password, password: password,
userAgentOverride: userAgent(_packageInfo), userAgentOverride: neonUserAgent,
); );
final response = await client.provisioningApi.getCurrentUser(); final response = await client.provisioningApi.getCurrentUser();
@ -58,7 +56,7 @@ class LoginCheckAccountBloc extends InteractiveBloc
loginName: loginName, loginName: loginName,
username: response.ocs.data.id, username: response.ocs.data.id,
password: password, password: password,
userAgent: userAgent(_packageInfo), userAgent: neonUserAgent,
); );
state.add(Result.success(account)); state.add(Result.success(account));

11
packages/neon/neon/lib/src/blocs/login_check_server_status.dart

@ -1,11 +1,10 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:neon/neon.dart';
import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/bloc/result.dart'; import 'package:neon/src/bloc/result.dart';
import 'package:neon/src/models/account.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
abstract interface class LoginCheckServerStatusBlocEvents {} abstract interface class LoginCheckServerStatusBlocEvents {}
@ -17,14 +16,10 @@ abstract interface class LoginCheckServerStatusBlocStates {
class LoginCheckServerStatusBloc extends InteractiveBloc class LoginCheckServerStatusBloc extends InteractiveBloc
implements LoginCheckServerStatusBlocEvents, LoginCheckServerStatusBlocStates { implements LoginCheckServerStatusBlocEvents, LoginCheckServerStatusBlocStates {
LoginCheckServerStatusBloc( LoginCheckServerStatusBloc(this.serverURL) {
this._packageInfo,
this.serverURL,
) {
unawaited(refresh()); unawaited(refresh());
} }
final PackageInfo _packageInfo;
final String serverURL; final String serverURL;
@override @override
@ -42,7 +37,7 @@ class LoginCheckServerStatusBloc extends InteractiveBloc
try { try {
final client = NextcloudClient( final client = NextcloudClient(
serverURL, serverURL,
userAgentOverride: userAgent(_packageInfo), userAgentOverride: neonUserAgent,
); );
final status = await client.core.getStatus(); final status = await client.core.getStatus();

11
packages/neon/neon/lib/src/blocs/login_flow.dart

@ -1,11 +1,10 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:neon/neon.dart';
import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/bloc/result.dart'; import 'package:neon/src/bloc/result.dart';
import 'package:neon/src/models/account.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
abstract class LoginFlowBlocEvents {} abstract class LoginFlowBlocEvents {}
@ -17,18 +16,14 @@ abstract class LoginFlowBlocStates {
} }
class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, LoginFlowBlocStates { class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, LoginFlowBlocStates {
LoginFlowBloc( LoginFlowBloc(this.serverURL) {
this._packageInfo,
this.serverURL,
) {
unawaited(refresh()); unawaited(refresh());
} }
final PackageInfo _packageInfo;
final String serverURL; final String serverURL;
late final _client = NextcloudClient( late final _client = NextcloudClient(
serverURL, serverURL,
userAgentOverride: userAgent(_packageInfo), userAgentOverride: neonUserAgent,
); );
final _resultController = StreamController<CoreLoginFlowResult>(); final _resultController = StreamController<CoreLoginFlowResult>();

9
packages/neon/neon/lib/src/models/account.dart

@ -5,18 +5,9 @@ import 'package:crypto/crypto.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:package_info_plus/package_info_plus.dart';
part 'account.g.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() @JsonSerializable()
@immutable @immutable
class Account { class Account {

2
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/exception.dart';
import 'package:neon/src/widgets/linear_progress_indicator.dart'; import 'package:neon/src/widgets/linear_progress_indicator.dart';
import 'package:neon/src/widgets/validation_tile.dart'; import 'package:neon/src/widgets/validation_tile.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class LoginCheckAccountPage extends StatefulWidget { class LoginCheckAccountPage extends StatefulWidget {
@ -38,7 +37,6 @@ class _LoginCheckAccountPageState extends State<LoginCheckAccountPage> {
super.initState(); super.initState();
bloc = LoginCheckAccountBloc( bloc = LoginCheckAccountBloc(
Provider.of<PackageInfo>(context, listen: false),
widget.serverURL, widget.serverURL,
widget.loginName, widget.loginName,
widget.password, widget.password,

4
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/linear_progress_indicator.dart';
import 'package:neon/src/widgets/validation_tile.dart'; import 'package:neon/src/widgets/validation_tile.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
class LoginCheckServerStatusPage extends StatefulWidget { class LoginCheckServerStatusPage extends StatefulWidget {
const LoginCheckServerStatusPage({ const LoginCheckServerStatusPage({
@ -30,7 +28,7 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
void initState() { void initState() {
super.initState(); super.initState();
bloc = LoginCheckServerStatusBloc(Provider.of<PackageInfo>(context, listen: false), widget.serverURL); bloc = LoginCheckServerStatusBloc(widget.serverURL);
} }
@override @override

4
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/router.dart';
import 'package:neon/src/widgets/exception.dart'; import 'package:neon/src/widgets/exception.dart';
import 'package:neon/src/widgets/linear_progress_indicator.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'; import 'package:url_launcher/url_launcher_string.dart';
class LoginFlowPage extends StatefulWidget { class LoginFlowPage extends StatefulWidget {
@ -28,7 +26,7 @@ class _LoginFlowPageState extends State<LoginFlowPage> {
void initState() { void initState() {
super.initState(); super.initState();
bloc = LoginFlowBloc(Provider.of<PackageInfo>(context, listen: false), widget.serverURL); bloc = LoginFlowBloc(widget.serverURL);
bloc.init.listen((final result) async { bloc.init.listen((final result) async {
if (result.hasData) { if (result.hasData) {

Loading…
Cancel
Save