monorepo/dialer/lib/main_old.dart
AlexisDanlos 664dd4bb38
All checks were successful
/ mirror (push) Successful in 5s
/ build-stealth (push) Successful in 8m55s
/ build (push) Successful in 8m58s
WIP: app rework
2025-03-26 22:27:02 +01:00

85 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'services/call_service.dart';
import 'services/cryptography/asymmetric_crypto_service.dart';
import 'globals.dart' as globals;
import 'presentation/features/home/home_page.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Check for stealth mode
const stealthFlag = String.fromEnvironment('STEALTH', defaultValue: 'false');
globals.isStealthMode = stealthFlag.toLowerCase() == 'true';
// Initialize cryptography service with error handling
final AsymmetricCryptoService cryptoService = AsymmetricCryptoService();
try {
await cryptoService.initializeDefaultKeyPair();
} catch (e) {
debugPrint('Error initializing cryptography: $e');
// Continue app initialization even if crypto fails
}
// Request permissions before running the app
await _requestPermissions();
// Initialize call service
CallService();
runApp(
MultiProvider(
providers: [
Provider<AsymmetricCryptoService>(
create: (_) => cryptoService,
),
],
child: const DialerApp(),
),
);
}
Future<void> _requestPermissions() async {
try {
Map<Permission, PermissionStatus> statuses = await [
Permission.phone,
Permission.contacts,
Permission.microphone,
].request();
if (statuses.values.every((status) => status.isGranted)) {
debugPrint("All required permissions granted");
const channel = MethodChannel('call_service');
await channel.invokeMethod('permissionsGranted');
} else {
debugPrint("Permissions denied: ${statuses.entries.where((e) => !e.value.isGranted).map((e) => e.key).join(', ')}");
}
} catch (e) {
debugPrint("Error requesting permissions: $e");
}
}
class DialerApp extends StatelessWidget {
const DialerApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Dialer App',
navigatorKey: CallService.navigatorKey,
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: Colors.black,
primaryColor: Colors.blue,
appBarTheme: const AppBarTheme(
backgroundColor: Colors.black,
elevation: 0,
),
),
home: const MyHomePage(),
);
}
}