Skip to content

Commit

Permalink
hotfix: proper error handling in plausible provider (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes authored Mar 5, 2024
2 parents 5365aab + 1cc7990 commit 396156c
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions uni/lib/model/providers/plausible/plausible_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import 'dart:async';

import 'package:battery_plus/battery_plus.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:logger/logger.dart';
import 'package:plausible_analytics/plausible_analytics.dart';
import 'package:provider/provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:uni/controller/local_storage/preferences_controller.dart';

class PlausibleProvider extends StatefulWidget {
Expand Down Expand Up @@ -38,10 +40,19 @@ class _PlausibleProviderState extends State<PlausibleProvider> {
if (plausible != null) {
plausible.enabled = false;

_startListeners(plausible)
.then((_) => _updateBatteryState())
.then((_) => _updateConnectivityState())
.then((_) => _updateUsageStatsState());
unawaited(
_startListeners(plausible)
.then((_) => _updateBatteryState())
.then((_) => _updateConnectivityState())
.then((_) => _updateUsageStatsState())
.onError((error, stackTrace) {
unawaited(Sentry.captureException(error, stackTrace: stackTrace));
Logger().e(
'Error initializing plausible: $error',
stackTrace: stackTrace,
);
}),
);
}
}

Expand All @@ -67,7 +78,12 @@ class _PlausibleProviderState extends State<PlausibleProvider> {

final battery = Battery();
_batteryLevel = await battery.batteryLevel;
_isInBatterySaveMode = await battery.isInBatterySaveMode;

try {
_isInBatterySaveMode = await battery.isInBatterySaveMode;
} on PlatformException catch (_) {
_isInBatterySaveMode = false;
}

_updateAnalyticsState();
}
Expand Down

0 comments on commit 396156c

Please sign in to comment.