Adds code for the callback for floating app window, and fixes Trip End time not being initialized.

This commit is contained in:
zontreck 2025-05-24 18:46:12 -07:00
parent 35863780f6
commit aedde74e77
5 changed files with 30 additions and 2 deletions

View file

@ -9,7 +9,7 @@ class TTConsts {
static get SESSION_SERVER =>
"https://api.zontreck.com/timetrack/$UPDATE_CHANNEL/timetrack.php";
static const VERSION = "1.0.0-beta.13";
static const VERSION = "1.0.0-beta.14";
static bool UPDATE_AVAILABLE = false;
static UpdateChannel UPDATE_CHANNEL = UpdateChannel.beta;

View file

@ -4,6 +4,7 @@ import 'dart:math' as math;
import 'dart:ui';
import 'package:dio/dio.dart';
import 'package:floating_window_android/floating_window_android.dart';
import 'package:flutter/material.dart';
import 'package:flutter_background/flutter_background.dart';
import 'package:geolocator/geolocator.dart';
@ -164,6 +165,13 @@ class SessionData {
return false;
}
bool granted = await FloatingWindowAndroid.isPermissionGranted();
if (!granted) {
success = await FloatingWindowAndroid.requestPermission();
if (!success) return false;
}
StartTime = DateTime.now();
IsOnTheClock = true;
@ -319,6 +327,9 @@ class SessionData {
}
static Trip GetNewTrip() {
if (currentTrip != null) {
currentTrip!.EndTime = DateTime.now();
}
currentTrip = Trip();
Trips.add(currentTrip!);
return currentTrip!;
@ -335,6 +346,9 @@ class SessionData {
}
static void EndTrip() {
if (currentTrip != null) {
currentTrip!.EndTime = DateTime.now();
}
currentDelivery = null;
currentTrip = null;
}

View file

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
@ -6,6 +7,16 @@ import 'package:timetrack/consts.dart';
import 'package:timetrack/data.dart';
import 'package:timetrack/pages/MainApp.dart';
@pragma("vm:entry-point")
void serviceEntry() {
// This is where both the Background service and the Floating app window would enter the app.
Timer.periodic(Duration(seconds: 5), (timer) async {
// Run the location fetch, add to list, etc, etc.
});
// Run the floater app here.
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();