added loading bar and notify to start DXVK install

This commit is contained in:
ALEZ-DEV 2024-05-31 21:08:00 +02:00
parent 7ed53c752f
commit 3899ec3669
3 changed files with 107 additions and 61 deletions

View File

@ -17,8 +17,8 @@ class Proton with ChangeNotifier {
Int64 currentProgress = Int64(0); Int64 currentProgress = Int64(0);
Int64 maxProgress = Int64(0); Int64 maxProgress = Int64(0);
Future startInstallation(BuildContext context, String protonVersion) async { Future startInstallation(
protonState = ProtonInstallationState.downloading; GameStateProvider gameStateProvider, String protonVersion) async {
notifyListeners(); notifyListeners();
StartProtonInstallation(protonVersion: protonVersion).sendSignalToRust(); StartProtonInstallation(protonVersion: protonVersion).sendSignalToRust();
@ -26,6 +26,11 @@ class Proton with ChangeNotifier {
await for (final rustSignal in progressStream) { await for (final rustSignal in progressStream) {
currentProgress = rustSignal.message.current; currentProgress = rustSignal.message.current;
maxProgress = rustSignal.message.max; maxProgress = rustSignal.message.max;
if (protonState == ProtonInstallationState.idle) {
protonState = ProtonInstallationState.downloading;
}
notifyListeners(); notifyListeners();
if (currentProgress >= maxProgress) { if (currentProgress >= maxProgress) {
@ -44,7 +49,7 @@ class Proton with ChangeNotifier {
final notificationInstalledStream = final notificationInstalledStream =
NotifiyProtonSuccessfullyInstalled.rustSignalStream; NotifiyProtonSuccessfullyInstalled.rustSignalStream;
await for (final _ in notificationInstalledStream) { await for (final _ in notificationInstalledStream) {
Provider.of<GameStateProvider>(context, listen: false).updateGameState(); gameStateProvider.updateGameState();
break; break;
} }
} }

View File

@ -5,6 +5,7 @@ import 'package:yaru/widgets.dart';
import './../../models/github.dart'; import './../../models/github.dart';
import './../../models/proton.dart'; import './../../models/proton.dart';
import './../../widgets/simple_button.dart'; import './../../widgets/simple_button.dart';
import './../../providers/providers.dart';
class ProtonSteps extends StatefulWidget { class ProtonSteps extends StatefulWidget {
const ProtonSteps({super.key}); const ProtonSteps({super.key});
@ -18,7 +19,9 @@ class _ProtonStepsState extends State<ProtonSteps> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ChangeNotifierProvider( return Padding(
padding: const EdgeInsets.all(20.0),
child: ChangeNotifierProvider(
create: (_) => proton, create: (_) => proton,
child: Builder( child: Builder(
builder: (context) { builder: (context) {
@ -26,16 +29,22 @@ class _ProtonStepsState extends State<ProtonSteps> {
case ProtonInstallationState.idle: case ProtonInstallationState.idle:
return const InstallProton(); return const InstallProton();
case ProtonInstallationState.downloading: case ProtonInstallationState.downloading:
return const Center( return const ProtonDownloadProgress();
child: Text('downloading...'),
);
case ProtonInstallationState.decompressing: case ProtonInstallationState.decompressing:
return const Center( return const Row(
child: Text('decompressing...'), mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.all(8.0),
child: CircularProgressIndicator(),
),
Text('decompressing...'),
],
); );
} }
}, },
), ),
),
); );
} }
} }
@ -73,9 +82,7 @@ class _InstallProtonState extends State<InstallProton> {
selectedValue = protonVersions.first; selectedValue = protonVersions.first;
} }
return Padding( return isLoading
padding: const EdgeInsets.all(20.0),
child: isLoading
? const Row( ? const Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
@ -108,12 +115,34 @@ class _InstallProtonState extends State<InstallProton> {
padding: const EdgeInsets.only(left: 8.0), padding: const EdgeInsets.only(left: 8.0),
child: SimpleButton( child: SimpleButton(
onPressed: () => Provider.of<Proton>(context, listen: false) onPressed: () => Provider.of<Proton>(context, listen: false)
.startInstallation(context, selectedValue!), .startInstallation(
Provider.of<GameStateProvider>(context,
listen: false),
selectedValue!),
child: const Text("Install"), child: const Text("Install"),
), ),
), ),
], ],
), );
}
}
class ProtonDownloadProgress extends StatelessWidget {
const ProtonDownloadProgress({super.key});
@override
Widget build(BuildContext context) {
final provider = Provider.of<Proton>(context);
final pourcent =
(provider.currentProgress.toInt() / provider.maxProgress.toInt()) * 100;
return Column(
children: [
Text("Downloaded: ${pourcent.toStringAsFixed(2)}%"),
YaruLinearProgressIndicator(
value: pourcent / 100,
),
],
); );
} }
} }

View File

@ -75,7 +75,19 @@ pub async fn install_proton(component: ProtonComponent) {
error_message: format!("Failed to install Proton : {}", e), error_message: format!("Failed to install Proton : {}", e),
} }
.send_signal_to_dart(), .send_signal_to_dart(),
Ok(_) => NotifiyProtonSuccessfullyInstalled {}.send_signal_to_dart(), Ok(_) => {
let mut config = GameState::get_config().await;
config.is_wine_installed = true;
let result = GameState::save_config(config).await;
if let Err(e) = result {
ReportError {
error_message: format!("Failed to update config : {}", e),
}
.send_signal_to_dart();
}
NotifiyProtonSuccessfullyInstalled {}.send_signal_to_dart()
}
} }
} }