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_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<AppImplementation> 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,

8
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));

11
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();

11
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<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: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 {

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/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<LoginCheckAccountPage> {
super.initState();
bloc = LoginCheckAccountBloc(
Provider.of<PackageInfo>(context, listen: false),
widget.serverURL,
widget.loginName,
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/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<LoginCheckServerStatusPage>
void initState() {
super.initState();
bloc = LoginCheckServerStatusBloc(Provider.of<PackageInfo>(context, listen: false), widget.serverURL);
bloc = LoginCheckServerStatusBloc(widget.serverURL);
}
@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/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<LoginFlowPage> {
void initState() {
super.initState();
bloc = LoginFlowBloc(Provider.of<PackageInfo>(context, listen: false), widget.serverURL);
bloc = LoginFlowBloc(widget.serverURL);
bloc.init.listen((final result) async {
if (result.hasData) {

Loading…
Cancel
Save