Add await and logs
This commit is contained in:
parent
020e265b56
commit
ac91613d77
4 changed files with 16 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ import 'dart:developer' as developer;
|
|||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
||||
import 'package:traccar_client/location_cache.dart';
|
||||
import 'package:traccar_client/preferences.dart';
|
||||
|
|
@ -14,6 +15,7 @@ class GeolocationService {
|
|||
if (Platform.isAndroid) {
|
||||
await bg.BackgroundGeolocation.registerHeadlessTask(headlessTask);
|
||||
}
|
||||
FirebaseCrashlytics.instance.log('geolocation_init');
|
||||
bg.BackgroundGeolocation.onEnabledChange(onEnabledChange);
|
||||
bg.BackgroundGeolocation.onMotionChange(onMotionChange);
|
||||
bg.BackgroundGeolocation.onHeartbeat(onHeartbeat);
|
||||
|
|
@ -23,6 +25,7 @@ class GeolocationService {
|
|||
}
|
||||
|
||||
static Future<void> onEnabledChange(bool enabled) async {
|
||||
FirebaseCrashlytics.instance.log('geolocation_enabled:$enabled');
|
||||
if (Preferences.instance.getBool(Preferences.wakelock) ?? false) {
|
||||
if (!enabled) {
|
||||
await WakelockPartialAndroid.release();
|
||||
|
|
@ -31,6 +34,7 @@ class GeolocationService {
|
|||
}
|
||||
|
||||
static Future<void> onMotionChange(bg.Location location) async {
|
||||
FirebaseCrashlytics.instance.log('geolocation_motion:${location.isMoving}');
|
||||
if (Preferences.instance.getBool(Preferences.wakelock) ?? false) {
|
||||
if (location.isMoving) {
|
||||
await WakelockPartialAndroid.acquire();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:traccar_client/main.dart';
|
||||
import 'package:traccar_client/password_service.dart';
|
||||
import 'package:traccar_client/preferences.dart';
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
||||
|
||||
import 'l10n/app_localizations.dart';
|
||||
|
|
@ -98,6 +99,7 @@ class _MainScreenState extends State<MainScreen> {
|
|||
if (await PasswordService.authenticate(context) && mounted) {
|
||||
if (value) {
|
||||
try {
|
||||
FirebaseCrashlytics.instance.log('tracking_toggle_start');
|
||||
await bg.BackgroundGeolocation.start();
|
||||
if (mounted) {
|
||||
_checkBatteryOptimizations(context);
|
||||
|
|
@ -106,6 +108,7 @@ class _MainScreenState extends State<MainScreen> {
|
|||
messengerKey.currentState?.showSnackBar(SnackBar(content: Text(error.message ?? error.code)));
|
||||
}
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.log('tracking_toggle_stop');
|
||||
bg.BackgroundGeolocation.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:developer' as developer;
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
||||
import 'package:traccar_client/password_service.dart';
|
||||
|
|
@ -26,6 +27,7 @@ class PushService {
|
|||
|
||||
static Future<void> _onMessage(RemoteMessage message) async {
|
||||
final command = message.data['command'];
|
||||
FirebaseCrashlytics.instance.log('push_command: $command');
|
||||
switch (command) {
|
||||
case 'positionSingle':
|
||||
try {
|
||||
|
|
@ -61,5 +63,7 @@ class PushService {
|
|||
@pragma('vm:entry-point')
|
||||
Future<void> pushServiceBackgroundHandler(RemoteMessage message) async {
|
||||
await Preferences.init();
|
||||
await bg.BackgroundGeolocation.ready(Preferences.geolocationConfig());
|
||||
FirebaseCrashlytics.instance.log('push_background_handler');
|
||||
await PushService._onMessage(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:quick_actions/quick_actions.dart';
|
||||
|
|
@ -21,11 +22,12 @@ class _QuickActionsInitializerState extends State<QuickActionsInitializer> {
|
|||
void initState() {
|
||||
super.initState();
|
||||
quickActions.initialize((shortcutType) async {
|
||||
FirebaseCrashlytics.instance.log('quick_action: $shortcutType');
|
||||
switch (shortcutType) {
|
||||
case 'start':
|
||||
bg.BackgroundGeolocation.start();
|
||||
await bg.BackgroundGeolocation.start();
|
||||
case 'stop':
|
||||
bg.BackgroundGeolocation.stop();
|
||||
await bg.BackgroundGeolocation.stop();
|
||||
case 'sos':
|
||||
try {
|
||||
await bg.BackgroundGeolocation.getCurrentPosition(samples: 1, persist: true, extras: {'alarm': 'sos'});
|
||||
|
|
@ -34,6 +36,7 @@ class _QuickActionsInitializerState extends State<QuickActionsInitializer> {
|
|||
}
|
||||
}
|
||||
if (mounted) {
|
||||
FirebaseCrashlytics.instance.log('quick_action_exit');
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue