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