Harden app for 24-7 offline-first operation
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -11,7 +15,44 @@ import 'features/home/home_view.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
FlutterError.onError = (details) {
|
||||
FlutterError.presentError(details);
|
||||
debugPrint('[Fatal][FlutterError] ${details.exceptionAsString()}');
|
||||
};
|
||||
PlatformDispatcher.instance.onError = (error, stack) {
|
||||
debugPrint('[Fatal][PlatformDispatcher] $error');
|
||||
debugPrintStack(stackTrace: stack);
|
||||
return true;
|
||||
};
|
||||
ErrorWidget.builder = (details) {
|
||||
return const Material(
|
||||
color: SacredColors.background,
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(32),
|
||||
child: Text(
|
||||
'Terjadi gangguan tampilan.\nAplikasi tetap berjalan dalam mode aman.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: SacredColors.onSurface,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
await runZonedGuarded(() async {
|
||||
await _bootstrapAndRun();
|
||||
}, (error, stack) {
|
||||
debugPrint('[Fatal][Zone] $error');
|
||||
debugPrintStack(stackTrace: stack);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _bootstrapAndRun() async {
|
||||
// Landscape-only for TV
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
@@ -33,6 +74,7 @@ void main() async {
|
||||
if (settingsBox.get('default') == null) {
|
||||
await settingsBox.put('default', AppSettings());
|
||||
}
|
||||
await _sanitizeMediaSettings(settingsBox);
|
||||
|
||||
// Initialize date formatting for Indonesian locale
|
||||
await initializeDateFormatting('id_ID');
|
||||
@@ -47,6 +89,33 @@ void main() async {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _sanitizeMediaSettings(Box<AppSettings> settingsBox) async {
|
||||
final settings = settingsBox.get('default');
|
||||
if (settings == null) return;
|
||||
|
||||
final validSlides = settings.slideshowImages
|
||||
.where((path) => path.trim().isNotEmpty && File(path).existsSync())
|
||||
.toList();
|
||||
final brandedBg = (settings.brandedBgImage != null &&
|
||||
settings.brandedBgImage!.trim().isNotEmpty &&
|
||||
File(settings.brandedBgImage!).existsSync())
|
||||
? settings.brandedBgImage
|
||||
: null;
|
||||
|
||||
final needsSave =
|
||||
validSlides.length != settings.slideshowImages.length ||
|
||||
brandedBg != settings.brandedBgImage;
|
||||
if (!needsSave) return;
|
||||
|
||||
await settingsBox.put(
|
||||
'default',
|
||||
settings.copyWith(
|
||||
slideshowImages: validSlides,
|
||||
brandedBgImage: brandedBg,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class JamShalatApp extends ConsumerWidget {
|
||||
const JamShalatApp({super.key});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user