Skip to content

Commit

Permalink
Add new log ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed May 31, 2024
1 parent 52f0c7d commit cb96c58
Show file tree
Hide file tree
Showing 30 changed files with 248 additions and 183 deletions.
9 changes: 4 additions & 5 deletions lib/Backend/Bluetooth/bluetooth_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,7 +15,7 @@ final log.Logger bluetoothLog = log.Logger('Bluetooth');
class KnownDevices extends _$KnownDevices {
@override
Map<String, BaseStatefulDevice> build() {
List<BaseStoredDevice> storedDevices = SentryHive.box<BaseStoredDevice>('devices').values.toList();
List<BaseStoredDevice> storedDevices = HiveProxy.getAll<BaseStoredDevice>('devices').toList();
Map<String, BaseStatefulDevice> results = {};
try {
if (storedDevices.isNotEmpty) {
Expand Down Expand Up @@ -50,8 +50,7 @@ class KnownDevices extends _$KnownDevices {
}

Future<void> store() async {
SentryHive.box<BaseStoredDevice>('devices')
..clear()
..addAll(state.values.map((e) => e.baseStoredDevice));
await HiveProxy.clear('devices');
await HiveProxy.addAll('devices', state.values.map((e) => e.baseStoredDevice));
}
}
14 changes: 7 additions & 7 deletions lib/Backend/Bluetooth/bluetooth_manager_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -96,7 +96,7 @@ Future<void> 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();
}
Expand Down Expand Up @@ -129,12 +129,12 @@ Future<void> 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}")));
Expand Down Expand Up @@ -215,7 +215,7 @@ Future<void> 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;
}
Expand Down
52 changes: 52 additions & 0 deletions lib/Backend/LoggingWrappers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:logarte/logarte.dart';
import 'package:sentry_hive/sentry_hive.dart';

import '../constants.dart';

_HiveProxyImpl HiveProxy = _HiveProxyImpl();
List<String> genericBoxes = [settings, notificationBox];

class _HiveProxyImpl {
Future<void> put<E>(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<E>(box).put(key, value);
}
}

E getOrDefault<E>(String box, dynamic key, {E? defaultValue}) {
if (genericBoxes.contains(box)) {
return SentryHive.box(box).get(key, defaultValue: defaultValue)!;
} else {
return SentryHive.box<E>(box).get(key, defaultValue: defaultValue)!;
}
}

Future<int> clear<E>(String box) {
if (genericBoxes.contains(box)) {
return SentryHive.box(box).clear();
} else {
return SentryHive.box<E>(box).clear();
}
}

Future<Iterable<int>> addAll<E>(String name, Iterable<E> values) {
return SentryHive.box<E>(name).addAll(values);
}

Iterable<E> getAll<E>(String name) {
return SentryHive.box<E>(name).values;
}
}

