Browse Source

harbour: Use proper user-agent

pull/25/head
jld3103 2 years ago
parent
commit
0a11e3ae51
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 2
      packages/harbour/lib/main.dart
  2. 3
      packages/harbour/lib/src/blocs/login.dart
  3. 1
      packages/harbour/lib/src/harbour.dart
  4. 7
      packages/harbour/lib/src/models/account.dart
  5. 2
      packages/harbour/lib/src/pages/login/login.dart
  6. 9
      packages/harbour/lib/src/utils/global.dart

2
packages/harbour/lib/main.dart

@ -25,6 +25,8 @@ Future main() async {
FlutterNativeSplash.preserve(widgetsBinding: WidgetsBinding.instance);
await Global.init();
final platform = getHarbourPlatform();
await platform.init?.call();

3
packages/harbour/lib/src/blocs/login.dart

@ -35,8 +35,7 @@ class LoginBloc extends $LoginBloc {
try {
final client = NextcloudClient(
url,
userAgentSuffix: userAgentSuffix,
appType: appType,
userAgentOverride: userAgentOverride(),
);
final status = (await client.core.getStatus())!;

1
packages/harbour/lib/src/harbour.dart

@ -69,6 +69,7 @@ part 'utils/app_implementation.dart';
part 'utils/confirmation_dialog.dart';
part 'utils/custom_timeago.dart';
part 'utils/env.dart';
part 'utils/global.dart';
part 'utils/global_options.dart';
part 'utils/hex_color.dart';
part 'utils/missing_permission_exception.dart';

7
packages/harbour/lib/src/models/account.dart

@ -9,9 +9,7 @@ import 'package:settings/settings.dart';
part 'account.g.dart';
// TODO: https://github.com/jld3103/nextcloud-harbour/issues/9
const userAgentSuffix = ' // Harbour';
const appType = AppType.nextcloud;
String userAgentOverride() => 'Harbour ${Global.packageInfo.version}+${Global.packageInfo.buildNumber}';
@JsonSerializable()
class Account {
@ -54,8 +52,7 @@ class Account {
serverURL,
username: username,
password: password ?? appPassword,
userAgentSuffix: userAgentSuffix,
appType: appType,
userAgentOverride: userAgentOverride(),
);
}

2
packages/harbour/lib/src/pages/login/login.dart

@ -73,6 +73,7 @@ class _LoginPageState extends State<LoginPage> {
final Env? env,
) =>
{
HttpHeaders.userAgentHeader: userAgentOverride(),
if (env != null) ...{
HttpHeaders.authorizationHeader:
'Basic ${base64.encode(utf8.encode('${env.testUsername}:${env.testPassword}'))}',
@ -136,6 +137,7 @@ class _LoginPageState extends State<LoginPage> {
? WebView(
javascriptMode: JavascriptMode.unrestricted,
zoomEnabled: false,
userAgent: userAgentOverride(),
onWebViewCreated: (final controller) async {
_webViewController = controller;
final url =

9
packages/harbour/lib/src/utils/global.dart

@ -0,0 +1,9 @@
part of '../harbour.dart';
class Global {
static Future init() async {
packageInfo = await PackageInfo.fromPlatform();
}
static late PackageInfo packageInfo;
}
Loading…
Cancel
Save