can now update the game from the GUI

This commit is contained in:
ALEZ-DEV 2024-06-10 19:47:44 +02:00
parent 9188860db3
commit 62ffdd2dff
6 changed files with 32 additions and 9 deletions

View File

@ -17,8 +17,8 @@ class Game with ChangeNotifier {
Int64 currentProgress = Int64(0);
Int64 maxProgress = Int64(0);
Future startInstallation(GameStateProvider gameState) async {
StartGameInstallation().sendSignalToRust();
Future startInstallation(GameStateProvider gameState, bool isUpdating) async {
StartGameInstallation(isUpdating: isUpdating).sendSignalToRust();
gameInstallationState = GameInstallationState.checkingFile;
notifyListeners();

View File

@ -36,4 +36,8 @@ class GameStateProvider with ChangeNotifier {
_gameState == States.FontNotInstalled ||
_gameState == States.DependecieNotInstalled;
}
bool isGameUpdating() {
return _gameState == States.GameNeedUpdate;
}
}

View File

@ -15,11 +15,12 @@ class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final gameStateProvider = Provider.of<GameStateProvider>(context);
return Stack(
children: [
const ShowBackground(),
Provider.of<GameStateProvider>(context).gameState !=
States.GameInstalled
gameStateProvider.gameState != States.GameInstalled
? const GameSteps()
: Padding(
padding: const EdgeInsets.all(50.0),

View File

@ -35,6 +35,8 @@ class _InstallGame extends StatelessWidget {
@override
Widget build(BuildContext context) {
final gameStateProvider = Provider.of<GameStateProvider>(context);
return Row(
children: [
const Expanded(
@ -56,11 +58,16 @@ class _InstallGame extends StatelessWidget {
onPressed: () async {
Provider.of<Game>(context, listen: false).startInstallation(
Provider.of<GameStateProvider>(context, listen: false),
gameStateProvider.isGameUpdating(),
);
},
child: const Center(
child: Text("Download"),
),
child: gameStateProvider.isGameUpdating()
? const Center(
child: Text("Update"),
)
: const Center(
child: Text("Download"),
),
),
),
],

View File

@ -8,7 +8,9 @@ message GameInstallationProgress {
}
// [RINF:DART-SIGNAL]
message StartGameInstallation {}
message StartGameInstallation {
bool isUpdating = 1;
}
// [RINF:RUST-SIGNAL]
message NotifyGameStartDownloading {}

View File

@ -16,7 +16,7 @@ use crate::messages::{
pub async fn listen_game_installation() {
let mut receiver = StartGameInstallation::get_dart_signal_receiver();
while let Some(_) = receiver.recv().await {
while let Some(info) = receiver.recv().await {
thread::spawn(move || {
debug_print!("start downloading game...");
tokio::runtime::Builder::new_current_thread()
@ -24,6 +24,15 @@ pub async fn listen_game_installation() {
.build()
.unwrap()
.block_on(async {
if info.message.is_updating {
if let Err(e) = GameManager::update_game().await {
ReportError {
error_message: format!("Failed to start updating the game : {}", e),
}
.send_signal_to_dart();
}
}
let game_dir = GameState::get_config().await.config_dir;
match GameManager::install_game(