final Logarte logarte = Logarte(
// Whether to ignore the password
ignorePassword: true,
disableDebugConsoleLogs: true,
);
9 changes: 4 additions & 5 deletions lib/Backend/action_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -352,7 +352,7 @@ class FavoriteActions extends _$FavoriteActions {
List<FavoriteAction> build() {
List<FavoriteAction> results = [];
try {
results = SentryHive.box<FavoriteAction>(favoriteActionsBox).values.toList(growable: true);
results = HiveProxy.getAll<FavoriteAction>(favoriteActionsBox).toList(growable: true);
} catch (e, s) {
actionRegistryLogger.severe("Unable to load favorites: $e", e, s);
}
Expand All @@ -376,9 +376,8 @@ class FavoriteActions extends _$FavoriteActions {

Future<void> store() async {
actionRegistryLogger.info("Storing favorites");
SentryHive.box<FavoriteAction>(favoriteActionsBox)
..clear()
..addAll(state);
await HiveProxy.clear<FavoriteAction>(favoriteActionsBox);
await HiveProxy.addAll<FavoriteAction>(favoriteActionsBox, state);
updateShortcuts(state, ref);
updateWearActions(state, ref);
}
Expand Down
9 changes: 4 additions & 5 deletions lib/Backend/audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -44,7 +44,7 @@ class UserAudioActions extends _$UserAudioActions {
List<AudioAction> build() {
List<AudioAction> results = [];
try {
results = SentryHive.box<AudioAction>(audioActionsBox).values.toList(growable: true);
results = HiveProxy.getAll<AudioAction>(audioActionsBox).toList(growable: true);
} catch (e, s) {
_audioLogger.severe("Unable to load audio: $e", e, s);
}
Expand All @@ -68,8 +68,7 @@ class UserAudioActions extends _$UserAudioActions {

Future<void> store() async {
_audioLogger.info("Storing Custom Audio");
SentryHive.box<AudioAction>(audioActionsBox)
..clear()
..addAll(state);
await HiveProxy.clear<AudioAction>(audioActionsBox);
await HiveProxy.addAll<AudioAction>(audioActionsBox, state);
}
}
9 changes: 5 additions & 4 deletions lib/Backend/background_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> initBackgroundTasks() async {
Expand Down Expand Up @@ -51,7 +52,7 @@ Future<void> initBackgroundTasks() async {
}

Future<void> checkForNewPosts() async {
if (!SentryHive.box(settings).get(allowNewsletterNotifications, defaultValue: allowNewsletterNotificationsDefault)) {
if (!HiveProxy.getOrDefault(settings, allowNewsletterNotifications, defaultValue: allowNewsletterNotificationsDefault)) {
return;
}
_backgroundLogger.info("Checking for new posts");
Expand All @@ -70,10 +71,10 @@ Future<void> 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,
Expand Down
9 changes: 4 additions & 5 deletions lib/Backend/move_lists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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';
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';

Expand Down Expand Up @@ -162,7 +162,7 @@ class MoveLists extends _$MoveLists {
List<MoveList> build() {
List<MoveList> results = [];
try {
results = SentryHive.box<MoveList>('sequences').values.toList(growable: true);
results = HiveProxy.getAll<MoveList>('sequences').toList(growable: true);
} catch (e, s) {
sequencesLogger.severe("Unable to load sequences: $e", e, s);
}
Expand All @@ -183,9 +183,8 @@ class MoveLists extends _$MoveLists {

Future<void> store() async {
sequencesLogger.info("Storing sequences");
SentryHive.box<MoveList>('sequences')
..clear()
..addAll(state);
HiveProxy.clear<MoveList>('sequences');
HiveProxy.addAll<MoveList>('sequences', state);
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/Backend/plausible_dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,7 +25,7 @@ class PlausibleDio extends Plausible {
/// Post event to plausible
@override
Future<int> event({String name = "pageview", String referrer = "", String page = "", Map<String, String> 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');
Expand All @@ -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<BaseStoredDevice>('devices').length.toString();
props['Number Of Sequences'] = SentryHive.box<MoveList>('sequences').length.toString();
props['Number Of Triggers'] = SentryHive.box<Trigger>(triggerBox).length.toString();
props['Number Of Devices'] = HiveProxy.getAll<BaseStoredDevice>('devices').length.toString();
props['Number Of Sequences'] = HiveProxy.getAll<MoveList>('sequences').length.toString();
props['Number Of Triggers'] = HiveProxy.getAll<Trigger>(triggerBox).length.toString();
props['App Version'] = (await PackageInfo.fromPlatform()).version;
props['App Build'] = (await PackageInfo.fromPlatform()).buildNumber;

Expand Down
17 changes: 8 additions & 9 deletions lib/Backend/sensors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -247,7 +247,7 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
)
.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(baseAction, baseStatefulDevice);
Expand Down Expand Up @@ -710,7 +710,7 @@ class TriggerList extends _$TriggerList {
List<Trigger> build() {
List<Trigger> results = [];
try {
results = SentryHive.box<Trigger>(triggerBox).values.map((trigger) {
results = HiveProxy.getAll<Trigger>(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;
Expand All @@ -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<Trigger>(triggerBox)
..clear()
..addAll([trigger]);

HiveProxy.clear<Trigger>(triggerBox);
HiveProxy.addAll<Trigger>(triggerBox, [trigger]);
return [trigger];
}
return results;
Expand All @@ -745,9 +745,8 @@ class TriggerList extends _$TriggerList {

Future<void> store() async {
sensorsLogger.info("Storing triggers");
SentryHive.box<Trigger>(triggerBox)
..clear()
..addAll(state);
await HiveProxy.clear<Trigger>(triggerBox);
await HiveProxy.addAll<Trigger>(triggerBox, state);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Frontend/Widgets/bt_app_state_controller.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -31,7 +31,7 @@ class _BtAppStateControllerState extends ConsumerState<BtAppStateController> {
},
);
// 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);
}
}
Expand Down
Loading

0 comments on commit cb96c58

Please sign in to comment.