Skip to content

Commit

Permalink
support bluetooth pre SDK 31 and readd cronet
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Apr 12, 2024
1 parent 370c70e commit da7bbe0
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 57 deletions.
3 changes: 2 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (flutterVersionName == null) {
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 34
Expand Down Expand Up @@ -68,6 +68,7 @@ android {
}
}
namespace 'com.codel1417.tail_app'
ndkVersion '25.1.8937393'
}

flutter {
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/Bluetooth/bluetooth_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/sensors.dart';
import 'package:tail_app/main.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

import '../../Frontend/utils.dart';
import '../../constants.dart';
import '../Definitions/Device/device_definition.dart';
import '../auto_move.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/Backend/plausible_dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/move_lists.dart';

import '../Frontend/utils.dart';
import '../constants.dart';
import '../main.dart';
import 'Definitions/Device/device_definition.dart';
Expand Down
5 changes: 2 additions & 3 deletions lib/Frontend/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart' as log;
import 'package:permission_handler/permission_handler.dart';
import 'package:tail_app/constants.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../Backend/Bluetooth/bluetooth_manager.dart';
import '../intn_defs.dart';
import '../utils.dart';

final log.Logger homeLogger = log.Logger('Home');

Expand Down Expand Up @@ -131,8 +131,7 @@ class _HomeState extends ConsumerState<Home> {
children: <Widget>[
TextButton(
onPressed: () async {
homeLogger.info("Permission BluetoothScan: ${await Permission.bluetoothScan.request()}");
homeLogger.info("Permission BluetoothConnect: ${await Permission.bluetoothConnect.request()}");
homeLogger.info("Permission Bluetooth: ${await getBluetoothPermission()}");
},
child: const Text('Grant Permissions'),
),
Expand Down
8 changes: 4 additions & 4 deletions lib/Frontend/pages/intro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:introduction_screen/introduction_screen.dart';
import 'package:lottie/lottie.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart';
import 'package:tail_app/Frontend/intn_defs.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../constants.dart';
import '../../main.dart';
import '../utils.dart';

class OnBoardingPage extends ConsumerStatefulWidget {
const OnBoardingPage({super.key});
Expand All @@ -28,6 +29,7 @@ class OnBoardingPageState extends ConsumerState<OnBoardingPage> {

void _onIntroEnd(BuildContext context) {
// Navigator.of(context).pushReplacement()
plausible.event(name: "Complete Onboarding");
SentryHive.box(settings).put(hasCompletedOnboarding, true);
context.pushReplacement('/');
}
Expand Down Expand Up @@ -166,9 +168,7 @@ class OnBoardingPageState extends ConsumerState<OnBoardingPage> {
onPressed: bluetoothAccepted
? null
: () async {
PermissionStatus value = await Permission.bluetoothScan.request();
PermissionStatus value2 = await Permission.bluetoothConnect.request();
if (value == PermissionStatus.granted && value2 == PermissionStatus.granted) {
if (await getBluetoothPermission()) {
setState(
() {
bluetoothAccepted = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/pages/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import 'package:path_provider/path_provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Frontend/intn_defs.dart';
import 'package:tail_app/main.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../constants.dart';
import '../utils.dart';

class More extends ConsumerStatefulWidget {
const More({super.key});
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/pages/ota_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart';
import 'package:tail_app/Backend/Definitions/Device/device_definition.dart';
import 'package:tail_app/main.dart';

import '../../Backend/firmware_update.dart';
import '../../constants.dart';
import '../intn_defs.dart';
import '../utils.dart';

class OtaUpdate extends ConsumerStatefulWidget {
const OtaUpdate({super.key, required this.device});
Expand Down
29 changes: 29 additions & 0 deletions lib/Frontend/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:cross_platform/cross_platform.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:dio/dio.dart';
import 'package:native_dio_adapter/native_dio_adapter.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sentry_dio/sentry_dio.dart';

Future<bool> getBluetoothPermission() async {
bool granted = false;
if (Platform.isAndroid && (await DeviceInfoPlugin().androidInfo).version.sdkInt > 30) {
granted = PermissionStatus.granted == await Permission.bluetoothScan.request();
granted = granted && PermissionStatus.granted == await Permission.bluetoothConnect.request();
} else {
granted = PermissionStatus.granted == await Permission.location.request();
granted = granted && PermissionStatus.granted == await Permission.locationWhenInUse.request();
granted = granted && PermissionStatus.granted == await Permission.bluetooth.request();
}
return granted;
}

Dio initDio() {
final Dio dio = Dio();

/// This *must* be the last initialization step of the Dio setup, otherwise
/// your configuration of Dio might overwrite the Sentry configuration.
dio.httpClientAdapter = NativeAdapter();
dio.addSentry(failedRequestStatusCodes: []);
return dio;
}
12 changes: 0 additions & 12 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:developer';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:feedback_sentry/feedback_sentry.dart';
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -14,7 +13,6 @@ import 'package:logging/logging.dart';
import 'package:logging_flutter/logging_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:plausible_analytics/plausible_analytics.dart';
import 'package:sentry_dio/sentry_dio.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:sentry_logging/sentry_logging.dart';
Expand Down Expand Up @@ -126,16 +124,6 @@ Future<void> main() async {
);
}

Dio initDio() {
final Dio dio = Dio();

/// This *must* be the last initialization step of the Dio setup, otherwise
/// your configuration of Dio might overwrite the Sentry configuration.
dio.addSentry(failedRequestStatusCodes: []);
return dio;
}

class TailApp extends ConsumerWidget {
TailApp({super.key}) {
//Init Plausible
Expand Down
Loading

0 comments on commit da7bbe0

Please sign in to comment.