104 lines
2.7 KiB
Dart
104 lines
2.7 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
import 'updater_service.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await windowManager.ensureInitialized();
|
|
|
|
const windowOptions = WindowOptions(
|
|
size: Size(420, 320),
|
|
center: true,
|
|
backgroundColor: Color(0xFF121212),
|
|
skipTaskbar: false,
|
|
titleBarStyle: TitleBarStyle.hidden,
|
|
title: 'SOMA PRO',
|
|
);
|
|
|
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
|
await windowManager.show();
|
|
await windowManager.focus();
|
|
});
|
|
|
|
runApp(const UpdaterApp());
|
|
}
|
|
|
|
class UpdaterApp extends StatelessWidget {
|
|
const UpdaterApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData.dark(useMaterial3: true).copyWith(
|
|
scaffoldBackgroundColor: const Color(0xFF121212),
|
|
),
|
|
home: const SplashScreen(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class SplashScreen extends StatefulWidget {
|
|
const SplashScreen({super.key});
|
|
|
|
@override
|
|
State<SplashScreen> createState() => _SplashScreenState();
|
|
}
|
|
|
|
class _SplashScreenState extends State<SplashScreen> {
|
|
String _status = 'Chequeando actualizaciones...';
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_run();
|
|
}
|
|
|
|
Future<void> _run() async {
|
|
try {
|
|
await UpdaterService.checkAndUpdate(
|
|
onStatus: (status) {
|
|
if (mounted) setState(() => _status = status);
|
|
},
|
|
);
|
|
} catch (_) {
|
|
if (mounted) {
|
|
setState(() => _status = 'Sin conexión, abriendo SOMA PRO...');
|
|
}
|
|
}
|
|
await UpdaterService.launchApp();
|
|
// Si este proceso muere apenas después de lanzar la app, macOS a veces no
|
|
// llega a terminar de transferirle el foco: la ventana queda "ocluida"
|
|
// para el engine de Flutter y nunca dispara el primer frame (pantalla
|
|
// negra permanente, sin ningún error). Dar un respiro antes de salir le
|
|
// da tiempo al sistema a completar la activación.
|
|
await Future.delayed(const Duration(milliseconds: 600));
|
|
exit(0);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Image.asset('assets/logo.png', width: 220),
|
|
const SizedBox(height: 32),
|
|
const SizedBox(
|
|
width: 28,
|
|
height: 28,
|
|
child: CircularProgressIndicator(strokeWidth: 3),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(_status, style: const TextStyle(color: Colors.white70)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|