forked from firka/firka
add option to tick the debug timer
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
DateTime? fakeTime;
|
||||
Duration? offset;
|
||||
var tick = false;
|
||||
|
||||
DateTime timeNow() {
|
||||
if (fakeTime != null) {
|
||||
return fakeTime!;
|
||||
if (tick && offset != null) {
|
||||
return fakeTime!.add(offset!);
|
||||
} else {
|
||||
return fakeTime!;
|
||||
}
|
||||
} else {
|
||||
return DateTime.now();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import '../l10n/app_localizations.dart';
|
||||
import 'api/model/timetable.dart';
|
||||
import 'debug_helper.dart';
|
||||
|
||||
extension IterableExtension on Iterable<MapEntry<String, dynamic>> {
|
||||
extension IterableExtensionMap on Iterable<MapEntry<String, dynamic>> {
|
||||
Map<String, dynamic> toMap() {
|
||||
var map = <String, dynamic>{};
|
||||
for (var item in this) {
|
||||
@@ -16,6 +16,15 @@ extension IterableExtension on Iterable<MapEntry<String, dynamic>> {
|
||||
}
|
||||
}
|
||||
|
||||
extension IterableExtension<T> on Iterable<T> {
|
||||
T? firstWhereOrNull(bool Function(T element) test) {
|
||||
for (var element in this) {
|
||||
if (test(element)) return element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
extension DurationExtension on Duration {
|
||||
String formatDuration() {
|
||||
String hours = inHours.toString().padLeft(2, '0');
|
||||
@@ -166,4 +175,4 @@ extension LessonExtension on Lesson {
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:firka/helpers/db/models/app_settings_model.dart';
|
||||
import 'package:firka/helpers/db/models/generic_cache_model.dart';
|
||||
import 'package:firka/helpers/db/models/timetable_cache_model.dart';
|
||||
import 'package:firka/helpers/db/models/token_model.dart';
|
||||
import 'package:firka/helpers/debug_helper.dart';
|
||||
import 'package:firka/helpers/extensions.dart';
|
||||
import 'package:firka/ui/phone/pages/error/error_page.dart';
|
||||
import 'package:firka/ui/phone/screens/debug/debug_screen.dart';
|
||||
@@ -88,6 +89,13 @@ Future<AppInitialization> initializeApp() async {
|
||||
|
||||
if (kDebugMode) {
|
||||
print('Token count: $tokenCount');
|
||||
|
||||
// debug timer tick
|
||||
Timer.periodic(Duration(milliseconds: 100), (timer) {
|
||||
offset ??= Duration(milliseconds: 0);
|
||||
|
||||
offset = Duration(milliseconds: offset!.inMilliseconds + 100);
|
||||
});
|
||||
}
|
||||
|
||||
if (await isar.appSettingsModels.count() != 0) {
|
||||
|
||||
@@ -77,6 +77,20 @@ class _DebugScreen extends State<DebugScreen> {
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Row(
|
||||
children: [
|
||||
Text('tick debug timer'),
|
||||
Switch(
|
||||
value: tick,
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
tick = value;
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
profilePicture,
|
||||
ElevatedButton(
|
||||
@@ -106,6 +120,8 @@ class _DebugScreen extends State<DebugScreen> {
|
||||
fakeTime = d
|
||||
.getMidnight()
|
||||
.add(Duration(hours: t.hour, minutes: t.minute));
|
||||
|
||||
offset = Duration(milliseconds: 0);
|
||||
}
|
||||
},
|
||||
child: const Text('Set fake time'),
|
||||
|
||||
Reference in New Issue
Block a user