mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2025-12-15 17:08:51 +00:00
can now install dependencies from GUI and made some refactor
This commit is contained in:
parent
dfde93325b
commit
8773d34b71
@ -117,7 +117,7 @@ async fn main() {
|
||||
}
|
||||
GameState::DependecieNotInstalled => {
|
||||
info!("Dependecies not installed, installing it...");
|
||||
GameManager::install_dependecies(&proton.clone().unwrap())
|
||||
GameManager::install_dependencies(&proton.clone().unwrap())
|
||||
.await
|
||||
.expect("Failed to install dependecies");
|
||||
info!("Dependecies installed");
|
||||
|
||||
@ -110,7 +110,7 @@ impl GameManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn install_dependecies(proton: &Proton) -> anyhow::Result<()> {
|
||||
pub async fn install_dependencies(proton: &Proton) -> anyhow::Result<()> {
|
||||
let wine_with_proton_prefix = proton // wine take the data/wine/pfx prefix, but we want the data/wine prefix
|
||||
.wine()
|
||||
.clone()
|
||||
|
||||
23
babylonia_terminal_launcher/lib/models/dependencies.dart
Normal file
23
babylonia_terminal_launcher/lib/models/dependencies.dart
Normal file
@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import './../messages/steps/dependencies.pb.dart';
|
||||
import './../providers/providers.dart';
|
||||
|
||||
enum DependenciesInstallationState {
|
||||
idle,
|
||||
installing,
|
||||
}
|
||||
|
||||
class Dependencies with ChangeNotifier {
|
||||
DependenciesInstallationState dependeciesState =
|
||||
DependenciesInstallationState.idle;
|
||||
|
||||
Future startInstallation(GameStateProvider gameState) async {
|
||||
StartDependenciesInstallation().sendSignalToRust();
|
||||
final stream = NotifyDependenciesSuccessfullyInstalled.rustSignalStream;
|
||||
await for (final _ in stream) {
|
||||
gameState.updateGameState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,7 @@ class DXVK with ChangeNotifier {
|
||||
}
|
||||
|
||||
final notificationInstalledStream =
|
||||
NotifiyDXVKSuccessfullyInstalled.rustSignalStream;
|
||||
NotifyDXVKSuccessfullyInstalled.rustSignalStream;
|
||||
await for (final _ in notificationInstalledStream) {
|
||||
gameStateProvider.updateGameState();
|
||||
break;
|
||||
|
||||
@ -44,7 +44,7 @@ class Proton with ChangeNotifier {
|
||||
}
|
||||
|
||||
final notificationInstalledStream =
|
||||
NotifiyProtonSuccessfullyInstalled.rustSignalStream;
|
||||
NotifyProtonSuccessfullyInstalled.rustSignalStream;
|
||||
await for (final _ in notificationInstalledStream) {
|
||||
gameStateProvider.updateGameState();
|
||||
break;
|
||||
|
||||
@ -9,6 +9,7 @@ import './../../widgets/simple_button.dart';
|
||||
import './../../widgets/steps/proton_steps_widget.dart';
|
||||
import './../../widgets/steps/dxvk_steps_widget.dart';
|
||||
import './../../widgets/steps/fonts_steps_widget.dart';
|
||||
import './../../widgets/steps/dependencies_steps_widget.dart';
|
||||
|
||||
class StepsScreen extends StatelessWidget {
|
||||
StepsScreen({super.key});
|
||||
@ -49,16 +50,13 @@ class StepsScreen extends StatelessWidget {
|
||||
Text("Proton"),
|
||||
Text("DXVK"),
|
||||
Text("Fonts"),
|
||||
Text("Dependecies"),
|
||||
Text("Dependencies"),
|
||||
],
|
||||
children: const [
|
||||
ProtonSteps(),
|
||||
DXVKSteps(),
|
||||
FontsSteps(),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(40.0),
|
||||
child: Text("Dependecies"),
|
||||
),
|
||||
DependenciesSteps(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
import 'package:babylonia_terminal_launcher/widgets/gtk_spinner_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import './../../models/dependencies.dart';
|
||||
import './../../providers/providers.dart';
|
||||
import './../../widgets/simple_button.dart';
|
||||
|
||||
class DependenciesSteps extends StatelessWidget {
|
||||
const DependenciesSteps({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: ChangeNotifierProvider(
|
||||
create: (context) => Dependencies(),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
switch (Provider.of<Dependencies>(context).dependeciesState) {
|
||||
case DependenciesInstallationState.idle:
|
||||
return const InstallDependecies();
|
||||
case DependenciesInstallationState.installing:
|
||||
return const DependeciesInstallationProgress();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class InstallDependecies extends StatefulWidget {
|
||||
const InstallDependecies({super.key});
|
||||
|
||||
@override
|
||||
State<InstallDependecies> createState() => _InstallDependeciesState();
|
||||
}
|
||||
|
||||
class _InstallDependeciesState extends State<InstallDependecies> {
|
||||
bool canInstall = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SimpleButton(
|
||||
onPressed: canInstall
|
||||
? () {
|
||||
Provider.of<Dependencies>(context, listen: false)
|
||||
.startInstallation(
|
||||
Provider.of<GameStateProvider>(context, listen: false),
|
||||
);
|
||||
setState(() {
|
||||
canInstall = false;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: const Text("Install"),
|
||||
),
|
||||
if (!canInstall) const GtkSpinner(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DependeciesInstallationProgress extends StatelessWidget {
|
||||
const DependeciesInstallationProgress({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Row(
|
||||
children: [
|
||||
GtkSpinner(),
|
||||
Text(
|
||||
'Installing dependecies (this can take a while, so go grab a coffee)',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -99,6 +99,7 @@ class _InstallDXVKState extends State<InstallDXVK> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
YaruPopupMenuButton(
|
||||
enabled: canInstall,
|
||||
initialValue: selectedValue,
|
||||
itemBuilder: (_) => protonVersions
|
||||
.map(
|
||||
@ -131,6 +132,7 @@ class _InstallDXVKState extends State<InstallDXVK> {
|
||||
child: const Text("Install"),
|
||||
),
|
||||
),
|
||||
if (!canInstall) const GtkSpinner(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@ -45,18 +45,25 @@ class _InstallFontsState extends State<InstallFonts> {
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: SimpleButton(
|
||||
onPressed: canInstall
|
||||
? () {
|
||||
Provider.of<Fonts>(context, listen: false).startInstallation(
|
||||
Provider.of<GameStateProvider>(context, listen: false),
|
||||
);
|
||||
setState(() {
|
||||
canInstall = false;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: const Text("Install"),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SimpleButton(
|
||||
onPressed: canInstall
|
||||
? () {
|
||||
Provider.of<Fonts>(context, listen: false)
|
||||
.startInstallation(
|
||||
Provider.of<GameStateProvider>(context, listen: false),
|
||||
);
|
||||
setState(() {
|
||||
canInstall = false;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: const Text("Install"),
|
||||
),
|
||||
if (!canInstall) const GtkSpinner(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
syntax = "proto3";
|
||||
package dependencies;
|
||||
|
||||
// [RINF:DART-SIGNAL]
|
||||
message StartDependenciesInstallation {}
|
||||
|
||||
// [RINF:RUST-SIGNAL]
|
||||
message NotifyDependenciesSuccessfullyInstalled {}
|
||||
@ -16,4 +16,4 @@ message StartDXVKInstallation {
|
||||
message NotifyDXVKStartDecompressing {}
|
||||
|
||||
// [RINF:RUST-SIGNAL]
|
||||
message NotifiyDXVKSuccessfullyInstalled {}
|
||||
message NotifyDXVKSuccessfullyInstalled {}
|
||||
|
||||
@ -8,9 +8,7 @@ message FontsInstallationProgress {
|
||||
}
|
||||
|
||||
// [RINF:DART-SIGNAL]
|
||||
message StartFontsInstallation {
|
||||
string protonVersion = 1;
|
||||
};
|
||||
message StartFontsInstallation {};
|
||||
|
||||
// [RINF:RUST-SIGNAL]
|
||||
message NotifiyFontsSuccessfullyInstalled {}
|
||||
message NotifyFontsSuccessfullyInstalled {}
|
||||
|
||||
@ -16,4 +16,4 @@ message StartProtonInstallation {
|
||||
message NotifyProtonStartDecompressing {}
|
||||
|
||||
// [RINF:RUST-SIGNAL]
|
||||
message NotifiyProtonSuccessfullyInstalled {}
|
||||
message NotifyProtonSuccessfullyInstalled {}
|
||||
|
||||
42
babylonia_terminal_launcher/native/hub/src/dependencies.rs
Normal file
42
babylonia_terminal_launcher/native/hub/src/dependencies.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use std::thread;
|
||||
|
||||
use babylonia_terminal_sdk::{
|
||||
components::proton_component::ProtonComponent, game_manager::GameManager, game_state::GameState,
|
||||
};
|
||||
use tokio_with_wasm::tokio;
|
||||
|
||||
use crate::messages::{
|
||||
error::ReportError,
|
||||
steps::dependencies::{NotifyDependenciesSuccessfullyInstalled, StartDependenciesInstallation},
|
||||
};
|
||||
|
||||
pub async fn listen_dependecies_installation() {
|
||||
let mut receiver = StartDependenciesInstallation::get_dart_signal_receiver();
|
||||
while let Some(_) = receiver.recv().await {
|
||||
let proton_component = ProtonComponent::new(GameState::get_config().await.config_dir);
|
||||
let proton = proton_component.init_proton();
|
||||
if let Err(e) = proton {
|
||||
ReportError {
|
||||
error_message: format!("Failed to install DXVK : {}", e),
|
||||
}
|
||||
.send_signal_to_dart();
|
||||
continue;
|
||||
}
|
||||
|
||||
thread::spawn(move || {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
match GameManager::install_dependencies(&proton.unwrap()).await {
|
||||
Err(e) => ReportError {
|
||||
error_message: format!("Failed to install dependencies : {}", e),
|
||||
}
|
||||
.send_signal_to_dart(),
|
||||
Ok(_) => NotifyDependenciesSuccessfullyInstalled {}.send_signal_to_dart(),
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -16,7 +16,7 @@ use crate::{
|
||||
messages::{
|
||||
error::ReportError,
|
||||
steps::dxvk::{
|
||||
DxvkDownloadProgress, NotifiyDxvkSuccessfullyInstalled, NotifyDxvkStartDecompressing,
|
||||
DxvkDownloadProgress, NotifyDxvkStartDecompressing, NotifyDxvkSuccessfullyInstalled,
|
||||
StartDxvkInstallation,
|
||||
},
|
||||
},
|
||||
@ -76,7 +76,7 @@ pub async fn listen_dxvk_installation() {
|
||||
error_message: format!("Failed to install DXVK : {}", e),
|
||||
}
|
||||
.send_signal_to_dart(),
|
||||
Ok(_) => NotifiyDxvkSuccessfullyInstalled {}.send_signal_to_dart(),
|
||||
Ok(_) => NotifyDxvkSuccessfullyInstalled {}.send_signal_to_dart(),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -8,7 +8,7 @@ use tokio_with_wasm::tokio;
|
||||
use crate::messages::{
|
||||
error::ReportError,
|
||||
steps::fonts::{
|
||||
FontsInstallationProgress, NotifiyFontsSuccessfullyInstalled, StartFontsInstallation,
|
||||
FontsInstallationProgress, NotifyFontsSuccessfullyInstalled, StartFontsInstallation,
|
||||
},
|
||||
};
|
||||
|
||||
@ -41,19 +41,19 @@ pub async fn listen_fonts_installation() {
|
||||
error_message: format!("Failed to install DXVK : {}", e),
|
||||
}
|
||||
.send_signal_to_dart(),
|
||||
Ok(_) => NotifiyFontsSuccessfullyInstalled {}.send_signal_to_dart(),
|
||||
Ok(_) => NotifyFontsSuccessfullyInstalled {}.send_signal_to_dart(),
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
struct InstallationReporterPrivate {
|
||||
struct DownloadReporterPrivate {
|
||||
max_progress: Option<u64>,
|
||||
}
|
||||
|
||||
struct InstallationReporter {
|
||||
private: std::sync::Mutex<Option<InstallationReporterPrivate>>,
|
||||
private: std::sync::Mutex<Option<DownloadReporterPrivate>>,
|
||||
}
|
||||
|
||||
impl InstallationReporter {
|
||||
@ -66,7 +66,7 @@ impl InstallationReporter {
|
||||
|
||||
impl downloader::progress::Reporter for InstallationReporter {
|
||||
fn setup(&self, max_progress: Option<u64>, _: &str) {
|
||||
let private = InstallationReporterPrivate { max_progress };
|
||||
let private = DownloadReporterPrivate { max_progress };
|
||||
|
||||
let mut guard = self.private.lock().unwrap();
|
||||
*guard = Some(private);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use tokio_with_wasm::tokio;
|
||||
|
||||
mod config;
|
||||
mod dependencies;
|
||||
mod dxvk;
|
||||
mod fonts;
|
||||
mod game_state;
|
||||
@ -23,4 +24,5 @@ async fn main() {
|
||||
tokio::spawn(proton::listen_proton_installation());
|
||||
tokio::spawn(dxvk::listen_dxvk_installation());
|
||||
tokio::spawn(fonts::listen_fonts_installation());
|
||||
tokio::spawn(dependencies::listen_dependecies_installation());
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ use crate::{
|
||||
messages::{
|
||||
error::ReportError,
|
||||
steps::proton::{
|
||||
NotifiyProtonSuccessfullyInstalled, NotifyProtonStartDecompressing,
|
||||
NotifyProtonStartDecompressing, NotifyProtonSuccessfullyInstalled,
|
||||
ProtonDownloadProgress, StartProtonInstallation,
|
||||
},
|
||||
},
|
||||
@ -66,7 +66,7 @@ pub async fn listen_proton_installation() {
|
||||
error_message: format!("Failed to install Proton : {}", e),
|
||||
}
|
||||
.send_signal_to_dart(),
|
||||
Ok(_) => NotifiyProtonSuccessfullyInstalled {}.send_signal_to_dart(),
|
||||
Ok(_) => NotifyProtonSuccessfullyInstalled {}.send_signal_to_dart(),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user