Skip to content

Commit

Permalink
[Infrastructure] Added a method to retrieve webview user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Oct 9, 2024
1 parent 79aed90 commit 53cba0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/domain/enums/app_push_notification_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enum AppPushNotificationType {
newGameCodesAvailable,
}
16 changes: 16 additions & 0 deletions lib/infrastructure/app_infra_constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dart:io';

import 'package:flutter/services.dart';

const String _channelName = 'com.github.wolfteam.shiori';
const MethodChannel _appMethodChannel = MethodChannel(_channelName);

class AppMethodChannel {
static Future<String?> getWebViewUserAgent() async {
if (Platform.isWindows || Platform.isMacOS) {
return null;
}
final String? value = await _appMethodChannel.invokeMethod<String?>('getWebViewUserAgent');
return value?.replaceAll(RegExp('wv'), '');
}
}
11 changes: 4 additions & 7 deletions lib/infrastructure/device_info_service.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:fk_user_agent/fk_user_agent.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:shiori/domain/app_constants.dart';
import 'package:shiori/domain/extensions/string_extensions.dart';
import 'package:shiori/domain/services/device_info_service.dart';
import 'package:shiori/infrastructure/app_infra_constants.dart';
import 'package:store_checker/store_checker.dart';
import 'package:version_tracker/version_tracker.dart';

Expand All @@ -19,6 +19,7 @@ class DeviceInfoServiceImpl implements DeviceInfoService {
late String _packageName;
Source? _installationSource;
String? _buildNumber;
String? _userAgent;

@override
Map<String, String> get deviceInfo => _deviceInfo;
Expand All @@ -38,9 +39,8 @@ class DeviceInfoServiceImpl implements DeviceInfoService {
@override
bool get versionChanged => _versionChanged;

//TODO: COMPLETE THIS
@override
String? get userAgent => Platform.isWindows || Platform.isMacOS ? null : FkUserAgent.webViewUserAgent!.replaceAll(RegExp('wv'), '');
String? get userAgent => _userAgent;

@override
bool get installedFromValidSource {
Expand All @@ -65,6 +65,7 @@ class DeviceInfoServiceImpl implements DeviceInfoService {
_packageName = packageInfo.packageName;
_versionWithBuildNumber = '$_version+${packageInfo.buildNumber}';
_buildNumber = packageInfo.buildNumber;
_userAgent = await AppMethodChannel.getWebViewUserAgent();

await _setAppInfoProps();

Expand All @@ -87,10 +88,6 @@ class DeviceInfoServiceImpl implements DeviceInfoService {
if (Platform.isMacOS) {
await _initForMac();
}

if (!Platform.isWindows && !Platform.isMacOS) {
await FkUserAgent.init();
}
} catch (ex) {
_version = _versionWithBuildNumber = _appName = _packageName = na;
_setDefaultDeviceInfoProps(na, na);
Expand Down

0 comments on commit 53cba0a

Please sign in to comment.