Initial commit

This commit is contained in:
gasaichandesu
2025-08-30 19:47:42 +04:00
commit 58d7808a8d
100 changed files with 6186 additions and 0 deletions
@@ -0,0 +1,114 @@
import 'dart:async';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:moonwell_launcher/app/home_screen/bloc/home_screen_model.dart';
import 'package:moonwell_launcher/features/downloader/application/download_manager.dart';
import 'package:moonwell_launcher/features/downloader/domain/entities/download_progress.dart';
import 'package:moonwell_launcher/features/downloader/domain/entities/download_request.dart';
import 'package:moonwell_launcher/features/preferences/domain/repositories/preferences_repository.dart';
import 'package:rxdart/rxdart.dart';
part 'home_screen_event.dart';
part 'home_screen_state.dart';
const _downloadId = 'client';
class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
final DownloadManager _downloadManager;
final PreferencesRepository _preferencesRepository;
StreamSubscription<DownloadProgress>? _downloadProgressSubscription;
HomeScreenBloc({
required DownloadManager downloadManager,
required PreferencesRepository preferencesRepository,
}) : _downloadManager = downloadManager,
_preferencesRepository = preferencesRepository,
super(HomeScreenInitialState(model: HomeScreenModel.initial())) {
_setupHandlers();
add(HomeScreenLoad());
}
void _setupHandlers() {
on<HomeScreenLoad>(_onHomeScreenLoad);
on<HomeScreenDownloadRequested>(_onHomeScreenDownloadRequested);
on<HomeScreenDownloadPaused>((event, emit) {
// _downloadManager.pauseDownload();
// emit(HomeScreenDownloadPausedState());
});
on<HomeScreenDownloadProgressUpdated>(
_onHomeScreenDownloadProgressUpdated,
transformer: (events, mapper) =>
events.throttleTime(const Duration(seconds: 2)).switchMap(mapper),
);
}
Future<void> _onHomeScreenLoad(
HomeScreenLoad event,
Emitter<HomeScreenState> emit,
) async {
final outputDir = await _preferencesRepository.getOutputDir();
emit(
HomeScreenReadyToDownloadState(
model: state.model.copyWith(outputPath: outputDir),
),
);
}
Future<void> _onHomeScreenDownloadRequested(
HomeScreenDownloadRequested event,
Emitter<HomeScreenState> emit,
) async {
if (state.model.outputPath == null) {
final directory = await FilePicker.platform.getDirectoryPath(
dialogTitle: 'Please select installation directory',
);
if (directory == null) {
return;
}
await _preferencesRepository.setOutputDir(Uri.directory(directory));
emit(
HomeScreenReadyToDownloadState(
model: state.model.copyWith(outputPath: Uri.directory(directory)),
),
);
}
_downloadProgressSubscription = _downloadManager
.start(
id: _downloadId,
request: DownloadRequest(
destinationPath: state.model.outputPath!.toFilePath(),
),
)
.listen((progress) => add(HomeScreenDownloadProgressUpdated(progress)));
}
void _onHomeScreenDownloadProgressUpdated(
HomeScreenDownloadProgressUpdated event,
Emitter<HomeScreenState> emit,
) {
emit(
HomeScreenDownloadingState(
model: state.model.copyWith(progress: event.progress),
),
);
}
@override
Future<void> close() async {
await _downloadProgressSubscription?.cancel();
await _downloadManager.cancel(_downloadId);
return super.close();
}
}
@@ -0,0 +1,16 @@
part of 'home_screen_bloc.dart';
@immutable
sealed class HomeScreenEvent {}
final class HomeScreenLoad extends HomeScreenEvent {}
final class HomeScreenDownloadRequested extends HomeScreenEvent {}
final class HomeScreenDownloadPaused extends HomeScreenEvent {}
final class HomeScreenDownloadProgressUpdated extends HomeScreenEvent {
final DownloadProgress progress;
HomeScreenDownloadProgressUpdated(this.progress);
}
@@ -0,0 +1,24 @@
import 'package:flutter/foundation.dart';
import 'package:moonwell_launcher/features/downloader/domain/entities/download_progress.dart';
@immutable
final class HomeScreenModel {
/// The current download progress.
final DownloadProgress progress;
/// The output path for the downloaded file.
final Uri? outputPath;
const HomeScreenModel({required this.progress, this.outputPath});
const HomeScreenModel.initial()
: progress = const DownloadProgress.initial(),
outputPath = null;
HomeScreenModel copyWith({DownloadProgress? progress, Uri? outputPath}) {
return HomeScreenModel(
progress: progress ?? this.progress,
outputPath: outputPath ?? this.outputPath,
);
}
}
@@ -0,0 +1,24 @@
part of 'home_screen_bloc.dart';
@immutable
sealed class HomeScreenState {
final HomeScreenModel model;
const HomeScreenState({required this.model});
}
final class HomeScreenInitialState extends HomeScreenState {
const HomeScreenInitialState({required super.model});
}
final class HomeScreenReadyToDownloadState extends HomeScreenState {
const HomeScreenReadyToDownloadState({required super.model});
}
final class HomeScreenDownloadPausedState extends HomeScreenState {
const HomeScreenDownloadPausedState({required super.model});
}
final class HomeScreenDownloadingState extends HomeScreenState {
const HomeScreenDownloadingState({required super.model});
}
+68
View File
@@ -0,0 +1,68 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:moonwell_launcher/app/home_screen/bloc/home_screen_bloc.dart';
import 'package:moonwell_launcher/app/home_screen/left_pane.dart';
import 'package:moonwell_launcher/app/theme/mw_theme.dart';
import 'package:moonwell_launcher/features/downloader/application/download_manager.dart';
import 'package:moonwell_launcher/features/preferences/domain/repositories/preferences_repository.dart';
import 'package:moonwell_launcher/service_container.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return BlocProvider<HomeScreenBloc>(
create: (context) => HomeScreenBloc(
downloadManager: getIt<DownloadManager>(),
preferencesRepository: getIt<PreferencesRepository>(),
),
child: Builder(
builder: (context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(
// subtle vignette for “night” vibe
gradient: RadialGradient(
center: Alignment(0, -0.5),
radius: 1.2,
colors: [MWColors.deepNavy, MWColors.abyss],
),
),
child: Center(
child: Padding(
padding: EdgeInsets.all(24.0),
child: Row(
children: [
Expanded(
child: LeftPane(
title: Text(
'MoonWell',
style: theme.textTheme.headlineLarge,
),
progress: 0.0,
isDownloading: false,
kbps: 0.0,
eta: Duration.zero,
onStart: () {
context.read<HomeScreenBloc>().add(
HomeScreenDownloadRequested(),
);
},
onPause: () {},
onReset: () {},
),
),
],
),
),
),
),
);
},
),
);
}
}
+181
View File
@@ -0,0 +1,181 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:moonwell_launcher/app/home_screen/bloc/home_screen_bloc.dart';
import 'package:moonwell_launcher/app/home_screen/widgets/progress_bar.dart';
import 'package:moonwell_launcher/app/theme/mw_theme.dart';
import 'package:pixelarticons/pixel.dart';
class LeftPane extends StatelessWidget {
const LeftPane({
super.key,
required this.title,
required this.progress,
required this.isDownloading,
required this.kbps,
required this.eta,
required this.onStart,
required this.onPause,
required this.onReset,
});
final Widget title;
final double progress;
final bool isDownloading;
final double kbps;
final Duration eta;
final VoidCallback onStart;
final VoidCallback onPause;
final VoidCallback onReset;
String _speedLabel(BuildContext context) {
final kbps = context.read<HomeScreenBloc>().state.model.progress.speed;
if (kbps <= 0) return '';
if (kbps >= 1024) {
return '${(kbps / 1024).toStringAsFixed(2)} MB/s';
}
return '${kbps.toStringAsFixed(0)} kB/s';
}
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
final deco = Theme.of(context).extension<MoonWellDecorations>()!;
return BlocBuilder<HomeScreenBloc, HomeScreenState>(
builder: (context, state) {
final percent = _resolvePercentage(context);
final eta = state.model.progress.eta;
final canPlay = progress >= 1.0 && state is! HomeScreenDownloadingState;
return Card(
margin: EdgeInsets.zero,
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
title,
const SizedBox(height: 16),
Text(
'Classic+ Wrath of the Lich King experience',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: cs.onSurface.withAlpha(200),
),
),
const SizedBox(height: 28),
// Progress bar
GildedProgressBar(value: progress),
const SizedBox(height: 12),
Row(
children: [
Text(
'$percent%',
style: Theme.of(context).textTheme.titleMedium,
),
const Spacer(),
Icon(Pixel.speedfast, size: 18, color: cs.onSurfaceVariant),
const SizedBox(width: 6),
Text(
_speedLabel(context),
style: TextStyle(color: cs.onSurfaceVariant),
),
const SizedBox(width: 16),
Icon(
Pixel.timeline, // Updated to use PixelArtIcons
size: 18,
color: cs.onSurfaceVariant,
),
const SizedBox(width: 6),
Text(
eta == Duration.zero
? ''
: '${eta.inMinutes}:${(eta.inSeconds % 60).toString().padLeft(2, '0')}',
style: TextStyle(color: cs.onSurfaceVariant),
),
],
),
const SizedBox(height: 24),
// Controls row
Row(
children: [
Expanded(
child: ElevatedButton.icon(
icon: Icon(
canPlay ? Icons.play_arrow_rounded : Icons.download,
),
label: Text(
canPlay
? 'Play'
: (isDownloading
? 'Downloading…'
: (progress == 0 ? 'Install' : 'Resume')),
),
onPressed: canPlay
? () {}
: (isDownloading ? null : onStart),
),
),
// const SizedBox(width: 12),
// OutlinedButton.icon(
// icon: Icon(
// isDownloading ? Icons.pause_rounded : Icons.replay,
// ),
// label: Text(isDownloading ? 'Pause' : 'Reset'),
// onPressed: isDownloading
// ? onPause
// : (progress > 0 ? onReset : null),
// ),
],
),
const SizedBox(height: 20),
// Disk path / build info (placeholders)
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: cs.surfaceContainerHighest.withAlpha(128),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: cs.outline),
boxShadow: (deco.cardGlow),
),
child: Row(
children: [
const Icon(Pixel.folder),
const SizedBox(width: 8),
Expanded(
child: Text(
'Install path: ${state.model.outputPath?.toFilePath() ?? ''}',
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 12),
],
),
),
],
),
),
);
},
);
}
String _resolvePercentage(BuildContext context) {
final state = context.read<HomeScreenBloc>().state;
if (state is HomeScreenDownloadingState) {
final percentage =
state.model.progress.downloaded / state.model.progress.total;
return (percentage * 100).clamp(0, 100).toStringAsFixed(1);
}
return '0.0';
}
}
@@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:moonwell_launcher/app/theme/mw_theme.dart';
class GildedProgressBar extends StatelessWidget {
const GildedProgressBar({required this.value});
final double value;
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
final deco = Theme.of(context).extension<MoonWellDecorations>()!;
return Container(
height: 20,
decoration: BoxDecoration(
color: cs.surfaceContainerHighest,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: cs.outline),
),
clipBehavior: Clip.antiAlias,
child: Stack(
children: [
// Fill with gold bevel
FractionallySizedBox(
widthFactor: value.clamp(0.0, 1.0),
alignment: Alignment.centerLeft,
child: DecoratedBox(
decoration: BoxDecoration(
gradient: (deco.goldBevel as LinearGradient),
),
),
),
// Subtle top highlight
Align(
alignment: Alignment.topCenter,
child: Container(height: 6, color: Colors.white.withAlpha(10)),
),
],
),
);
}
}
+16
View File
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:moonwell_launcher/app/home_screen/home_screen.dart';
import 'package:moonwell_launcher/app/theme/mw_theme.dart';
class MoonWellApp extends StatelessWidget {
const MoonWellApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MoonWell',
home: const HomeScreen(),
theme: moonWellTheme(),
);
}
}
+25
View File
@@ -0,0 +1,25 @@
part of 'mw_theme.dart';
/// Core palette derived from the logo
class MWColors {
// “Night sky” blues
static const Color abyss = Color(0xFF0B101A); // page bg
static const Color deepNavy = Color(0xFF0F1522); // surfaces
static const Color stormNavy = Color(0xFF1A2233); // elevated surfaces
static const Color moonBlue = Color(
0xFF6BA3FF,
); // tertiary accent (moonlight)
// “Ornate gold”
static const Color gold = Color(0xFFE5B74A); // primary
static const Color goldDark = Color(0xFF7A5A00); // primary container
static const Color goldSoft = Color(0xFFF3D98C); // gradient highlight
// Lines & states
static const Color outline = Color(0xFF2B3242);
static const Color outlineGold = Color(0xFF7C6A3A);
// Semantic
static const Color success = Color(0xFF3DDC97);
static const Color warning = Color(0xFFF0B429);
}
+40
View File
@@ -0,0 +1,40 @@
part of 'mw_theme.dart';
class MoonWellDecorations extends ThemeExtension<MoonWellDecorations> {
final Gradient goldBevel; // for gilded headers/buttons
final Shadow textGlow; // subtle moonlight glow
final List<BoxShadow> cardGlow;
const MoonWellDecorations({
required this.goldBevel,
required this.textGlow,
required this.cardGlow,
});
@override
MoonWellDecorations copyWith({
Gradient? goldBevel,
Shadow? textGlow,
List<BoxShadow>? cardGlow,
}) => MoonWellDecorations(
goldBevel: goldBevel ?? this.goldBevel,
textGlow: textGlow ?? this.textGlow,
cardGlow: cardGlow ?? this.cardGlow,
);
@override
ThemeExtension<MoonWellDecorations> lerp(
ThemeExtension<MoonWellDecorations>? other,
double t,
) {
if (other is! MoonWellDecorations) return this;
return MoonWellDecorations(
goldBevel: Gradient.lerp(goldBevel, other.goldBevel, t)!,
textGlow: Shadow.lerp(textGlow, other.textGlow, t)!,
cardGlow: [
for (int i = 0; i < cardGlow.length; i++)
BoxShadow.lerp(cardGlow[i], other.cardGlow[i], t)!,
],
);
}
}
+222
View File
@@ -0,0 +1,222 @@
import 'package:flutter/material.dart';
part 'mw_colors.dart';
part 'mw_decorations.dart';
ThemeData moonWellTheme() {
const cs = ColorScheme(
brightness: Brightness.dark,
primary: MWColors.gold,
onPrimary: Color(0xFF1B1202),
primaryContainer: MWColors.goldDark,
onPrimaryContainer: Color(0xFFFFF0C2),
secondary: Color(0xFFC08A2E), // bronze accent
onSecondary: Color(0xFF201300),
secondaryContainer: Color(0xFF3B2A00),
onSecondaryContainer: Color(0xFFF6E2B6),
tertiary: MWColors.moonBlue, // moon-glow accent
onTertiary: Color(0xFF081120),
tertiaryContainer: Color(0xFF143A66),
onTertiaryContainer: Color(0xFFD9EBFF),
error: Color(0xFFFFB4AB),
onError: Color(0xFF690005),
errorContainer: Color(0xFF93000A),
onErrorContainer: Color(0xFFFFDAD6),
surface: MWColors.abyss,
onSurface: Color(0xFFE5EAF6),
surfaceContainerHighest: MWColors.stormNavy,
onSurfaceVariant: Color(0xFFC3C8D6),
outline: MWColors.outline,
outlineVariant: Color(0xFF40495C),
shadow: Colors.black,
scrim: Colors.black87,
inverseSurface: Color(0xFFE5EAF6),
onInverseSurface: Color(0xFF11151E),
inversePrimary: Color(0xFFF0D072),
);
final base = ThemeData(
useMaterial3: true,
colorScheme: cs,
scaffoldBackgroundColor: cs.surface,
canvasColor: cs.surface,
);
final text = base.textTheme
.apply(
fontFamily: 'Cinzel',
bodyColor: cs.onSurface,
displayColor: cs.onSurface,
)
.copyWith(
displayLarge: base.textTheme.displayLarge?.copyWith(
letterSpacing: 0.5,
fontWeight: FontWeight.w700,
shadows: const [Shadow(blurRadius: 10, color: Color(0x336BA3FF))],
),
headlineMedium: base.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.w700,
),
titleLarge: base.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w700,
),
);
return base.copyWith(
textTheme: text,
appBarTheme: AppBarTheme(
backgroundColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
elevation: 0,
scrolledUnderElevation: 0,
foregroundColor: cs.onSurface,
centerTitle: true,
titleTextStyle: text.titleLarge,
toolbarHeight: 64,
),
cardTheme: CardThemeData(
color: cs.surface,
elevation: 0,
margin: const EdgeInsets.all(12),
shape: RoundedRectangleBorder(
side: BorderSide(color: MWColors.outline.withAlpha(150)),
borderRadius: BorderRadius.circular(20),
),
shadowColor: MWColors.moonBlue.withAlpha(63),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ButtonStyle(
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 18, vertical: 14),
),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
),
elevation: const WidgetStatePropertyAll(6),
shadowColor: WidgetStatePropertyAll(MWColors.moonBlue.withAlpha(89)),
backgroundColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.disabled)) {
return MWColors.gold.withAlpha(115);
}
return cs.primary;
}),
foregroundColor: const WidgetStatePropertyAll(
Color(0xFF1B1202),
), // dark text on gold
),
),
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
foregroundColor: WidgetStatePropertyAll(cs.tertiary),
overlayColor: WidgetStatePropertyAll(cs.tertiary.withAlpha(10)),
),
),
filledButtonTheme: FilledButtonThemeData(
style: ButtonStyle(
backgroundColor: WidgetStatePropertyAll(cs.tertiaryContainer),
foregroundColor: WidgetStatePropertyAll(cs.onTertiaryContainer),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: ButtonStyle(
side: WidgetStatePropertyAll(
BorderSide(color: MWColors.outlineGold.withAlpha(230)),
),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
),
foregroundColor: WidgetStatePropertyAll(cs.primary),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: cs.surfaceContainerHighest,
hintStyle: TextStyle(color: cs.onSurfaceVariant.withAlpha(179)),
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide(color: MWColors.outline),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide(color: cs.primary, width: 1.6),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide(color: cs.error),
),
prefixIconColor: cs.onSurfaceVariant,
suffixIconColor: cs.onSurfaceVariant,
),
chipTheme: base.chipTheme.copyWith(
backgroundColor: cs.surfaceContainerHighest,
side: BorderSide(color: MWColors.outline),
selectedColor: cs.primaryContainer,
labelStyle: TextStyle(color: cs.onSurface),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
sliderTheme: base.sliderTheme.copyWith(
activeTrackColor: cs.primary,
inactiveTrackColor: cs.primary.withAlpha(63),
thumbColor: cs.primary,
),
dividerTheme: DividerThemeData(
color: MWColors.outline,
thickness: 1,
space: 24,
),
bottomNavigationBarTheme: BottomNavigationBarThemeData(
backgroundColor: cs.surface,
selectedItemColor: cs.primary,
unselectedItemColor: cs.onSurface.withAlpha(153),
elevation: 8,
type: BottomNavigationBarType.fixed,
),
extensions: <ThemeExtension<dynamic>>[
const MoonWellDecorations(
goldBevel: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
MWColors.goldSoft, // highlight
MWColors.gold, // body
Color(0xFFC58A1E), // warm edge
],
stops: [0.0, 0.55, 1.0],
),
textGlow: Shadow(
color: Color(0x446BA3FF), // moon-glow
blurRadius: 14,
offset: Offset(0, 0),
),
cardGlow: [
BoxShadow(
color: Color(0x33143666), // cool rim light
blurRadius: 28,
spreadRadius: 2,
offset: Offset(0, 8),
),
],
),
],
);
}