mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 01:12:12 +00:00
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
43 lines
1.1 KiB
Dart
43 lines
1.1 KiB
Dart
import 'dart:io';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:twonly/src/utils/log.dart';
|
|
|
|
class StartupGuard {
|
|
static Future<File> _getLockFile() async {
|
|
final path = (await getApplicationCacheDirectory()).path;
|
|
return File('$path/app_startup.lock');
|
|
}
|
|
|
|
static Future<void> markAppStartup() async {
|
|
try {
|
|
final file = await _getLockFile();
|
|
await file.writeAsString(
|
|
DateTime.now().millisecondsSinceEpoch.toString(),
|
|
);
|
|
Log.info('App is starting');
|
|
} catch (e) {
|
|
Log.error('Failed to mark app startup: $e');
|
|
}
|
|
}
|
|
|
|
static Future<bool> isAppStarting() async {
|
|
try {
|
|
final file = await _getLockFile();
|
|
if (!file.existsSync()) return false;
|
|
|
|
final stat = file.statSync();
|
|
final diff = DateTime.now().difference(stat.modified);
|
|
|
|
final starting = diff.inSeconds < 30;
|
|
if (starting) {
|
|
Log.info(
|
|
'Startup guard: App is currently starting (${diff.inSeconds}s ago).',
|
|
);
|
|
}
|
|
return starting;
|
|
} catch (e) {
|
|
Log.error('Failed to check startup guard: $e');
|
|
return false;
|
|
}
|
|
}
|
|
}
|