From aedde74e771f413662fbabed53420be61290d900 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 24 May 2025 18:46:12 -0700 Subject: [PATCH] Adds code for the callback for floating app window, and fixes Trip End time not being initialized. --- android/app/src/main/AndroidManifest.xml | 2 ++ lib/consts.dart | 2 +- lib/data.dart | 14 ++++++++++++++ lib/main.dart | 11 +++++++++++ pubspec.yaml | 3 ++- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 335936d..94886ea 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -13,6 +13,8 @@ + + "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; diff --git a/lib/data.dart b/lib/data.dart index 724313f..6947538 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -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; } diff --git a/lib/main.dart b/lib/main.dart index 9e336ca..63248e7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 main() async { WidgetsFlutterBinding.ensureInitialized(); diff --git a/pubspec.yaml b/pubspec.yaml index 1768f47..9a7dbaa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0-beta.13 +version: 1.0.0-beta.14 environment: sdk: ^3.7.2 @@ -48,6 +48,7 @@ dependencies: flutter_map_tile_caching: ^10.1.1 url_launcher: ^6.3.1 flutter_background: ^1.3.0+1 + floating_window_android: ^1.0.0 dev_dependencies: flutter_test: