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,23 +19,31 @@ class _ProtonStepsState extends State<ProtonSteps> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ChangeNotifierProvider( return Padding(
create: (_) => proton, padding: const EdgeInsets.all(20.0),
child: Builder( child: ChangeNotifierProvider(
builder: (context) { create: (_) => proton,
switch (Provider.of<Proton>(context).protonState) { child: Builder(
case ProtonInstallationState.idle: builder: (context) {
return const InstallProton(); switch (Provider.of<Proton>(context).protonState) {
case ProtonInstallationState.downloading: case ProtonInstallationState.idle:
return const Center( return const InstallProton();
child: Text('downloading...'), case ProtonInstallationState.downloading:
); return const ProtonDownloadProgress();
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,47 +82,67 @@ class _InstallProtonState extends State<InstallProton> {
selectedValue = protonVersions.first; selectedValue = protonVersions.first;
} }
return Padding( return isLoading
padding: const EdgeInsets.all(20.0), ? const Row(
child: isLoading mainAxisAlignment: MainAxisAlignment.center,
? const Row( children: [
mainAxisAlignment: MainAxisAlignment.center, Padding(
children: [ padding: EdgeInsets.all(8.0),
Padding( child: CircularProgressIndicator(),
padding: EdgeInsets.all(8.0), ),
child: CircularProgressIndicator(), Text('Fetching versions...'),
],
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
YaruPopupMenuButton(
initialValue: selectedValue,
itemBuilder: (_) => protonVersions
.map(
(e) => PopupMenuItem(
value: e,
child: Text(e),
),
)
.toList(),
onSelected: (v) => setState(() {
selectedValue = v;
}),
child: Text(selectedValue!),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: SimpleButton(
onPressed: () => Provider.of<Proton>(context, listen: false)
.startInstallation(
Provider.of<GameStateProvider>(context,
listen: false),
selectedValue!),
child: const Text("Install"),
), ),
Text('Fetching versions...'), ),
], ],
) );
: Row( }
mainAxisAlignment: MainAxisAlignment.center, }
children: [
YaruPopupMenuButton( class ProtonDownloadProgress extends StatelessWidget {
initialValue: selectedValue, const ProtonDownloadProgress({super.key});
itemBuilder: (_) => protonVersions
.map( @override
(e) => PopupMenuItem( Widget build(BuildContext context) {
value: e, final provider = Provider.of<Proton>(context);
child: Text(e), final pourcent =
), (provider.currentProgress.toInt() / provider.maxProgress.toInt()) * 100;
)
.toList(), return Column(
onSelected: (v) => setState(() { children: [
selectedValue = v; Text("Downloaded: ${pourcent.toStringAsFixed(2)}%"),
}), YaruLinearProgressIndicator(
child: Text(selectedValue!), value: pourcent / 100,
), ),
Padding( ],
padding: const EdgeInsets.only(left: 8.0),
child: SimpleButton(
onPressed: () => Provider.of<Proton>(context, listen: false)
.startInstallation(context, selectedValue!),
child: const Text("Install"),
),
),
],
),
); );
} }
} }

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()
}
} }
} }