mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2025-12-16 01:18:50 +00:00
added loading bar and notify to start DXVK install
This commit is contained in:
parent
7ed53c752f
commit
3899ec3669
@ -17,8 +17,8 @@ class Proton with ChangeNotifier {
|
||||
Int64 currentProgress = Int64(0);
|
||||
Int64 maxProgress = Int64(0);
|
||||
|
||||
Future startInstallation(BuildContext context, String protonVersion) async {
|
||||
protonState = ProtonInstallationState.downloading;
|
||||
Future startInstallation(
|
||||
GameStateProvider gameStateProvider, String protonVersion) async {
|
||||
notifyListeners();
|
||||
|
||||
StartProtonInstallation(protonVersion: protonVersion).sendSignalToRust();
|
||||
@ -26,6 +26,11 @@ class Proton with ChangeNotifier {
|
||||
await for (final rustSignal in progressStream) {
|
||||
currentProgress = rustSignal.message.current;
|
||||
maxProgress = rustSignal.message.max;
|
||||
|
||||
if (protonState == ProtonInstallationState.idle) {
|
||||
protonState = ProtonInstallationState.downloading;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
|
||||
if (currentProgress >= maxProgress) {
|
||||
@ -44,7 +49,7 @@ class Proton with ChangeNotifier {
|
||||
final notificationInstalledStream =
|
||||
NotifiyProtonSuccessfullyInstalled.rustSignalStream;
|
||||
await for (final _ in notificationInstalledStream) {
|
||||
Provider.of<GameStateProvider>(context, listen: false).updateGameState();
|
||||
gameStateProvider.updateGameState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import 'package:yaru/widgets.dart';
|
||||
import './../../models/github.dart';
|
||||
import './../../models/proton.dart';
|
||||
import './../../widgets/simple_button.dart';
|
||||
import './../../providers/providers.dart';
|
||||
|
||||
class ProtonSteps extends StatefulWidget {
|
||||
const ProtonSteps({super.key});
|
||||
@ -18,23 +19,31 @@ class _ProtonStepsState extends State<ProtonSteps> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider(
|
||||
create: (_) => proton,
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
switch (Provider.of<Proton>(context).protonState) {
|
||||
case ProtonInstallationState.idle:
|
||||
return const InstallProton();
|
||||
case ProtonInstallationState.downloading:
|
||||
return const Center(
|
||||
child: Text('downloading...'),
|
||||
);
|
||||
case ProtonInstallationState.decompressing:
|
||||
return const Center(
|
||||
child: Text('decompressing...'),
|
||||
);
|
||||
}
|
||||
},
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: ChangeNotifierProvider(
|
||||
create: (_) => proton,
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
switch (Provider.of<Proton>(context).protonState) {
|
||||
case ProtonInstallationState.idle:
|
||||
return const InstallProton();
|
||||
case ProtonInstallationState.downloading:
|
||||
return const ProtonDownloadProgress();
|
||||
case ProtonInstallationState.decompressing:
|
||||
return const Row(
|
||||
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;
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: isLoading
|
||||
? const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: CircularProgressIndicator(),
|
||||
return isLoading
|
||||
? const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
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(
|
||||
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(context, selectedValue!),
|
||||
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,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +75,19 @@ pub async fn install_proton(component: ProtonComponent) {
|
||||
error_message: format!("Failed to install Proton : {}", e),
|
||||
}
|
||||
.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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user