WIP: feat(ui): Migrate to new UI implementation
This commit is contained in:
@@ -136,6 +136,7 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
|
||||
errorMessage: null,
|
||||
processedFiles: 0,
|
||||
totalFiles: 0,
|
||||
syncStage: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -306,6 +307,7 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
|
||||
remoteBuildHash: event.status.remoteBuildHash,
|
||||
processedFiles: event.status.processedFiles,
|
||||
totalFiles: event.status.totalFiles,
|
||||
syncStage: event.status.stage,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -330,6 +332,7 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
|
||||
statusText: 'Обновление приостановлено.',
|
||||
currentPath: null,
|
||||
errorMessage: null,
|
||||
syncStage: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -344,6 +347,7 @@ class HomeScreenBloc extends Bloc<HomeScreenEvent, HomeScreenState> {
|
||||
statusText: 'Не удалось завершить обновление клиента.',
|
||||
currentPath: null,
|
||||
errorMessage: _formatError(event.error),
|
||||
syncStage: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:moonwell_launcher/features/downloader/domain/entities/download_progress.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/domain/entities/client_sync_status.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/domain/entities/launcher_news_item.dart';
|
||||
|
||||
enum HomeScreenPhase {
|
||||
@@ -31,6 +32,7 @@ final class HomeScreenModel {
|
||||
final List<LauncherNewsItem> newsItems;
|
||||
final bool isLoadingNews;
|
||||
final String? newsErrorMessage;
|
||||
final ClientSyncStage? syncStage;
|
||||
|
||||
const HomeScreenModel({
|
||||
required this.progress,
|
||||
@@ -48,6 +50,7 @@ final class HomeScreenModel {
|
||||
required this.newsItems,
|
||||
required this.isLoadingNews,
|
||||
required this.newsErrorMessage,
|
||||
required this.syncStage,
|
||||
});
|
||||
|
||||
const HomeScreenModel.initial()
|
||||
@@ -65,7 +68,8 @@ final class HomeScreenModel {
|
||||
totalFiles = 0,
|
||||
newsItems = const <LauncherNewsItem>[],
|
||||
isLoadingNews = true,
|
||||
newsErrorMessage = null;
|
||||
newsErrorMessage = null,
|
||||
syncStage = null;
|
||||
|
||||
bool get isBusy =>
|
||||
phase == HomeScreenPhase.authenticating ||
|
||||
@@ -91,6 +95,7 @@ final class HomeScreenModel {
|
||||
List<LauncherNewsItem>? newsItems,
|
||||
bool? isLoadingNews,
|
||||
Object? newsErrorMessage = _sentinel,
|
||||
Object? syncStage = _sentinel,
|
||||
}) {
|
||||
return HomeScreenModel(
|
||||
progress: progress ?? this.progress,
|
||||
@@ -120,6 +125,9 @@ final class HomeScreenModel {
|
||||
newsErrorMessage: newsErrorMessage == _sentinel
|
||||
? this.newsErrorMessage
|
||||
: newsErrorMessage as String?,
|
||||
syncStage: syncStage == _sentinel
|
||||
? this.syncStage
|
||||
: syncStage as ClientSyncStage?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ 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/home_screen_content.dart';
|
||||
import 'package:moonwell_launcher/app/login_screen/login_screen.dart';
|
||||
import 'package:moonwell_launcher/app/theme/mw_theme.dart';
|
||||
import 'package:moonwell_launcher/app/widgets/window_title_bar.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/application/client_sync_use_case.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/data/game_installation_service.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/data/launcher_api_client.dart';
|
||||
@@ -44,38 +42,7 @@ class HomeScreen extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Image.asset('assets/background.png', fit: BoxFit.cover),
|
||||
),
|
||||
Positioned.fill(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
MWColors.abyss.withAlpha(180),
|
||||
MWColors.abyss.withAlpha(220),
|
||||
MWColors.abyss.withAlpha(240),
|
||||
],
|
||||
stops: const [0.0, 0.5, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Positioned.fill(child: HomeScreenContent()),
|
||||
const Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: WindowTitleBar(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: const HomeScreenContent(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,618 +1,191 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:moonwell_launcher/app/design_system/mw_launcher_components.dart';
|
||||
import 'package:moonwell_launcher/app/design_system/mw_shells.dart';
|
||||
import 'package:moonwell_launcher/app/home_screen/bloc/home_screen_bloc.dart';
|
||||
import 'package:moonwell_launcher/app/home_screen/bloc/home_screen_model.dart';
|
||||
import 'package:moonwell_launcher/app/home_screen/widgets/gilded_progress_bar.dart';
|
||||
import 'package:moonwell_launcher/app/theme/mw_theme.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/domain/entities/launcher_news_item.dart';
|
||||
import 'package:pixelarticons/pixel.dart';
|
||||
import 'package:moonwell_launcher/app/mw_app.dart';
|
||||
import 'package:moonwell_launcher/features/launcher/domain/entities/client_sync_status.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class HomeScreenContent extends StatelessWidget {
|
||||
const HomeScreenContent({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = context.watch<HomeScreenBloc>().state;
|
||||
final model = state.model;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 36),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: _NewsPanel(model: model, cs: cs),
|
||||
),
|
||||
SizedBox(
|
||||
width: 320,
|
||||
child: _RightPanel(model: model, cs: cs),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_BottomBar(model: model, cs: cs),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NewsPanel extends StatelessWidget {
|
||||
const _NewsPanel({required this.model, required this.cs});
|
||||
|
||||
final HomeScreenModel model;
|
||||
final ColorScheme cs;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 24, top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Image.asset(
|
||||
'assets/logo.png',
|
||||
height: 120,
|
||||
filterQuality: FilterQuality.high,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'\u041d\u043e\u0432\u043e\u0441\u0442\u0438',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleLarge?.copyWith(color: cs.onSurface),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: ShaderMask(
|
||||
shaderCallback: (bounds) => LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Colors.white, Colors.white, Colors.white.withAlpha(0)],
|
||||
stops: const [0.0, 0.85, 1.0],
|
||||
).createShader(bounds),
|
||||
blendMode: BlendMode.dstIn,
|
||||
child: _buildNewsBody(context),
|
||||
),
|
||||
),
|
||||
],
|
||||
final model = context.watch<HomeScreenBloc>().state.model;
|
||||
return MwLauncherShell(
|
||||
news: _buildNews(model),
|
||||
syncActions: _buildSyncActions(context, model),
|
||||
statusBar: _buildStatusBar(model),
|
||||
account: MwAccountAffordance(
|
||||
onSettings: () => _showSettings(context, model),
|
||||
onLogout: () =>
|
||||
context.read<HomeScreenBloc>().add(HomeScreenLogoutRequested()),
|
||||
),
|
||||
onDrag: windowManager.startDragging,
|
||||
onDoubleTap: () => unawaited(_toggleMaximized()),
|
||||
onMinimize: windowManager.minimize,
|
||||
onMaximizeRestore: () => unawaited(_toggleMaximized()),
|
||||
onClose: () => unawaited(windowManager.destroy()),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNewsBody(BuildContext context) {
|
||||
if (model.isLoadingNews) {
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: 26,
|
||||
height: 26,
|
||||
child: CircularProgressIndicator(strokeWidth: 2.2, color: cs.primary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (model.newsItems.isEmpty && model.newsErrorMessage != null) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(right: 16, bottom: 24),
|
||||
children: [
|
||||
_NewsStatusCard(
|
||||
icon: Icons.cloud_off_rounded,
|
||||
title:
|
||||
'\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c '
|
||||
'\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c '
|
||||
'\u043d\u043e\u0432\u043e\u0441\u0442\u0438',
|
||||
description: model.newsErrorMessage!,
|
||||
Widget _buildNews(HomeScreenModel model) {
|
||||
final state = model.isLoadingNews
|
||||
? MwNewsListState.loading
|
||||
: model.newsItems.isNotEmpty
|
||||
? MwNewsListState.populated
|
||||
: model.newsErrorMessage != null
|
||||
? MwNewsListState.failure
|
||||
: MwNewsListState.empty;
|
||||
return MwNewsList(
|
||||
state: state,
|
||||
error: model.newsErrorMessage,
|
||||
items: [
|
||||
for (final item in model.newsItems)
|
||||
MwNewsItemData(
|
||||
title: item.title,
|
||||
body: item.body,
|
||||
createdAt: item.createdAt,
|
||||
imageUrl: item.imageUrl,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
if (model.newsItems.isEmpty) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(right: 16, bottom: 24),
|
||||
children: const [
|
||||
_NewsStatusCard(
|
||||
icon: Icons.inbox_outlined,
|
||||
title:
|
||||
'\u041d\u043e\u0432\u043e\u0441\u0442\u0435\u0439 '
|
||||
'\u043f\u043e\u043a\u0430 \u043d\u0435\u0442',
|
||||
description:
|
||||
'\u041a\u043e\u0433\u0434\u0430 \u0432 API \u043f\u043e\u044f'
|
||||
'\u0432\u044f\u0442\u0441\u044f \u043f\u0443\u0431\u043b\u0438'
|
||||
'\u043a\u0430\u0446\u0438\u0438, \u043e\u043d\u0438 '
|
||||
'\u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0437\u0434'
|
||||
'\u0435\u0441\u044c.',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.only(right: 16, bottom: 24),
|
||||
itemCount: model.newsItems.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, index) {
|
||||
return _NewsCard(item: model.newsItems[index]);
|
||||
Widget _buildSyncActions(BuildContext context, HomeScreenModel model) {
|
||||
final presentation = _syncPresentation(model);
|
||||
final progress = model.progress.total > 0
|
||||
? (model.progress.downloaded / model.progress.total).clamp(0.0, 1.0)
|
||||
: null;
|
||||
return MwSyncActionArea(
|
||||
state: presentation,
|
||||
status: model.statusText,
|
||||
currentPath: model.currentPath,
|
||||
error: model.errorMessage,
|
||||
progress: progress,
|
||||
onPrimary: () {
|
||||
final bloc = context.read<HomeScreenBloc>();
|
||||
if (model.phase == HomeScreenPhase.readyToPlay && model.canPlay) {
|
||||
bloc.add(HomeScreenPlayRequested());
|
||||
} else {
|
||||
bloc.add(HomeScreenSyncRequested());
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NewsStatusCard extends StatelessWidget {
|
||||
const _NewsStatusCard({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String description;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface.withAlpha(140),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: cs.outline.withAlpha(100)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, color: cs.tertiary),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
color: cs.tertiary,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
description,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: cs.onSurface.withAlpha(200),
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NewsCard extends StatelessWidget {
|
||||
const _NewsCard({required this.item});
|
||||
|
||||
final LauncherNewsItem item;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface.withAlpha(140),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: cs.outline.withAlpha(100)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.title,
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
color: cs.tertiary,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
if (item.createdAt != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
_formatCreatedAt(item.createdAt!),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodySmall?.copyWith(color: cs.onSurfaceVariant),
|
||||
),
|
||||
],
|
||||
if (item.imageUrl != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 16 / 7,
|
||||
child: Image.network(
|
||||
item.imageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, _, _) => Container(
|
||||
color: cs.surface.withAlpha(120),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(
|
||||
Icons.broken_image_outlined,
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
item.body,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: cs.onSurface.withAlpha(200),
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
onPause: model.isSyncing
|
||||
? () => context.read<HomeScreenBloc>().add(HomeScreenPauseRequested())
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
String _formatCreatedAt(DateTime value) {
|
||||
final localValue = value.toLocal();
|
||||
final day = localValue.day.toString().padLeft(2, '0');
|
||||
final month = localValue.month.toString().padLeft(2, '0');
|
||||
final year = localValue.year.toString();
|
||||
return '$day.$month.$year';
|
||||
}
|
||||
}
|
||||
|
||||
class _RightPanel extends StatelessWidget {
|
||||
const _RightPanel({required this.model, required this.cs});
|
||||
|
||||
final HomeScreenModel model;
|
||||
final ColorScheme cs;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final deco = Theme.of(context).extension<MoonWellDecorations>()!;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(right: 20, top: 8, bottom: 12),
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: MWColors.abyss.withAlpha(200),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: cs.outline.withAlpha(80)),
|
||||
boxShadow: deco.cardGlow,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: TextButton.icon(
|
||||
onPressed: () => context.read<HomeScreenBloc>().add(
|
||||
HomeScreenLogoutRequested(),
|
||||
),
|
||||
icon: const Icon(Icons.logout_rounded, size: 16),
|
||||
label: const Text('\u0412\u044b\u0439\u0442\u0438'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: cs.onSurfaceVariant,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 8,
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => context.read<HomeScreenBloc>().add(
|
||||
HomeScreenOutputDirRequested(),
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface.withAlpha(100),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: cs.outline.withAlpha(80)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Pixel.folder, size: 18, color: cs.onSurfaceVariant),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
model.outputPath?.toFilePath() ??
|
||||
'\u0412\u044b\u0431\u0440\u0430\u0442\u044c '
|
||||
'\u043f\u0430\u043f\u043a\u0443',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: cs.onSurfaceVariant,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.edit,
|
||||
size: 14,
|
||||
color: cs.onSurfaceVariant.withAlpha(120),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface.withAlpha(80),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: cs.outline.withAlpha(60)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
model.statusText,
|
||||
style: TextStyle(
|
||||
color: cs.onSurface.withAlpha(180),
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
if (model.currentPath != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
model.currentPath!,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 11),
|
||||
),
|
||||
],
|
||||
if (model.totalFiles > 0) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'\u0424\u0430\u0439\u043b\u044b: '
|
||||
'${model.processedFiles}/${model.totalFiles}',
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 11),
|
||||
),
|
||||
],
|
||||
if (model.errorMessage != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
model.errorMessage!,
|
||||
style: TextStyle(color: cs.error, fontSize: 12),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (model.remoteBuildHash != null || model.localBuildHash != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
'Build: ${_shortHash(model.localBuildHash)} / '
|
||||
'${_shortHash(model.remoteBuildHash)}',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 10),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _shortHash(String? hash) {
|
||||
if (hash == null || hash.isEmpty) {
|
||||
return '-';
|
||||
MwSyncPresentation _syncPresentation(HomeScreenModel model) {
|
||||
if (model.phase == HomeScreenPhase.paused) {
|
||||
return MwSyncPresentation.paused;
|
||||
}
|
||||
|
||||
if (hash.length <= 12) {
|
||||
return hash;
|
||||
if (model.phase == HomeScreenPhase.failure) {
|
||||
return MwSyncPresentation.failure;
|
||||
}
|
||||
|
||||
return '${hash.substring(0, 8)}...${hash.substring(hash.length - 4)}';
|
||||
if (model.phase == HomeScreenPhase.readyToPlay) {
|
||||
return model.statusText.startsWith('Игра запущена')
|
||||
? MwSyncPresentation.launched
|
||||
: MwSyncPresentation.ready;
|
||||
}
|
||||
if (model.phase != HomeScreenPhase.syncing) {
|
||||
return MwSyncPresentation.install;
|
||||
}
|
||||
return switch (model.syncStage) {
|
||||
ClientSyncStage.downloadingFiles => MwSyncPresentation.downloading,
|
||||
ClientSyncStage.verifyingInstallation => MwSyncPresentation.verifying,
|
||||
ClientSyncStage.completed => MwSyncPresentation.ready,
|
||||
_ => MwSyncPresentation.scanning,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class _BottomBar extends StatelessWidget {
|
||||
const _BottomBar({required this.model, required this.cs});
|
||||
Widget _buildStatusBar(HomeScreenModel model) {
|
||||
return MwLauncherStatusBar(
|
||||
status: model.outputPath?.toFilePath() ?? 'Папка установки не выбрана',
|
||||
fileCount: model.totalFiles > 0
|
||||
? '${model.processedFiles}/${model.totalFiles}'
|
||||
: null,
|
||||
speed: model.progress.speed > 0
|
||||
? _formatSpeed(model.progress.speed)
|
||||
: null,
|
||||
eta: model.progress.eta > Duration.zero
|
||||
? _formatDuration(model.progress.eta)
|
||||
: null,
|
||||
buildHash: _shortHash(model.localBuildHash ?? model.remoteBuildHash),
|
||||
);
|
||||
}
|
||||
|
||||
final HomeScreenModel model;
|
||||
final ColorScheme cs;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final progressValue = model.progress.total == 0
|
||||
? 0.0
|
||||
: model.progress.downloaded / model.progress.total;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [MWColors.abyss.withAlpha(0), MWColors.abyss.withAlpha(230)],
|
||||
Future<void> _showSettings(
|
||||
BuildContext context,
|
||||
HomeScreenModel model,
|
||||
) async {
|
||||
final bloc = context.read<HomeScreenBloc>();
|
||||
final themeController = LauncherThemeScope.of(context);
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => Dialog(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 460, maxHeight: 620),
|
||||
child: AnimatedBuilder(
|
||||
animation: themeController,
|
||||
builder: (context, _) => SingleChildScrollView(
|
||||
child: MwSettingsPanel(
|
||||
installationPath: model.outputPath?.toFilePath(),
|
||||
themeVariant: themeController.variant,
|
||||
syncActive: model.isSyncing,
|
||||
onChooseDirectory: () {
|
||||
Navigator.of(dialogContext).pop();
|
||||
bloc.add(HomeScreenOutputDirRequested());
|
||||
},
|
||||
onThemeChanged: (variant) {
|
||||
unawaited(themeController.setVariant(variant));
|
||||
},
|
||||
onVerify: () {
|
||||
Navigator.of(dialogContext).pop();
|
||||
bloc.add(HomeScreenSyncRequested());
|
||||
},
|
||||
onLogout: () {
|
||||
Navigator.of(dialogContext).pop();
|
||||
bloc.add(HomeScreenLogoutRequested());
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (model.isSyncing) ...[
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: GildedProgressBar(value: progressValue)),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'${(progressValue * 100).clamp(0, 100).toStringAsFixed(1)}%',
|
||||
style: TextStyle(
|
||||
color: cs.onSurface,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
_formatSpeed(model.progress.speed),
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 44,
|
||||
child: ElevatedButton.icon(
|
||||
icon: Icon(_resolvePrimaryIcon(model), size: 20),
|
||||
label: Text(_resolvePrimaryLabel(model)),
|
||||
onPressed: model.isBusy
|
||||
? null
|
||||
: () => _onPrimaryAction(context, model),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (model.canPlay || model.isSyncing) ...[
|
||||
const SizedBox(width: 8),
|
||||
SizedBox(
|
||||
height: 44,
|
||||
child: OutlinedButton.icon(
|
||||
icon: Icon(_resolveSecondaryIcon(model), size: 18),
|
||||
label: Text(_resolveSecondaryLabel(model)),
|
||||
onPressed: () => _onSecondaryAction(context, model),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 38,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface.withAlpha(100),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: cs.outline.withAlpha(60)),
|
||||
),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
model.currentPath ?? model.statusText,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: cs.onSurface.withAlpha(160),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onPrimaryAction(BuildContext context, HomeScreenModel model) {
|
||||
final bloc = context.read<HomeScreenBloc>();
|
||||
|
||||
if (model.canPlay) {
|
||||
bloc.add(HomeScreenPlayRequested());
|
||||
return;
|
||||
Future<void> _toggleMaximized() async {
|
||||
if (await windowManager.isMaximized()) {
|
||||
await windowManager.unmaximize();
|
||||
} else {
|
||||
await windowManager.maximize();
|
||||
}
|
||||
|
||||
bloc.add(HomeScreenSyncRequested());
|
||||
}
|
||||
|
||||
void _onSecondaryAction(BuildContext context, HomeScreenModel model) {
|
||||
final bloc = context.read<HomeScreenBloc>();
|
||||
|
||||
if (model.isSyncing) {
|
||||
bloc.add(HomeScreenPauseRequested());
|
||||
return;
|
||||
}
|
||||
|
||||
if (model.canPlay) {
|
||||
bloc.add(HomeScreenSyncRequested());
|
||||
return;
|
||||
}
|
||||
|
||||
bloc.add(HomeScreenOutputDirRequested());
|
||||
}
|
||||
|
||||
String _resolvePrimaryLabel(HomeScreenModel model) {
|
||||
if (model.isSyncing) {
|
||||
return '\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435...';
|
||||
}
|
||||
|
||||
if (model.canPlay) {
|
||||
return '\u0418\u0433\u0440\u0430\u0442\u044c';
|
||||
}
|
||||
|
||||
return model.hasClientExecutable
|
||||
? '\u041e\u0431\u043d\u043e\u0432\u0438\u0442\u044c'
|
||||
: '\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c';
|
||||
}
|
||||
|
||||
IconData _resolvePrimaryIcon(HomeScreenModel model) {
|
||||
if (model.canPlay) {
|
||||
return Icons.play_arrow_rounded;
|
||||
}
|
||||
|
||||
return Icons.download_rounded;
|
||||
}
|
||||
|
||||
String _resolveSecondaryLabel(HomeScreenModel model) {
|
||||
if (model.isSyncing) {
|
||||
return '\u041f\u0430\u0443\u0437\u0430';
|
||||
}
|
||||
|
||||
if (model.canPlay) {
|
||||
return '\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c';
|
||||
}
|
||||
|
||||
return '\u041f\u0430\u043f\u043a\u0430';
|
||||
}
|
||||
|
||||
IconData _resolveSecondaryIcon(HomeScreenModel model) {
|
||||
if (model.isSyncing) {
|
||||
return Pixel.pause;
|
||||
}
|
||||
|
||||
if (model.canPlay) {
|
||||
return Icons.refresh_rounded;
|
||||
}
|
||||
|
||||
return Pixel.folder;
|
||||
}
|
||||
|
||||
String _formatSpeed(int bytesPerSecond) {
|
||||
if (bytesPerSecond <= 0) {
|
||||
return '-';
|
||||
const megabyte = 1024 * 1024;
|
||||
if (bytesPerSecond >= megabyte) {
|
||||
return '${(bytesPerSecond / megabyte).toStringAsFixed(1)} MB/s';
|
||||
}
|
||||
return '${(bytesPerSecond / 1024).toStringAsFixed(0)} KB/s';
|
||||
}
|
||||
|
||||
if (bytesPerSecond >= 1024 * 1024) {
|
||||
return '${(bytesPerSecond / (1024 * 1024)).toStringAsFixed(2)} MB/s';
|
||||
}
|
||||
String _formatDuration(Duration duration) {
|
||||
final hours = duration.inHours.toString().padLeft(2, '0');
|
||||
final minutes = (duration.inMinutes % 60).toString().padLeft(2, '0');
|
||||
final seconds = (duration.inSeconds % 60).toString().padLeft(2, '0');
|
||||
return '$hours:$minutes:$seconds';
|
||||
}
|
||||
|
||||
if (bytesPerSecond >= 1024) {
|
||||
return '${(bytesPerSecond / 1024).toStringAsFixed(1)} KB/s';
|
||||
}
|
||||
|
||||
return '$bytesPerSecond B/s';
|
||||
String? _shortHash(String? hash) {
|
||||
if (hash == null || hash.isEmpty) return null;
|
||||
return hash.length <= 8 ? hash : hash.substring(0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:moonwell_launcher/app/theme/mw_theme.dart';
|
||||
|
||||
class GildedProgressBar extends StatelessWidget {
|
||||
const GildedProgressBar({super.key, 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: [
|
||||
// Subtle top highlight
|
||||
Positioned(
|
||||
top: 0.0,
|
||||
height: 6.0,
|
||||
left: 0.0,
|
||||
right: 0.0,
|
||||
child: ColoredBox(color: Colors.white.withAlpha(10)),
|
||||
),
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: value.clamp(0.0, 1.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
gradient: (deco.goldBevel as LinearGradient),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user