Fixed freezing on start up for some devices
This commit is contained in:
parent
b8ec5dbf69
commit
1e1c7d9552
|
|
@ -240,10 +240,20 @@ Future<void> main() async {
|
||||||
pdfrxFlutterInitialize(dismissPdfiumWasmWarnings: true);
|
pdfrxFlutterInitialize(dismissPdfiumWasmWarnings: true);
|
||||||
|
|
||||||
// initialize Firebase before anything that uses messaging
|
// initialize Firebase before anything that uses messaging
|
||||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
try {
|
||||||
|
await Firebase.initializeApp(
|
||||||
|
options: DefaultFirebaseOptions.currentPlatform,
|
||||||
|
).timeout(const Duration(seconds: 15));
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Firebase init failed or timed out: $e');
|
||||||
|
}
|
||||||
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
||||||
|
|
||||||
await dotenv.load(fileName: '.env');
|
try {
|
||||||
|
await dotenv.load(fileName: '.env').timeout(const Duration(seconds: 5));
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('dotenv load failed or timed out: $e');
|
||||||
|
}
|
||||||
|
|
||||||
AppTime.initialize(location: 'Asia/Manila');
|
AppTime.initialize(location: 'Asia/Manila');
|
||||||
|
|
||||||
|
|
@ -255,11 +265,26 @@ Future<void> main() async {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Supabase.initialize(url: supabaseUrl, anonKey: supabaseAnonKey);
|
try {
|
||||||
|
await Supabase.initialize(
|
||||||
|
url: supabaseUrl,
|
||||||
|
anonKey: supabaseAnonKey,
|
||||||
|
).timeout(const Duration(seconds: 20));
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Supabase init failed or timed out: $e');
|
||||||
|
runApp(const _MissingConfigApp());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize background location service (Workmanager)
|
// Initialize background location service (Workmanager)
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
await initBackgroundLocationService();
|
try {
|
||||||
|
await initBackgroundLocationService().timeout(
|
||||||
|
const Duration(seconds: 10),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Background location service init failed or timed out: $e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure token saved shortly after startup if already signed in.
|
// ensure token saved shortly after startup if already signed in.
|
||||||
|
|
@ -312,20 +337,38 @@ Future<void> main() async {
|
||||||
// on Android 13+ we must request POST_NOTIFICATIONS at runtime; without it
|
// on Android 13+ we must request POST_NOTIFICATIONS at runtime; without it
|
||||||
// notifications are automatically denied and cannot be re‑enabled from the
|
// notifications are automatically denied and cannot be re‑enabled from the
|
||||||
// system settings. The helper uses `permission_handler`.
|
// system settings. The helper uses `permission_handler`.
|
||||||
final granted = await ensureNotificationPermission();
|
try {
|
||||||
if (!granted) {
|
final granted = await ensureNotificationPermission().timeout(
|
||||||
// we don’t block startup, but it’s worth logging so developers notice.
|
const Duration(seconds: 10),
|
||||||
// debugPrint('notification permission not granted');
|
);
|
||||||
|
if (!granted) {
|
||||||
|
// we don't block startup, but it's worth logging so developers notice.
|
||||||
|
// debugPrint('notification permission not granted');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Notification permission request failed or timed out: $e');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request location permission at launch (same pattern as notification)
|
// Request location permission at launch (same pattern as notification)
|
||||||
final locationGranted = await ensureLocationPermission();
|
try {
|
||||||
if (!locationGranted) {
|
final locationGranted = await ensureLocationPermission().timeout(
|
||||||
// debugPrint('location permission not granted');
|
const Duration(seconds: 10),
|
||||||
|
);
|
||||||
|
if (!locationGranted) {
|
||||||
|
// debugPrint('location permission not granted');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Location permission request failed or timed out: $e');
|
||||||
}
|
}
|
||||||
|
|
||||||
// request FCM permission (iOS/Android13+) and handle foreground messages
|
// request FCM permission (iOS/Android13+) and handle foreground messages
|
||||||
await FirebaseMessaging.instance.requestPermission();
|
try {
|
||||||
|
await FirebaseMessaging.instance.requestPermission().timeout(
|
||||||
|
const Duration(seconds: 10),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('FCM permission request failed or timed out: $e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user