192 lines
6.0 KiB
Dart
192 lines
6.0 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../monitor/monitor2app.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
const String securityURL =
|
|
"https://ididit.bymycode.com/supercodeur/monitor2/isSoftwareActive_1.0.0.txt";
|
|
|
|
class KillSwitchHomePage extends StatefulWidget {
|
|
const KillSwitchHomePage({super.key});
|
|
|
|
@override
|
|
KillSwitchHomePageState createState() => KillSwitchHomePageState();
|
|
}
|
|
|
|
class KillSwitchHomePageState extends State<KillSwitchHomePage> {
|
|
String _message = "Vérification de l'état...";
|
|
bool _isLoading = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_checkStatus();
|
|
}
|
|
|
|
Future<void> _checkStatus() async {
|
|
setState(() {
|
|
_isLoading = true;
|
|
_message = "Vérification de l'état...";
|
|
});
|
|
|
|
try {
|
|
final response = await http.get(Uri.parse(securityURL));
|
|
|
|
if (!mounted) return;
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
final data = response.body;
|
|
if (data.contains('active: true')) {
|
|
setState(() {
|
|
_isLoading = false;
|
|
_message = "Application active, c'est parti...";
|
|
});
|
|
if (!mounted) return;
|
|
await Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => const Monitor2App()),
|
|
);
|
|
} else {
|
|
_updateMessage("L'application est désormais bloquée.");
|
|
}
|
|
} else if (response.statusCode >= 400 && response.statusCode < 500) {
|
|
_updateMessage("Veuillez mettre à jour l'application.");
|
|
} else {
|
|
_showNetworkError();
|
|
}
|
|
} catch (e) {
|
|
_showNetworkError();
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() {
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
void _showNetworkError() {
|
|
setState(() {
|
|
_message =
|
|
"Une connexion réseau est nécessaire pour accéder à l'application.";
|
|
_isLoading = false;
|
|
});
|
|
|
|
Timer(const Duration(seconds: 5), () {
|
|
setState(() {
|
|
_isLoading = true;
|
|
_checkStatus();
|
|
});
|
|
});
|
|
}
|
|
|
|
void _updateMessage(String message) {
|
|
setState(() {
|
|
_message = message;
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Initialisation')),
|
|
body: Center(
|
|
child:
|
|
_isLoading
|
|
? const CircularProgressIndicator()
|
|
: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
const Text(
|
|
'TourPet',
|
|
style: TextStyle(
|
|
fontSize: 30,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.teal,
|
|
),
|
|
),
|
|
Text(_message, textAlign: TextAlign.center),
|
|
const SizedBox(height: 20),
|
|
Image.asset(
|
|
'assets/icon.png',
|
|
width: MediaQuery.of(context).size.width * 0.25,
|
|
fit: BoxFit.contain,
|
|
),
|
|
const SizedBox(height: 20),
|
|
Text(
|
|
'Copyright (c) 2025 SuperCodeur',
|
|
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
|
),
|
|
const SizedBox(height: 10),
|
|
GestureDetector(
|
|
onTap:
|
|
() =>
|
|
_launchEmail('cgifl300+supercodeur@gmail.com'),
|
|
child: const Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text('✉️ ', style: TextStyle(fontSize: 18)),
|
|
Text(
|
|
'cgifl300+supercodeur@gmail.com',
|
|
style: TextStyle(
|
|
color: Colors.blue,
|
|
fontSize: 14,
|
|
decoration: TextDecoration.underline,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
GestureDetector(
|
|
onTap:
|
|
() => _launchUrl(
|
|
'https://ididit.bymycode.com/supercodeur/monitor2/',
|
|
),
|
|
child: const Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text('🌐 ', style: TextStyle(fontSize: 18)),
|
|
Text(
|
|
'Visiter le site du projet',
|
|
style: TextStyle(
|
|
color: Colors.blue,
|
|
fontSize: 14,
|
|
decoration: TextDecoration.underline,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _launchUrl(String url) async {
|
|
final Uri uri = Uri.parse(url);
|
|
if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
|
|
throw Exception('Could not launch $url');
|
|
}
|
|
}
|
|
|
|
void _launchEmail(String email) async {
|
|
final Uri emailUri = Uri(
|
|
scheme: 'mailto',
|
|
path: email,
|
|
queryParameters: {'subject': 'Hello', 'body': 'Test'},
|
|
);
|
|
if (await canLaunchUrl(emailUri)) {
|
|
await launchUrl(emailUri);
|
|
} else {
|
|
throw 'Could not launch email client';
|
|
}
|
|
}
|
|
}
|