diff --git a/lib/Backend/Bluetooth/BluetoothManager.dart b/lib/Backend/Bluetooth/BluetoothManager.dart index 2b550d69..70231f93 100644 --- a/lib/Backend/Bluetooth/BluetoothManager.dart +++ b/lib/Backend/Bluetooth/BluetoothManager.dart @@ -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'; @@ -23,8 +24,6 @@ import 'btMessage.dart'; part 'BluetoothManager.g.dart'; -Dio dio = Dio(); - @Riverpod(dependencies: [reactiveBLE, KnownDevices]) Stream scanForDevices(ScanForDevicesRef ref) { Flogger.d("Starting scan"); @@ -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())); diff --git a/lib/Frontend/pages/ota_update.dart b/lib/Frontend/pages/ota_update.dart index 9f7fd341..2e016a72 100644 --- a/lib/Frontend/pages/ota_update.dart +++ b/lib/Frontend/pages/ota_update.dart @@ -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'; @@ -129,7 +130,7 @@ class _OtaUpdateState extends ConsumerState { otaState = OtaState.download; downloadProgress = 0; }); - final Response> rs = await Dio().get>(updateURL!.url, options: Options(responseType: ResponseType.bytes), onReceiveProgress: (current, total) { + final Response> rs = await initDio().get>(updateURL!.url, options: Options(responseType: ResponseType.bytes), onReceiveProgress: (current, total) { setState(() { downloadProgress = current / total; }); diff --git a/lib/main.dart b/lib/main.dart index d64fb1cf..3d679a64 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -94,6 +94,7 @@ Future main() async { await SentryHive.openBox('triggers'); await SentryHive.openBox('sequences'); await SentryHive.openBox('devices'); + initDio(); await SentryFlutter.init( (options) async { options.dsn = 'https://284f1830184d74dbbbb48ad14b577ffc@sentry.codel1417.xyz/3'; @@ -131,12 +132,13 @@ Future 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 {