This commit is contained in:
2025-11-08 17:27:01 +01:00
parent ade0c3fbc4
commit 6845a7d6fe
5 changed files with 120 additions and 6 deletions
+61 -6
View File
@@ -26,6 +26,8 @@ interface Game {
thumbnail: Uint8Array;
installed: boolean;
install_status: InstallStatus;
eti_game_version?: string;
local_version?: string;
}
const App = () => {
@@ -204,6 +206,47 @@ const App = () => {
}
};
const updateGame = async (id: string) => {
console.log(`🎯 Updating game with id=${id}`);
try {
const success = await invoke('install_game', { id });
if (success) {
console.log(`✅ Game update for id=${id} started...`);
// update install status in gameItems for this game
setGameItems(prev => prev.map(item => item.id === id
? { ...item, install_status: InstallStatus.CheckingServer }
: item));
} else {
// game is already being installed
console.warn(`🚧 Game with id=${id} is already being updated`);
}
} catch (error) {
console.error('❌ Error updating game:', error);
}
};
const needsUpdate = (game: Game): boolean => {
if (!game.installed) return false;
// Check if server has a version and we have a local version
const serverVersion = game.eti_game_version;
const localVersion = game.local_version;
// If we don't have local version but server has one, we need update
if (!localVersion && serverVersion) {
return true;
}
// If we have both versions, compare them numerically
if (localVersion && serverVersion) {
const localNum = parseInt(localVersion, 10);
const serverNum = parseInt(serverVersion, 10);
return serverNum > localNum;
}
return false;
};
const dialogGameDir = async () => {
const file = await open({
multiple: false,
@@ -259,14 +302,26 @@ const App = () => {
<span className="size-text">{(item.size / 1024 / 1024 / 1024).toFixed(1)} GB</span>
</div>
<div className="play-button"
onClick={() => item.installed
? runGame(item.id)
: installGame(item.id)}>
{item.installed ? 'Play'
: item.install_status === InstallStatus.CheckingServer ? 'Checking server...'
onClick={() => {
if (!item.installed) {
installGame(item.id);
} else if (needsUpdate(item)) {
updateGame(item.id);
} else {
runGame(item.id);
}
}}>
{!item.installed
? item.install_status === InstallStatus.CheckingServer ? 'Checking server...'
: item.install_status === InstallStatus.Downloading ? 'Downloading...'
: item.install_status === InstallStatus.Unpacking ? 'Unpacking...'
: 'Install'}
: 'Install'
: needsUpdate(item)
? item.install_status === InstallStatus.CheckingServer ? 'Checking server...'
: item.install_status === InstallStatus.Downloading ? 'Downloading...'
: item.install_status === InstallStatus.Unpacking ? 'Unpacking...'
: 'Update'
: 'Play'}
</div>
</div>
);