Files

194 lines
5.7 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:media_kit/media_kit.dart';
import 'package:window_manager/window_manager.dart';
import 'screens/home_page.dart';
import 'screens/library_pages.dart';
import 'screens/search_page.dart';
import 'screens/settings_page.dart';
import 'screens/subscriptions_page.dart';
import 'services/app_settings_service.dart';
import 'services/background_playback_service.dart';
import 'services/google_auth_service.dart';
import 'services/library_service.dart';
import 'services/media_cache_settings_service.dart';
import 'theme/app_theme.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();
if (Platform.isWindows) {
await windowManager.ensureInitialized();
}
await BackgroundPlaybackService.instance.initialize();
await LibraryService.instance.initialize();
await AppSettingsService.instance.initialize();
await MediaCacheSettingsService.instance.ensureInitialized();
await GoogleAuthService.instance.initialize();
runApp(const YouTubePersonalApp());
}
class YouTubePersonalApp extends StatelessWidget {
const YouTubePersonalApp({super.key});
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<String>(
valueListenable: AppSettingsService.instance.appearanceMode,
builder: (context, appearanceMode, child) {
final hour = DateTime.now().hour;
final themeMode = switch (appearanceMode) {
'dark' => ThemeMode.dark,
'light' => ThemeMode.light,
'auto' => (hour >= 19 || hour < 7) ? ThemeMode.dark : ThemeMode.light,
_ => ThemeMode.light,
};
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'YouTube Personal',
theme: AppTheme.light,
darkTheme: AppTheme.dark,
themeMode: themeMode,
home: const MainScreen(),
);
},
);
}
}
class MainScreen extends StatefulWidget {
const MainScreen({super.key});
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
int selectedIndex = 0;
final pages = const [
HomePage(),
SearchPage(),
SubscriptionsPage(),
LibraryHubPage(),
SettingsPage(),
];
@override
Widget build(BuildContext context) {
final mediaSize = MediaQuery.sizeOf(context);
final width = mediaSize.width;
final shortestSide = mediaSize.shortestSide;
final desktop = width >= 1000 && shortestSide >= 700;
if (desktop) {
return Scaffold(
body: Row(
children: [
NavigationRail(
selectedIndex: selectedIndex,
onDestinationSelected: (index) {
setState(() {
selectedIndex = index;
});
},
labelType: NavigationRailLabelType.selected,
leading: const Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Icon(
Icons.play_circle_fill,
size: 42,
color: Color(0xFFFF4E45),
),
),
destinations: const [
NavigationRailDestination(
icon: Icon(Icons.home_outlined),
selectedIcon: Icon(Icons.home),
label: Text('Accueil'),
),
NavigationRailDestination(
icon: Icon(Icons.search),
label: Text('Recherche'),
),
NavigationRailDestination(
icon: Icon(Icons.subscriptions_outlined),
selectedIcon: Icon(Icons.subscriptions),
label: Text('Abonnements'),
),
NavigationRailDestination(
icon: Icon(Icons.video_library_outlined),
selectedIcon: Icon(Icons.video_library),
label: Text('Bibliothèque'),
),
NavigationRailDestination(
icon: Icon(Icons.settings_outlined),
selectedIcon: Icon(Icons.settings),
label: Text('Réglages'),
),
],
),
const VerticalDivider(width: 1),
Expanded(
child: IndexedStack(
index: selectedIndex,
children: pages,
),
),
],
),
);
}
return Scaffold(
body: IndexedStack(
index: selectedIndex,
children: pages,
),
bottomNavigationBar: NavigationBar(
height: 72,
labelBehavior:
NavigationDestinationLabelBehavior.alwaysShow,
selectedIndex: selectedIndex,
onDestinationSelected: (index) {
setState(() {
selectedIndex = index;
});
},
destinations: const [
NavigationDestination(
icon: Icon(Icons.home_outlined),
selectedIcon: Icon(Icons.home),
label: 'Accueil',
),
NavigationDestination(
icon: Icon(Icons.search),
label: 'Recherche',
),
NavigationDestination(
icon: Icon(Icons.subscriptions_outlined),
selectedIcon: Icon(Icons.subscriptions),
label: 'Abos',
),
NavigationDestination(
icon: Icon(Icons.video_library_outlined),
selectedIcon: Icon(Icons.video_library),
label: 'Bibliothèque',
),
NavigationDestination(
icon: Icon(Icons.settings_outlined),
selectedIcon: Icon(Icons.settings),
label: 'Réglages',
),
],
),
);
}
}