Skip to content

Commit

Permalink
dio attach listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Mar 1, 2024
1 parent 6b300ac commit 675d38a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/Backend/Bluetooth/BluetoothManager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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 '../AutoMove.dart';
Expand All @@ -23,8 +24,6 @@ import 'btMessage.dart';

part 'BluetoothManager.g.dart';

Dio dio = Dio();

@Riverpod(dependencies: [reactiveBLE, KnownDevices])
Stream<DiscoveredDevice> scanForDevices(ScanForDevicesRef ref) {
Flogger.d("Starting scan");
Expand Down Expand Up @@ -154,7 +153,7 @@ class KnownDevices extends _$KnownDevices {
}
}, cancelOnError: true);
if (deviceDefinition.fwURL != "") {
dio.get(statefulDevice.baseDeviceDefinition.fwURL, options: Options(responseType: ResponseType.json)).then(
initDio().get(statefulDevice.baseDeviceDefinition.fwURL, options: Options(responseType: ResponseType.json)).then(
(value) {
if (value.statusCode == 200) {
statefulDevice.fwInfo.value = FWInfo.fromJson(const JsonDecoder().convert(value.data.toString()));
Expand Down
3 changes: 2 additions & 1 deletion lib/Frontend/pages/ota_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:tail_app/Backend/Bluetooth/BluetoothManager.dart';
import 'package:tail_app/Backend/Definitions/Device/BaseDeviceDefinition.dart';
import 'package:tail_app/main.dart';

import '../../Backend/FirmwareUpdate.dart';

Expand Down Expand Up @@ -129,7 +130,7 @@ class _OtaUpdateState extends ConsumerState<OtaUpdate> {
otaState = OtaState.download;
downloadProgress = 0;
});
final Response<List<int>> rs = await Dio().get<List<int>>(updateURL!.url, options: Options(responseType: ResponseType.bytes), onReceiveProgress: (current, total) {
final Response<List<int>> rs = await initDio().get<List<int>>(updateURL!.url, options: Options(responseType: ResponseType.bytes), onReceiveProgress: (current, total) {
setState(() {
downloadProgress = current / total;
});
Expand Down
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Future<void> main() async {
await SentryHive.openBox<Trigger>('triggers');
await SentryHive.openBox<MoveList>('sequences');
await SentryHive.openBox<BaseStoredDevice>('devices');
initDio();
await SentryFlutter.init(
(options) async {
options.dsn = 'https://[email protected]/3';
Expand Down Expand Up @@ -131,12 +132,13 @@ Future<void> main() async {
);
}

void initDio() {
Dio initDio() {
final 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();
return dio;
}

class TailApp extends ConsumerWidget {
Expand Down

0 comments on commit 675d38a

Please sign in to comment.