From cb96c58dd82aa6d6cb4d6dca9a974de1161ff990 Mon Sep 17 00:00:00 2001 From: Codel1417 Date: Fri, 31 May 2024 19:19:29 -0400 Subject: [PATCH] Add new log ui --- lib/Backend/Bluetooth/bluetooth_manager.dart | 9 ++- .../Bluetooth/bluetooth_manager_plus.dart | 14 ++--- lib/Backend/LoggingWrappers.dart | 52 +++++++++++++++++ lib/Backend/action_registry.dart | 9 ++- lib/Backend/audio.dart | 9 ++- lib/Backend/background_update.dart | 9 +-- lib/Backend/move_lists.dart | 9 ++- lib/Backend/plausible_dio.dart | 10 ++-- lib/Backend/sensors.dart | 17 +++--- .../Widgets/bt_app_state_controller.dart | 4 +- lib/Frontend/Widgets/known_gear.dart | 4 +- lib/Frontend/Widgets/scan_for_new_device.dart | 8 +-- lib/Frontend/Widgets/tail_blog.dart | 5 +- lib/Frontend/Widgets/tutorial_card.dart | 28 +++++----- lib/Frontend/go_router_config.dart | 22 ++++++-- lib/Frontend/pages/actions.dart | 10 ++-- .../pages/developer/developer_menu.dart | 25 ++++----- .../pages/developer/developer_pincode.dart | 4 +- lib/Frontend/pages/direct_gear_control.dart | 6 +- lib/Frontend/pages/home.dart | 4 +- lib/Frontend/pages/intro.dart | 15 +++-- lib/Frontend/pages/more.dart | 4 +- lib/Frontend/pages/move_list.dart | 6 +- lib/Frontend/pages/ota_update.dart | 10 ++-- lib/Frontend/pages/settings.dart | 56 +++++++++---------- lib/Frontend/pages/shell.dart | 9 +-- lib/Frontend/utils.dart | 8 ++- lib/main.dart | 36 ++++++------ pubspec.lock | 23 ++++---- pubspec.yaml | 6 +- 30 files changed, 248 insertions(+), 183 deletions(-) create mode 100644 lib/Backend/LoggingWrappers.dart diff --git a/lib/Backend/Bluetooth/bluetooth_manager.dart b/lib/Backend/Bluetooth/bluetooth_manager.dart index 9d34fbdf..21541ca2 100644 --- a/lib/Backend/Bluetooth/bluetooth_manager.dart +++ b/lib/Backend/Bluetooth/bluetooth_manager.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:logging/logging.dart' as log; import 'package:riverpod_annotation/riverpod_annotation.dart'; -import 'package:sentry_hive/sentry_hive.dart'; +import 'package:tail_app/Backend/LoggingWrappers.dart'; import '../Definitions/Device/device_definition.dart'; import '../device_registry.dart'; @@ -15,7 +15,7 @@ final log.Logger bluetoothLog = log.Logger('Bluetooth'); class KnownDevices extends _$KnownDevices { @override Map build() { - List storedDevices = SentryHive.box('devices').values.toList(); + List storedDevices = HiveProxy.getAll('devices').toList(); Map results = {}; try { if (storedDevices.isNotEmpty) { @@ -50,8 +50,7 @@ class KnownDevices extends _$KnownDevices { } Future store() async { - SentryHive.box('devices') - ..clear() - ..addAll(state.values.map((e) => e.baseStoredDevice)); + await HiveProxy.clear('devices'); + await HiveProxy.addAll('devices', state.values.map((e) => e.baseStoredDevice)); } } diff --git a/lib/Backend/Bluetooth/bluetooth_manager_plus.dart b/lib/Backend/Bluetooth/bluetooth_manager_plus.dart index c48777b6..70ce7e78 100644 --- a/lib/Backend/Bluetooth/bluetooth_manager_plus.dart +++ b/lib/Backend/Bluetooth/bluetooth_manager_plus.dart @@ -9,13 +9,13 @@ import 'package:flutter_foreground_task/flutter_foreground_task.dart'; import 'package:logging/logging.dart' as log; import 'package:permission_handler/permission_handler.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; import 'package:tail_app/Backend/device_registry.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; import '../../Frontend/utils.dart'; import '../../constants.dart'; +import '../LoggingWrappers.dart'; import '../sensors.dart'; import 'bluetooth_manager.dart'; import 'bluetooth_message.dart'; @@ -96,7 +96,7 @@ Future initFlutterBluePlus(InitFlutterBluePlusRef ref) async { // The timer used for the time value on the battery level graph statefulDevice.stopWatch.start(); isAnyGearConnected.value = true; - if (SentryHive.box(settings).get(keepAwake, defaultValue: keepAwakeDefault)) { + if (HiveProxy.getOrDefault(settings, keepAwake, defaultValue: keepAwakeDefault)) { _bluetoothPlusLogger.fine('Enabling wakelock'); WakelockPlus.enable(); } @@ -129,12 +129,12 @@ Future initFlutterBluePlus(InitFlutterBluePlusRef ref) async { if (bluetoothConnectionState == BluetoothConnectionState.disconnected) { _bluetoothPlusLogger.info("Disconnected from device: ${bluetoothDevice.remoteId.str}"); // We don't want to display the app review screen right away. We keep track of gear disconnects and after 5 we try to display the review dialog. - int count = SentryHive.box(settings).get(gearDisconnectCount, defaultValue: gearDisconnectCountDefault) + 1; - if (count > 5 && SentryHive.box(settings).get(hasDisplayedReview, defaultValue: hasDisplayedReviewDefault)) { - SentryHive.box(settings).put(shouldDisplayReview, true); + int count = HiveProxy.getOrDefault(settings, gearDisconnectCount, defaultValue: gearDisconnectCountDefault) + 1; + if (count > 5 && HiveProxy.getOrDefault(settings, hasDisplayedReview, defaultValue: hasDisplayedReviewDefault)!) { + HiveProxy.put(settings, shouldDisplayReview, true); _bluetoothPlusLogger.finer('Setting shouldDisplayReview to true'); } else { - SentryHive.box(settings).put(gearDisconnectCount, count); + HiveProxy.put(settings, gearDisconnectCount, count); _bluetoothPlusLogger.finer('Setting gearDisconnectCount to $count'); } //ref.read(snackbarStreamProvider.notifier).add(SnackBar(content: Text("Disconnected from ${baseStatefulDevice.baseStoredDevice.name}"))); @@ -215,7 +215,7 @@ Future initFlutterBluePlus(InitFlutterBluePlusRef ref) async { try { value = const Utf8Decoder().convert(values); } catch (e, s) { - _bluetoothPlusLogger.warning("Unable to read values: $values $e"); + _bluetoothPlusLogger.warning("Unable to read values: $values $e", e, s); statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: "Unknown: ${values.toString()}")); return; } diff --git a/lib/Backend/LoggingWrappers.dart b/lib/Backend/LoggingWrappers.dart new file mode 100644 index 00000000..2fdd22ee --- /dev/null +++ b/lib/Backend/LoggingWrappers.dart @@ -0,0 +1,52 @@ +import 'package:logarte/logarte.dart'; +import 'package:sentry_hive/sentry_hive.dart'; + +import '../constants.dart'; + +_HiveProxyImpl HiveProxy = _HiveProxyImpl(); +List genericBoxes = [settings, notificationBox]; + +class _HiveProxyImpl { + Future put(String box, dynamic key, E value) { + logarte.database( + target: '$key', + value: '$value', + source: box, + ); + if (genericBoxes.contains(box)) { + return SentryHive.box(box).put(key, value); + } else { + return SentryHive.box(box).put(key, value); + } + } + + E getOrDefault(String box, dynamic key, {E? defaultValue}) { + if (genericBoxes.contains(box)) { + return SentryHive.box(box).get(key, defaultValue: defaultValue)!; + } else { + return SentryHive.box(box).get(key, defaultValue: defaultValue)!; + } + } + + Future clear(String box) { + if (genericBoxes.contains(box)) { + return SentryHive.box(box).clear(); + } else { + return SentryHive.box(box).clear(); + } + } + + Future> addAll(String name, Iterable values) { + return SentryHive.box(name).addAll(values); + } + + Iterable getAll(String name) { + return SentryHive.box(name).values; + } +} + +final Logarte logarte = Logarte( + // Whether to ignore the password + ignorePassword: true, + disableDebugConsoleLogs: true, +); diff --git a/lib/Backend/action_registry.dart b/lib/Backend/action_registry.dart index 9a34d69e..869fdd93 100644 --- a/lib/Backend/action_registry.dart +++ b/lib/Backend/action_registry.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/audio.dart'; import 'package:tail_app/Backend/move_lists.dart'; import 'package:tail_app/Backend/wear_bridge.dart'; @@ -12,6 +11,7 @@ import 'Bluetooth/bluetooth_manager.dart'; import 'Bluetooth/bluetooth_manager_plus.dart'; import 'Definitions/Action/base_action.dart'; import 'Definitions/Device/device_definition.dart'; +import 'LoggingWrappers.dart'; import 'app_shortcuts.dart'; part 'action_registry.g.dart'; @@ -352,7 +352,7 @@ class FavoriteActions extends _$FavoriteActions { List build() { List results = []; try { - results = SentryHive.box(favoriteActionsBox).values.toList(growable: true); + results = HiveProxy.getAll(favoriteActionsBox).toList(growable: true); } catch (e, s) { actionRegistryLogger.severe("Unable to load favorites: $e", e, s); } @@ -376,9 +376,8 @@ class FavoriteActions extends _$FavoriteActions { Future store() async { actionRegistryLogger.info("Storing favorites"); - SentryHive.box(favoriteActionsBox) - ..clear() - ..addAll(state); + await HiveProxy.clear(favoriteActionsBox); + await HiveProxy.addAll(favoriteActionsBox, state); updateShortcuts(state, ref); updateWearActions(state, ref); } diff --git a/lib/Backend/audio.dart b/lib/Backend/audio.dart index 17493988..dfa3f243 100644 --- a/lib/Backend/audio.dart +++ b/lib/Backend/audio.dart @@ -2,10 +2,10 @@ import 'package:audio_session/audio_session.dart'; import 'package:just_audio/just_audio.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Definitions/Action/base_action.dart'; import '../constants.dart'; +import 'LoggingWrappers.dart'; part 'audio.g.dart'; @@ -44,7 +44,7 @@ class UserAudioActions extends _$UserAudioActions { List build() { List results = []; try { - results = SentryHive.box(audioActionsBox).values.toList(growable: true); + results = HiveProxy.getAll(audioActionsBox).toList(growable: true); } catch (e, s) { _audioLogger.severe("Unable to load audio: $e", e, s); } @@ -68,8 +68,7 @@ class UserAudioActions extends _$UserAudioActions { Future store() async { _audioLogger.info("Storing Custom Audio"); - SentryHive.box(audioActionsBox) - ..clear() - ..addAll(state); + await HiveProxy.clear(audioActionsBox); + await HiveProxy.addAll(audioActionsBox, state); } } diff --git a/lib/Backend/background_update.dart b/lib/Backend/background_update.dart index 009d8508..94b22364 100644 --- a/lib/Backend/background_update.dart +++ b/lib/Backend/background_update.dart @@ -3,11 +3,12 @@ import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:background_fetch/background_fetch.dart'; import 'package:logging/logging.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Frontend/utils.dart'; import 'package:tail_app/constants.dart'; import 'package:wordpress_client/wordpress_client.dart'; +import 'LoggingWrappers.dart'; + final _backgroundLogger = Logger('BackgroundLogger'); Future initBackgroundTasks() async { @@ -51,7 +52,7 @@ Future initBackgroundTasks() async { } Future checkForNewPosts() async { - if (!SentryHive.box(settings).get(allowNewsletterNotifications, defaultValue: allowNewsletterNotificationsDefault)) { + if (!HiveProxy.getOrDefault(settings, allowNewsletterNotifications, defaultValue: allowNewsletterNotificationsDefault)) { return; } _backgroundLogger.info("Checking for new posts"); @@ -70,10 +71,10 @@ Future checkForNewPosts() async { if (data != null) { final Post post = data.first; final int id = post.id; - final int oldID = SentryHive.box(notificationBox).get(latestPost, defaultValue: defaultPostId); + final int oldID = HiveProxy.getOrDefault(notificationBox, latestPost, defaultValue: defaultPostId); if (oldID < id) { _backgroundLogger.info("Found a new post"); - SentryHive.box(notificationBox).put(showAccurateBattery, id); + HiveProxy.put(notificationBox, showAccurateBattery, id); AwesomeNotifications().createNotification( content: NotificationContent( id: id, diff --git a/lib/Backend/move_lists.dart b/lib/Backend/move_lists.dart index 554a64b3..01da29c2 100644 --- a/lib/Backend/move_lists.dart +++ b/lib/Backend/move_lists.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_message.dart'; import 'package:tail_app/Backend/Definitions/Action/base_action.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; @@ -11,6 +10,7 @@ import 'package:tail_app/Backend/audio.dart'; import 'package:tail_app/Frontend/translation_string_definitions.dart'; import '../main.dart'; +import 'LoggingWrappers.dart'; part 'move_lists.g.dart'; @@ -162,7 +162,7 @@ class MoveLists extends _$MoveLists { List build() { List results = []; try { - results = SentryHive.box('sequences').values.toList(growable: true); + results = HiveProxy.getAll('sequences').toList(growable: true); } catch (e, s) { sequencesLogger.severe("Unable to load sequences: $e", e, s); } @@ -183,9 +183,8 @@ class MoveLists extends _$MoveLists { Future store() async { sequencesLogger.info("Storing sequences"); - SentryHive.box('sequences') - ..clear() - ..addAll(state); + HiveProxy.clear('sequences'); + HiveProxy.addAll('sequences', state); } } diff --git a/lib/Backend/plausible_dio.dart b/lib/Backend/plausible_dio.dart index 3a0536f7..a7524d0f 100644 --- a/lib/Backend/plausible_dio.dart +++ b/lib/Backend/plausible_dio.dart @@ -8,13 +8,13 @@ import 'package:install_referrer/install_referrer.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:plausible_analytics/plausible_analytics.dart'; 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'; +import 'LoggingWrappers.dart'; import 'sensors.dart'; class PlausibleDio extends Plausible { @@ -25,7 +25,7 @@ class PlausibleDio extends Plausible { /// Post event to plausible @override Future event({String name = "pageview", String referrer = "", String page = "", Map props = const {}}) async { - if (!enabled && SentryHive.box(settings).get(allowAnalytics, defaultValue: allowAnalyticsDefault)) { + if (!enabled && HiveProxy.getOrDefault(settings, allowAnalytics, defaultValue: allowAnalyticsDefault)) { return 0; } final transaction = Sentry.startTransaction('Plausible Event', 'http'); @@ -37,9 +37,9 @@ class PlausibleDio extends Plausible { page = "app://localhost/$page?utm_source=${(await InstallReferrer.referrer).name}"; referrer = "app://localhost/$referrer"; props = Map.of(props); - props['Number Of Devices'] = SentryHive.box('devices').length.toString(); - props['Number Of Sequences'] = SentryHive.box('sequences').length.toString(); - props['Number Of Triggers'] = SentryHive.box(triggerBox).length.toString(); + props['Number Of Devices'] = HiveProxy.getAll('devices').length.toString(); + props['Number Of Sequences'] = HiveProxy.getAll('sequences').length.toString(); + props['Number Of Triggers'] = HiveProxy.getAll(triggerBox).length.toString(); props['App Version'] = (await PackageInfo.fromPlatform()).version; props['App Build'] = (await PackageInfo.fromPlatform()).buildNumber; diff --git a/lib/Backend/sensors.dart b/lib/Backend/sensors.dart index e6a0e5a2..d6967a3d 100644 --- a/lib/Backend/sensors.dart +++ b/lib/Backend/sensors.dart @@ -13,7 +13,6 @@ import 'package:pedometer/pedometer.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:proximity_sensor/proximity_sensor.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:shake/shake.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager_plus.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_message.dart'; @@ -24,6 +23,7 @@ import '../constants.dart'; import 'Bluetooth/bluetooth_manager.dart'; import 'Definitions/Action/base_action.dart'; import 'Definitions/Device/device_definition.dart'; +import 'LoggingWrappers.dart'; import 'move_lists.dart'; part 'sensors.g.dart'; @@ -247,7 +247,7 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable build() { List results = []; try { - results = SentryHive.box(triggerBox).values.map((trigger) { + results = HiveProxy.getAll(triggerBox).map((trigger) { Trigger trigger2 = Trigger.trigDef(ref.read(triggerDefinitionListProvider).firstWhere((element) => element.uuid == trigger.triggerDefUUID), trigger.uuid); trigger2.actions = trigger.actions; trigger2.deviceType = trigger.deviceType; @@ -724,9 +724,9 @@ class TriggerList extends _$TriggerList { Trigger trigger = Trigger.trigDef(triggerDefinition, '91e3d421-6a52-45ab-a23e-f38e4987a8f5'); trigger.actions.firstWhere((element) => element.uuid == '77d22961-5a69-465a-bd27-5cf5508d10a6').actions.add(ActionRegistry.allCommands.firstWhere((element) => element.uuid == 'c53e980e-899e-4148-a13e-f57a8f9707f4').uuid); trigger.actions.firstWhere((element) => element.uuid == '7424097d-ba24-4d85-b963-bf58e85e289d').actions.add(ActionRegistry.allCommands.firstWhere((element) => element.uuid == '86b13d13-b09c-46ba-a887-b40d8118b00a').uuid); - SentryHive.box(triggerBox) - ..clear() - ..addAll([trigger]); + + HiveProxy.clear(triggerBox); + HiveProxy.addAll(triggerBox, [trigger]); return [trigger]; } return results; @@ -745,9 +745,8 @@ class TriggerList extends _$TriggerList { Future store() async { sensorsLogger.info("Storing triggers"); - SentryHive.box(triggerBox) - ..clear() - ..addAll(state); + await HiveProxy.clear(triggerBox); + await HiveProxy.addAll(triggerBox, state); } } diff --git a/lib/Frontend/Widgets/bt_app_state_controller.dart b/lib/Frontend/Widgets/bt_app_state_controller.dart index 90cb6966..6e6ef0b9 100644 --- a/lib/Frontend/Widgets/bt_app_state_controller.dart +++ b/lib/Frontend/Widgets/bt_app_state_controller.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import '../../Backend/Bluetooth/bluetooth_manager_plus.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../constants.dart'; class BtAppStateController extends ConsumerStatefulWidget { @@ -31,7 +31,7 @@ class _BtAppStateControllerState extends ConsumerState { }, ); // start FlutterBluePlus if its not started already - if (SentryHive.box(settings).get(hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) >= hasCompletedOnboardingVersionToAgree) { + if (HiveProxy.getOrDefault(settings, hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) >= hasCompletedOnboardingVersionToAgree) { ref.read(initFlutterBluePlusProvider); } } diff --git a/lib/Frontend/Widgets/known_gear.dart b/lib/Frontend/Widgets/known_gear.dart index 02d7a790..cf2f8fae 100644 --- a/lib/Frontend/Widgets/known_gear.dart +++ b/lib/Frontend/Widgets/known_gear.dart @@ -1,11 +1,11 @@ import 'package:animate_do/animate_do.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; import 'package:tail_app/Frontend/Widgets/scan_for_new_device.dart'; import '../../Backend/Bluetooth/bluetooth_manager.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../constants.dart'; import '../../main.dart'; import '../pages/shell.dart'; @@ -263,7 +263,7 @@ class _KnownGearCardState extends ConsumerState { } Widget getBattery(double level) { - if (SentryHive.box(settings).get(showAccurateBattery, defaultValue: showAccurateBatteryDefault)) { + if (HiveProxy.getOrDefault(settings, showAccurateBattery, defaultValue: showAccurateBatteryDefault)) { if (level < 0) { // battery level is unknown return const Text('?%'); diff --git a/lib/Frontend/Widgets/scan_for_new_device.dart b/lib/Frontend/Widgets/scan_for_new_device.dart index 081f8fbc..2fa56a8c 100644 --- a/lib/Frontend/Widgets/scan_for_new_device.dart +++ b/lib/Frontend/Widgets/scan_for_new_device.dart @@ -3,12 +3,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager_plus.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; import 'package:tail_app/Frontend/Widgets/tutorial_card.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../Backend/device_registry.dart'; import '../../constants.dart'; import '../../gen/assets.gen.dart'; @@ -38,7 +38,7 @@ class _ScanForNewDevice extends ConsumerState { @override void dispose() { super.dispose(); - if (!SentryHive.box(settings).get(alwaysScanning, defaultValue: alwaysScanningDefault) || !anyKnownGear) { + if (!HiveProxy.getOrDefault(settings, alwaysScanning, defaultValue: alwaysScanningDefault) || !anyKnownGear) { stopScan(); } } @@ -81,7 +81,7 @@ class _ScanForNewDevice extends ConsumerState { ScanResult e = snapshot.data!.where((test) => !knownDeviceIds.contains(test.device.remoteId.str)).toList()[index]; return ListTile( title: Text(getNameFromBTName(e.device.advName)), - trailing: Text(SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault) ? e.device.remoteId.str : ""), + trailing: Text(HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault) ? e.device.remoteId.str : ""), onTap: () async { await e.device.connect(); plausible.event(name: "Connect New Gear", props: {"Gear Type": e.device.advName}); @@ -130,7 +130,7 @@ class _ScanForNewDevice extends ConsumerState { ); }, ), - if (SentryHive.box(settings).get(showDemoGear, defaultValue: showDemoGearDefault)) ...[ + if (HiveProxy.getOrDefault(settings, showDemoGear, defaultValue: showDemoGearDefault)) ...[ ExpansionTile( title: Text(scanDemoGear()), children: [ diff --git a/lib/Frontend/Widgets/tail_blog.dart b/lib/Frontend/Widgets/tail_blog.dart index 4bac1a01..522fcb9b 100644 --- a/lib/Frontend/Widgets/tail_blog.dart +++ b/lib/Frontend/Widgets/tail_blog.dart @@ -5,12 +5,13 @@ import 'package:logging/logging.dart'; import 'package:path_provider/path_provider.dart'; import 'package:sentry_file/sentry_file.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Frontend/utils.dart'; import 'package:tail_app/constants.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:wordpress_client/wordpress_client.dart'; +import '../../Backend/LoggingWrappers.dart'; + final _wpLogger = Logger('Main'); class TailBlog extends StatefulWidget { @@ -117,7 +118,7 @@ class _TailBlogState extends State { if (data != null) { _wordpressPosts = data; // Store the latest post id for checking for new posts - SentryHive.box(notificationBox).put(latestPost, data.first.id); + HiveProxy.put(notificationBox, latestPost, data.first.id); } } catch (e, s) { setState(() { diff --git a/lib/Frontend/Widgets/tutorial_card.dart b/lib/Frontend/Widgets/tutorial_card.dart index 89d2d931..7ae09ff8 100644 --- a/lib/Frontend/Widgets/tutorial_card.dart +++ b/lib/Frontend/Widgets/tutorial_card.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:sentry_hive/sentry_hive.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../constants.dart'; class PageInfoCard extends StatelessWidget { @@ -10,20 +10,20 @@ class PageInfoCard extends StatelessWidget { @override Widget build(BuildContext context) { - bool show = !SentryHive.box(settings).get(hideTutorialCards, defaultValue: hideTutorialCardsDefault); + bool show = !HiveProxy.getOrDefault(settings, hideTutorialCards, defaultValue: hideTutorialCardsDefault); return show ? Padding( - padding: const EdgeInsets.all(16.0), - child: Card( - clipBehavior: Clip.antiAlias, - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Center( - child: Text(text), - ), - ), - ), - ) + padding: const EdgeInsets.all(16.0), + child: Card( + clipBehavior: Clip.antiAlias, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Center( + child: Text(text), + ), + ), + ), + ) : Container(); } -} \ No newline at end of file +} diff --git a/lib/Frontend/go_router_config.dart b/lib/Frontend/go_router_config.dart index d62ce713..bc98ebcd 100644 --- a/lib/Frontend/go_router_config.dart +++ b/lib/Frontend/go_router_config.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; +import 'package:logarte/logarte.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; import 'package:tail_app/Frontend/pages/action_selector.dart'; import 'package:tail_app/Frontend/pages/custom_audio.dart'; @@ -20,6 +20,7 @@ import 'package:tail_app/Frontend/pages/triggers.dart'; import 'package:tail_app/Frontend/pages/view_pdf.dart'; import 'package:tail_app/constants.dart'; +import '../Backend/LoggingWrappers.dart'; import '../Backend/NavigationObserver/custom_go_router_navigation_observer.dart'; import '../main.dart'; import 'pages/actions.dart'; @@ -30,7 +31,11 @@ final GlobalKey _shellNavigatorKey = GlobalKey() final GoRouter router = GoRouter( debugLogDiagnostics: true, navigatorKey: _rootNavigatorKey, - observers: [SentryNavigatorObserver(), CustomNavObserver(plausible)], + observers: [ + SentryNavigatorObserver(), + CustomNavObserver(plausible), + LogarteNavigatorObserver(logarte), + ], routes: [ ShellRoute( navigatorKey: _shellNavigatorKey, @@ -47,7 +52,7 @@ final GoRouter router = GoRouter( name: 'Actions', ), redirect: (context, state) { - if (SentryHive.box(settings).get(hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) < hasCompletedOnboardingVersionToAgree) { + if (HiveProxy.getOrDefault(settings, hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) < hasCompletedOnboardingVersionToAgree) { return '/onboarding'; } return null; @@ -152,7 +157,7 @@ final GoRouter router = GoRouter( ); }, redirect: (context, state) { - if (SentryHive.box(settings).get(hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) == hasCompletedOnboardingVersionToAgree) { + if (HiveProxy.getOrDefault(settings, hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) == hasCompletedOnboardingVersionToAgree) { return '/'; } return null; @@ -216,6 +221,15 @@ final GoRouter router = GoRouter( parentNavigatorKey: _rootNavigatorKey, builder: (BuildContext context, GoRouterState state) => BluetoothConsole(device: state.extra! as BaseStatefulDevice), ), + GoRoute( + name: 'Settings/Developer Menu/Logs', + path: 'logs', + parentNavigatorKey: _rootNavigatorKey, + builder: (BuildContext context, GoRouterState state) => LogarteDashboardScreen( + logarte, + showBackButton: true, + ), + ), GoRoute( name: 'Settings/Developer Menu/Pin', path: 'pin', diff --git a/lib/Frontend/pages/actions.dart b/lib/Frontend/pages/actions.dart index 076325ae..d214b3ed 100644 --- a/lib/Frontend/pages/actions.dart +++ b/lib/Frontend/pages/actions.dart @@ -7,11 +7,11 @@ import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:multi_listenable_builder/multi_listenable_builder.dart'; import 'package:multi_value_listenable_builder/multi_value_listenable_builder.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import '../../Backend/Bluetooth/bluetooth_manager.dart'; import '../../Backend/Definitions/Action/base_action.dart'; import '../../Backend/Definitions/Device/device_definition.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../Backend/action_registry.dart'; import '../../Backend/device_registry.dart'; import '../../Backend/move_lists.dart'; @@ -41,7 +41,7 @@ class ActionPageBuilder extends ConsumerStatefulWidget { class _ActionPageBuilderState extends ConsumerState { @override Widget build(BuildContext context) { - bool largerCards = SentryHive.box(settings).get(largerActionCardSize, defaultValue: largerActionCardSizeDefault); + bool largerCards = HiveProxy.getOrDefault(settings, largerActionCardSize, defaultValue: largerActionCardSizeDefault); Map knownDevices = ref.watch(knownDevicesProvider); return MultiValueListenableBuilder( @@ -143,7 +143,7 @@ class _ActionPageBuilderState extends ConsumerState { elevation: 1, child: InkWell( onLongPress: () { - if (SentryHive.box(settings).get(haptics, defaultValue: hapticsDefault)) { + if (HiveProxy.getOrDefault(settings, haptics, defaultValue: hapticsDefault)) { HapticFeedback.mediumImpact(); setState( () { @@ -157,11 +157,11 @@ class _ActionPageBuilderState extends ConsumerState { } }, onTap: () async { - if (SentryHive.box(settings).get(haptics, defaultValue: hapticsDefault)) { + if (HiveProxy.getOrDefault(settings, haptics, defaultValue: hapticsDefault)) { HapticFeedback.selectionClick(); } for (var device in ref.read(getByActionProvider(action)).toList()..shuffle()) { - if (SentryHive.box(settings).get(kitsuneModeToggle, defaultValue: kitsuneModeDefault)) { + if (HiveProxy.getOrDefault(settings, kitsuneModeToggle, defaultValue: kitsuneModeDefault)) { await Future.delayed(Duration(milliseconds: Random().nextInt(kitsuneDelayRange))); } runAction(action, device); diff --git a/lib/Frontend/pages/developer/developer_menu.dart b/lib/Frontend/pages/developer/developer_menu.dart index 9dd706b5..bea794e5 100644 --- a/lib/Frontend/pages/developer/developer_menu.dart +++ b/lib/Frontend/pages/developer/developer_menu.dart @@ -1,10 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; -import 'package:logging_flutter/logging_flutter.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import '../../../Backend/Bluetooth/bluetooth_manager_plus.dart'; +import '../../../Backend/LoggingWrappers.dart'; import '../../../constants.dart'; class DeveloperMenu extends ConsumerStatefulWidget { @@ -35,7 +34,7 @@ class _DeveloperMenuState extends ConsumerState { leading: const Icon(Icons.list), subtitle: const Text("Application Logs"), onTap: () { - LogConsole.open(context); + context.push("/settings/developer/logs"); }, ), ListTile( @@ -49,11 +48,11 @@ class _DeveloperMenuState extends ConsumerState { ListTile( title: const Text(hasCompletedOnboarding), trailing: Switch( - value: SentryHive.box(settings).get(hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) == hasCompletedOnboardingVersionToAgree, + value: HiveProxy.getOrDefault(settings, hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) == hasCompletedOnboardingVersionToAgree, onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(hasCompletedOnboarding, value ? hasCompletedOnboardingVersionToAgree : hasCompletedOnboardingDefault); + HiveProxy.put(settings, hasCompletedOnboarding, value ? hasCompletedOnboardingVersionToAgree : hasCompletedOnboardingDefault); }, ); }, @@ -62,11 +61,11 @@ class _DeveloperMenuState extends ConsumerState { ListTile( title: const Text(shouldDisplayReview), trailing: Switch( - value: SentryHive.box(settings).get(shouldDisplayReview, defaultValue: shouldDisplayReviewDefault), + value: HiveProxy.getOrDefault(settings, shouldDisplayReview, defaultValue: shouldDisplayReviewDefault), onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(shouldDisplayReview, value); + HiveProxy.put(settings, shouldDisplayReview, value); }, ); }, @@ -75,11 +74,11 @@ class _DeveloperMenuState extends ConsumerState { ListTile( title: const Text(hasDisplayedReview), trailing: Switch( - value: SentryHive.box(settings).get(hasDisplayedReview, defaultValue: hasDisplayedReviewDefault), + value: HiveProxy.getOrDefault(settings, hasDisplayedReview, defaultValue: hasDisplayedReviewDefault), onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(hasDisplayedReview, value); + HiveProxy.put(settings, hasDisplayedReview, value); }, ); }, @@ -91,10 +90,10 @@ class _DeveloperMenuState extends ConsumerState { divisions: 6, max: 6, min: 0, - value: SentryHive.box(settings).get(gearDisconnectCount, defaultValue: gearDisconnectCountDefault).toDouble(), + value: HiveProxy.getOrDefault(settings, gearDisconnectCount, defaultValue: gearDisconnectCountDefault).toDouble(), onChanged: (double value) { setState(() { - SentryHive.box(settings).put(gearDisconnectCount, value.toInt()); + HiveProxy.put(settings, gearDisconnectCount, value.toInt()); }); }, ), @@ -102,11 +101,11 @@ class _DeveloperMenuState extends ConsumerState { ListTile( title: const Text(showDebugging), trailing: Switch( - value: SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault), + value: HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault), onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(showDebugging, value); + HiveProxy.put(settings, showDebugging, value); context.pop(); }, ); diff --git a/lib/Frontend/pages/developer/developer_pincode.dart b/lib/Frontend/pages/developer/developer_pincode.dart index d1667af2..478e58ac 100644 --- a/lib/Frontend/pages/developer/developer_pincode.dart +++ b/lib/Frontend/pages/developer/developer_pincode.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_screen_lock/flutter_screen_lock.dart'; import 'package:go_router/go_router.dart'; -import 'package:sentry_hive/sentry_hive.dart'; +import '../../../Backend/LoggingWrappers.dart'; import '../../../constants.dart'; import '../../../gen/assets.gen.dart'; import '../../Widgets/lottie_lazy_load.dart'; @@ -25,7 +25,7 @@ class _DeveloperPincodeState extends State { ), onCancelled: () => context.pop(), onUnlocked: () { - SentryHive.box(settings).put(showDebugging, true); + HiveProxy.put(settings, showDebugging, true); context.pop(); }, // One at top left, 9 at bottom right diff --git a/lib/Frontend/pages/direct_gear_control.dart b/lib/Frontend/pages/direct_gear_control.dart index 96250ca5..b882308c 100644 --- a/lib/Frontend/pages/direct_gear_control.dart +++ b/lib/Frontend/pages/direct_gear_control.dart @@ -4,13 +4,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_joystick/flutter_joystick.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Frontend/Widgets/speed_widget.dart'; import 'package:vector_math/vector_math.dart'; import '../../Backend/Bluetooth/bluetooth_manager.dart'; import '../../Backend/Bluetooth/bluetooth_message.dart'; import '../../Backend/Definitions/Device/device_definition.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../Backend/move_lists.dart'; import '../../constants.dart'; import '../Widgets/device_type_widget.dart'; @@ -83,7 +83,7 @@ class _JoystickState extends ConsumerState { listener: (details) { setState( () { - if (SentryHive.box(settings).get(haptics, defaultValue: hapticsDefault)) { + if (HiveProxy.getOrDefault(settings, haptics, defaultValue: hapticsDefault)) { HapticFeedback.selectionClick(); } x = details.x; @@ -111,7 +111,7 @@ class _JoystickState extends ConsumerState { ), ], ), - if (SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) ...[ + if (HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault)) ...[ Padding( padding: const EdgeInsets.fromLTRB(8.0, 400, 8, 8), child: Align( diff --git a/lib/Frontend/pages/home.dart b/lib/Frontend/pages/home.dart index adba4848..a3333e31 100644 --- a/lib/Frontend/pages/home.dart +++ b/lib/Frontend/pages/home.dart @@ -4,13 +4,13 @@ import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:logging/logging.dart' as log; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager_plus.dart'; import 'package:tail_app/Frontend/Widgets/base_card.dart'; import 'package:tail_app/constants.dart'; import 'package:url_launcher/url_launcher.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../Widgets/tail_blog.dart'; import '../translation_string_definitions.dart'; import 'markdown_viewer.dart'; @@ -68,7 +68,7 @@ class _HomeState extends ConsumerState { child: Column( mainAxisSize: MainAxisSize.min, children: [ - if (ref.read(knownDevicesProvider).isNotEmpty && !SentryHive.box(settings).get(alwaysScanning, defaultValue: alwaysScanningDefault) && !SentryHive.box(settings).get(hideTutorialCards, defaultValue: hideTutorialCardsDefault)) ...[ + if (ref.read(knownDevicesProvider).isNotEmpty && !HiveProxy.getOrDefault(settings, alwaysScanning, defaultValue: alwaysScanningDefault) && !HiveProxy.getOrDefault(settings, hideTutorialCards, defaultValue: hideTutorialCardsDefault)) ...[ ListTile( leading: const Icon(Icons.info), subtitle: Text(homeContinuousScanningOffDescription()), diff --git a/lib/Frontend/pages/intro.dart b/lib/Frontend/pages/intro.dart index fed2d969..5cef259f 100644 --- a/lib/Frontend/pages/intro.dart +++ b/lib/Frontend/pages/intro.dart @@ -5,13 +5,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:introduction_screen/introduction_screen.dart'; import 'package:logging/logging.dart'; -import 'package:logging_flutter/logging_flutter.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager_plus.dart'; import 'package:tail_app/Frontend/Widgets/lottie_lazy_load.dart'; import 'package:tail_app/Frontend/translation_string_definitions.dart'; import 'package:url_launcher/url_launcher.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../constants.dart'; import '../../gen/assets.gen.dart'; import '../../main.dart'; @@ -25,7 +24,7 @@ class OnBoardingPage extends ConsumerStatefulWidget { } class OnBoardingPageState extends ConsumerState { - Logger _introLogger = Logger("Onboarding"); + final Logger _introLogger = Logger("Onboarding"); final introKey = GlobalKey(); bool bluetoothAccepted = false; bool privacyAccepted = false; @@ -34,7 +33,7 @@ class OnBoardingPageState extends ConsumerState { // Navigator.of(context).pushReplacement() plausible.event(name: "Complete Onboarding"); _introLogger.info("Complete Onboarding"); - SentryHive.box(settings).put(hasCompletedOnboarding, hasCompletedOnboardingVersionToAgree); + HiveProxy.put(settings, hasCompletedOnboarding, hasCompletedOnboardingVersionToAgree); context.pushReplacement('/'); } @@ -89,7 +88,7 @@ class OnBoardingPageState extends ConsumerState { child: _buildImage(Assets.tCLogoTransparentNoText.path, 60), onLongPress: () { _introLogger.info("Open Logs"); - LogConsole.open(context); + context.push("/settings/developer/logs"); }, ), ), @@ -129,10 +128,10 @@ class OnBoardingPageState extends ConsumerState { ? null : () { setState(() { - _introLogger.info("Accepted Privact Policy"); + _introLogger.info("Accepted Privacy Policy"); privacyAccepted = true; - SentryHive.box(settings).put(allowErrorReporting, true); - SentryHive.box(settings).put(allowAnalytics, true); + HiveProxy.put(settings, allowErrorReporting, true); + HiveProxy.put(settings, allowAnalytics, true); introKey.currentState?.next(); }); }, diff --git a/lib/Frontend/pages/more.dart b/lib/Frontend/pages/more.dart index 0f1c70d4..7cae384a 100644 --- a/lib/Frontend/pages/more.dart +++ b/lib/Frontend/pages/more.dart @@ -9,11 +9,11 @@ import 'package:go_router/go_router.dart'; import 'package:package_info_plus/package_info_plus.dart'; 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/pages/markdown_viewer.dart'; import 'package:tail_app/Frontend/translation_string_definitions.dart'; import 'package:url_launcher/url_launcher.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../constants.dart'; import '../../gen/assets.gen.dart'; import '../utils.dart'; @@ -139,7 +139,7 @@ class _MoreState extends ConsumerState { await launchUrl(Uri.parse('https://github.com/Codel1417/tail_app')); }, onLongPress: () { - if (SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) { + if (HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault)) { return; } context.push('/settings/developer/pin'); diff --git a/lib/Frontend/pages/move_list.dart b/lib/Frontend/pages/move_list.dart index 7e01fd3a..2660bac4 100644 --- a/lib/Frontend/pages/move_list.dart +++ b/lib/Frontend/pages/move_list.dart @@ -4,7 +4,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart'; import 'package:tail_app/Backend/Definitions/Action/base_action.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; @@ -12,6 +11,7 @@ import 'package:tail_app/Backend/move_lists.dart'; import 'package:tail_app/Frontend/Widgets/speed_widget.dart'; import 'package:uuid/uuid.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../constants.dart'; import '../../main.dart'; import '../Widgets/device_type_widget.dart'; @@ -82,11 +82,11 @@ class _MoveListViewState extends ConsumerState { }, ), onTap: () async { - if (SentryHive.box(settings).get(haptics, defaultValue: hapticsDefault)) { + if (HiveProxy.getOrDefault(settings, haptics, defaultValue: hapticsDefault)) { HapticFeedback.selectionClick(); } for (BaseStatefulDevice element in ref.watch(knownDevicesProvider).values.where((element) => allMoveLists[index].deviceCategory.contains(element.baseDeviceDefinition.deviceType))) { - if (SentryHive.box(settings).get(kitsuneModeToggle, defaultValue: kitsuneModeDefault)) { + if (HiveProxy.getOrDefault(settings, kitsuneModeToggle, defaultValue: kitsuneModeDefault)) { await Future.delayed(Duration(milliseconds: Random().nextInt(kitsuneDelayRange))); } runAction(allMoveLists[index], element); diff --git a/lib/Frontend/pages/ota_update.dart b/lib/Frontend/pages/ota_update.dart index b4107968..90648386 100644 --- a/lib/Frontend/pages/ota_update.dart +++ b/lib/Frontend/pages/ota_update.dart @@ -11,12 +11,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:logging/logging.dart'; import 'package:pub_semver/pub_semver.dart'; 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/Bluetooth/bluetooth_manager_plus.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../Backend/firmware_update.dart'; import '../../constants.dart'; import '../../gen/assets.gen.dart'; @@ -81,7 +81,7 @@ class _OtaUpdateState extends ConsumerState { } baseStatefulDevice?.deviceState.value = DeviceState.standby; baseStatefulDevice!.fwVersion.removeListener(verListener); - if (!SentryHive.box(settings).get(alwaysScanning, defaultValue: alwaysScanningDefault)) { + if (!HiveProxy.getOrDefault(settings, alwaysScanning, defaultValue: alwaysScanningDefault)) { stopScan(); } timer?.cancel(); @@ -99,7 +99,7 @@ class _OtaUpdateState extends ConsumerState { mainAxisAlignment: MainAxisAlignment.center, children: [ if ([OtaState.standby, OtaState.manual].contains(otaState)) ...[ - if (SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) ...[ + if (HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault)) ...[ ListTile( title: const Text("Debug"), subtitle: Column( @@ -134,7 +134,7 @@ class _OtaUpdateState extends ConsumerState { otaDownloadButtonLabel(), ), ), - if (SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) ...[ + if (HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault)) ...[ ElevatedButton( onPressed: () async { FilePickerResult? result = await FilePicker.platform.pickFiles( @@ -228,7 +228,7 @@ class _OtaUpdateState extends ConsumerState { return LinearProgressIndicator(value: otaState == OtaState.rebooting ? null : progress); }), ), - if (SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) ...[ + if (HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault)) ...[ ListTile( subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/Frontend/pages/settings.dart b/lib/Frontend/pages/settings.dart index e9dbae2e..61447ccf 100644 --- a/lib/Frontend/pages/settings.dart +++ b/lib/Frontend/pages/settings.dart @@ -2,11 +2,11 @@ import 'package:flex_color_picker/flex_color_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; -import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; import '../../Backend/Definitions/Device/device_definition.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../constants.dart'; import '../../main.dart'; import '../translation_string_definitions.dart'; @@ -25,7 +25,7 @@ class _SettingsState extends ConsumerState { @override void initState() { super.initState(); - appColorValue = Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault)); + appColorValue = Color(HiveProxy.getOrDefault(settings, appColor, defaultValue: appColorDefault)); } @override @@ -46,7 +46,7 @@ class _SettingsState extends ConsumerState { width: 44, height: 44, borderRadius: 22, - color: Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault)), + color: Color(HiveProxy.getOrDefault(settings, appColor, defaultValue: appColorDefault)), ), onTap: () { plausible.event(page: "Settings/App Color"); @@ -63,7 +63,7 @@ class _SettingsState extends ConsumerState { actions: [ TextButton( onPressed: () { - SentryHive.box(settings).put(appColor, appColorValue.value); + HiveProxy.put(settings, appColor, appColorValue.value); Navigator.of(context).pop(); }, child: Text( @@ -72,7 +72,7 @@ class _SettingsState extends ConsumerState { ), TextButton( onPressed: () { - appColorValue = Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault)); + appColorValue = Color(HiveProxy.getOrDefault(settings, appColor, defaultValue: appColorDefault)); Navigator.of(context).pop(); }, child: Text( @@ -104,11 +104,11 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.battery_unknown), subtitle: Text(settingsBatteryPercentageToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(showAccurateBattery, defaultValue: showAccurateBatteryDefault), + value: HiveProxy.getOrDefault(settings, showAccurateBattery, defaultValue: showAccurateBatteryDefault), onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(showAccurateBattery, value); + HiveProxy.put(settings, showAccurateBattery, value); }, ); }, @@ -119,11 +119,11 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.format_size), subtitle: Text(settingsLargerCardsToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(largerActionCardSize, defaultValue: largerActionCardSizeDefault), + value: HiveProxy.getOrDefault(settings, largerActionCardSize, defaultValue: largerActionCardSizeDefault), onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(largerActionCardSize, value); + HiveProxy.put(settings, largerActionCardSize, value); }, ); }, @@ -134,11 +134,11 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.help), subtitle: Text(settingsTutorialCardToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(hideTutorialCards, defaultValue: hideTutorialCardsDefault), + value: HiveProxy.getOrDefault(settings, hideTutorialCards, defaultValue: hideTutorialCardsDefault), onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(hideTutorialCards, value); + HiveProxy.put(settings, hideTutorialCards, value); }, ); }, @@ -152,10 +152,10 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.bluetooth_searching), subtitle: Text(settingsAlwaysScanningToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(alwaysScanning, defaultValue: alwaysScanningDefault), + value: HiveProxy.getOrDefault(settings, alwaysScanning, defaultValue: alwaysScanningDefault), onChanged: (bool value) { setState(() { - SentryHive.box(settings).put(alwaysScanning, value); + HiveProxy.put(settings, alwaysScanning, value); }); }, ), @@ -165,10 +165,10 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.vibration), subtitle: Text(settingsHapticsToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(haptics, defaultValue: hapticsDefault), + value: HiveProxy.getOrDefault(settings, haptics, defaultValue: hapticsDefault), onChanged: (bool value) { setState(() { - SentryHive.box(settings).put(haptics, value); + HiveProxy.put(settings, haptics, value); }); }, ), @@ -178,10 +178,10 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.phone_android), subtitle: Text(settingsKeepScreenOnToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(keepAwake, defaultValue: keepAwakeDefault), + value: HiveProxy.getOrDefault(settings, keepAwake, defaultValue: keepAwakeDefault), onChanged: (bool value) { setState(() { - SentryHive.box(settings).put(keepAwake, value); + HiveProxy.put(settings, keepAwake, value); if (ref.read(knownDevicesProvider).values.where((element) => element.deviceConnectionState.value == ConnectivityState.connected).isNotEmpty) { if (value) { WakelockPlus.enable(); @@ -198,11 +198,11 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.more_time), subtitle: Text(settingsKitsuneToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(kitsuneModeToggle, defaultValue: kitsuneModeDefault), + value: HiveProxy.getOrDefault(settings, kitsuneModeToggle, defaultValue: kitsuneModeDefault), onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(kitsuneModeToggle, value); + HiveProxy.put(settings, kitsuneModeToggle, value); }, ); }, @@ -213,11 +213,11 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.explore), subtitle: Text(scanDemoGearTip()), trailing: Switch( - value: SentryHive.box(settings).get(showDemoGear, defaultValue: showDemoGearDefault), + value: HiveProxy.getOrDefault(settings, showDemoGear, defaultValue: showDemoGearDefault), onChanged: (bool value) { setState( () { - SentryHive.box(settings).put(showDemoGear, value); + HiveProxy.put(settings, showDemoGear, value); }, ); }, @@ -231,10 +231,10 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.notifications), subtitle: Text(settingsNewsletterToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(allowNewsletterNotifications, defaultValue: allowNewsletterNotificationsDefault), + value: HiveProxy.getOrDefault(settings, allowNewsletterNotifications, defaultValue: allowNewsletterNotificationsDefault), onChanged: (bool value) { setState(() { - SentryHive.box(settings).put(allowNewsletterNotifications, value); + HiveProxy.put(settings, allowNewsletterNotifications, value); }); }, ), @@ -247,10 +247,10 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.analytics), subtitle: Text(settingsAnalyticsToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(allowAnalytics, defaultValue: allowAnalyticsDefault), + value: HiveProxy.getOrDefault(settings, allowAnalytics, defaultValue: allowAnalyticsDefault), onChanged: (bool value) { setState(() { - SentryHive.box(settings).put(allowAnalytics, value); + HiveProxy.put(settings, allowAnalytics, value); }); }, ), @@ -261,15 +261,15 @@ class _SettingsState extends ConsumerState { leading: const Icon(Icons.error), subtitle: Text(settingsErrorReportingToggleSubTitle()), trailing: Switch( - value: SentryHive.box(settings).get(allowErrorReporting, defaultValue: allowErrorReportingDefault), + value: HiveProxy.getOrDefault(settings, allowErrorReporting, defaultValue: allowErrorReportingDefault), onChanged: (bool value) { setState(() { - SentryHive.box(settings).put(allowErrorReporting, value); + HiveProxy.put(settings, allowErrorReporting, value); }); }, ), ), - if (SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) ...[ + if (HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault)) ...[ ListTile( title: const Text("Development Menu"), leading: const Icon(Icons.bug_report), diff --git a/lib/Frontend/pages/shell.dart b/lib/Frontend/pages/shell.dart index b7ea83b8..8149b0d1 100644 --- a/lib/Frontend/pages/shell.dart +++ b/lib/Frontend/pages/shell.dart @@ -18,6 +18,7 @@ import 'package:tail_app/Frontend/Widgets/known_gear_scan_controller.dart'; import 'package:tail_app/Frontend/Widgets/snack_bar_overlay.dart'; import 'package:upgrader/upgrader.dart'; +import '../../Backend/LoggingWrappers.dart'; import '../../constants.dart'; import '../../main.dart'; import '../Widgets/base_card.dart'; @@ -75,8 +76,8 @@ class _NavigationDrawerExampleState extends ConsumerState { ); }, ), - if (widget.device.hasUpdate.value || SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) ...[ + if (widget.device.hasUpdate.value || HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault)) ...[ Padding( padding: const EdgeInsets.all(16.0), child: FilledButton( @@ -353,7 +354,7 @@ class _ManageGearState extends ConsumerState { ).whenComplete(() => setState(() {})); }, ), - if (SentryHive.box(settings).get(showDebugging, defaultValue: showDebuggingDefault)) ...[ + if (HiveProxy.getOrDefault(settings, showDebugging, defaultValue: showDebuggingDefault)) ...[ const ListTile( title: Divider(), ), diff --git a/lib/Frontend/utils.dart b/lib/Frontend/utils.dart index 19205822..01b30877 100644 --- a/lib/Frontend/utils.dart +++ b/lib/Frontend/utils.dart @@ -1,6 +1,7 @@ import 'package:cross_platform/cross_platform.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:dio/dio.dart'; +import 'package:logarte/logarte.dart'; import 'package:logging/logging.dart'; import 'package:native_dio_adapter/native_dio_adapter.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -8,6 +9,8 @@ import 'package:pub_semver/pub_semver.dart'; import 'package:sentry_dio/sentry_dio.dart'; import 'package:wordpress_client/wordpress_client.dart'; +import '../Backend/LoggingWrappers.dart'; + Future getBluetoothPermission(Logger logger) async { bool granted = false; if (Platform.isAndroid && (await DeviceInfoPlugin().androidInfo).version.sdkInt > 30) { @@ -40,7 +43,7 @@ Dio initDio({skipSentry = false}) { /// 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.interceptors.add( + /*dio.interceptors.add( LogInterceptor( requestBody: false, requestHeader: false, @@ -49,7 +52,8 @@ Dio initDio({skipSentry = false}) { request: false, logPrint: (o) => dioLogger.finer(o.toString()), ), - ); + );*/ + dio.interceptors.add(LogarteDioInterceptor(logarte)); if (!skipSentry) { dio.addSentry(failedRequestStatusCodes: []); } diff --git a/lib/main.dart b/lib/main.dart index a50a7718..3ff01098 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,7 +13,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hive_flutter/adapters.dart'; import 'package:intl/intl.dart'; 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_flutter/sentry_flutter.dart'; @@ -25,6 +24,7 @@ import 'package:tail_app/Backend/wear_bridge.dart'; import 'package:tail_app/Frontend/Widgets/bt_app_state_controller.dart'; import 'Backend/Definitions/Action/base_action.dart'; +import 'Backend/LoggingWrappers.dart'; import 'Backend/app_shortcuts.dart'; import 'Backend/audio.dart'; import 'Backend/background_update.dart'; @@ -40,7 +40,7 @@ import 'l10n/messages_all_locales.dart'; //late SharedPreferences prefs; FutureOr beforeSend(SentryEvent event, Hint hint) async { - bool reportingEnabled = SentryHive.box(settings).get("allowErrorReporting", defaultValue: true); + bool reportingEnabled = HiveProxy.getOrDefault(settings, "allowErrorReporting", defaultValue: true); if (reportingEnabled) { if (kDebugMode) { print('Before sending sentry event'); @@ -60,7 +60,13 @@ final mainLogger = Logger('Main'); Future main() async { Logger.root.level = Level.ALL; mainLogger.info("Begin"); - initFlogger(); + Logger.root.onRecord.listen((event) { + if (event.level.value < 1000) { + logarte.info("[${event.loggerName}] ${event.message}"); + } else { + logarte.error(event.message, stackTrace: event.stackTrace); + } + }); initFlutter(); initNotifications(); initBackgroundTasks(); @@ -97,16 +103,6 @@ Future main() async { ); } -void initFlogger() { - Flogger.init(config: const FloggerConfig(showDebugLogs: true, printClassName: true, printMethodName: true, showDateTime: false)); - Flogger.registerListener( - (record) { - LogConsole.add(OutputEvent(record.level, [record.printable()]), bufferSize: 1000); - //log(record.printable(), stackTrace: record.stackTrace); - }, - ); -} - void initFlutter() { WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); widgetsBinding.addObserver(WidgetBindingLogger()); @@ -177,10 +173,10 @@ class TailApp extends StatefulWidget { mainLogger.info('Starting app'); if (kDebugMode) { mainLogger.info('Debug Mode Enabled'); - SentryHive.box(settings).put(showDebugging, true); - SentryHive.box(settings).put(allowAnalytics, false); - SentryHive.box(settings).put(allowErrorReporting, false); - SentryHive.box(settings).put(hasCompletedOnboarding, hasCompletedOnboardingVersionToAgree); + HiveProxy.put(settings, showDebugging, true); + HiveProxy.put(settings, allowAnalytics, false); + HiveProxy.put(settings, allowErrorReporting, false); + HiveProxy.put(settings, hasCompletedOnboarding, hasCompletedOnboardingVersionToAgree); } } @@ -224,9 +220,9 @@ class _TailAppState extends State { Future(() => FlutterNativeSplash.remove()); //remove the splash screen one frame later return MaterialApp.router( title: title(), - color: Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault)), - theme: buildTheme(Brightness.light, Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault))), - darkTheme: buildTheme(Brightness.dark, Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault))), + color: Color(HiveProxy.getOrDefault(settings, appColor, defaultValue: appColorDefault)), + theme: buildTheme(Brightness.light, Color(HiveProxy.getOrDefault(settings, appColor, defaultValue: appColorDefault))), + darkTheme: buildTheme(Brightness.dark, Color(HiveProxy.getOrDefault(settings, appColor, defaultValue: appColorDefault))), routerConfig: router, localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, diff --git a/pubspec.lock b/pubspec.lock index 6af71497..638bc5ee 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -496,10 +496,10 @@ packages: dependency: "direct main" description: name: flutter_adaptive_scaffold - sha256: "9a1d5e9f728815e27b7b612883db19107ba8a35a46a97c757ea00896cb027451" + sha256: "794791e6fc0cc23e375d07ea987e76cf7f0eb7cd753532e45dc35b7e90575e2d" url: "https://pub.dev" source: hosted - version: "0.1.10+2" + version: "0.1.11" flutter_android_volume_keydown: dependency: "direct main" description: @@ -913,6 +913,15 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" + logarte: + dependency: "direct main" + description: + path: "." + ref: HEAD + resolved-ref: "7d0c93843971b6498caa65337f00e22ec4ffe944" + url: "https://github.com/Codel1417/logarte" + source: git + version: "0.1.6" logging: dependency: "direct main" description: @@ -921,14 +930,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" - logging_flutter: - dependency: "direct main" - description: - name: logging_flutter - sha256: "8b418504617a55de0d3e0582b25365894fe8a8936b934953caeddb13db4a190b" - url: "https://pub.dev" - source: hosted - version: "3.0.0" lottie_native: dependency: "direct main" description: @@ -1498,7 +1499,7 @@ packages: source: hosted version: "7.0.0" stack_trace: - dependency: transitive + dependency: "direct main" description: name: stack_trace sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" diff --git a/pubspec.yaml b/pubspec.yaml index ffa0a97f..897a8de2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,7 +27,10 @@ dependencies: circular_buffer: ^0.11.0 # Used for serial console wordpress_client: ^8.4.10 # Used for tail blog pub_semver: ^2.1.4 # used for comparing firmware versions - + logarte: + git: + url: https://github.com/Codel1417/logarte + stack_trace: ^1.11.1 # Platform Interfaces device_info_plus: ^10.1.0 @@ -69,7 +72,6 @@ dependencies: flutter_joystick: ^0.0.4 multi_value_listenable_builder: ^0.0.2 multi_listenable_builder: ^1.0.0 - logging_flutter: ^3.0.0 flutter_markdown: ^0.7.1 #video_player: ^2.8.6 fading_edge_scrollview: ^4.1.1 # used for known gear bar