This commit is contained in:
Tickbase
2025-05-18 02:57:09 +02:00
parent e29f44bbd5
commit 28a86771fa

View File

@@ -381,15 +381,21 @@ function App() {
setProgressDialog((prev) => ({ ...prev, visible: false })) setProgressDialog((prev) => ({ ...prev, visible: false }))
// Only refresh if we need to (instructions didn't trigger update) // Only refresh if we need to (instructions didn't trigger update)
if (progressDialog.showInstructions === false && !refreshInProgress.current) { if (
refreshInProgress.current = true progressDialog.showInstructions === false &&
!progressDialog.title.includes("DLC") &&
!progressDialog.title.includes("Updating") &&
!progressDialog.title.includes("Update") &&
!refreshInProgress.current
) {
refreshInProgress.current = true;
setTimeout(() => { setTimeout(() => {
loadGames().then(() => { loadGames().then(() => {
refreshInProgress.current = false refreshInProgress.current = false;
}) });
}, 100) }, 100);
}
} }
};
// Function to fetch DLCs for a game with streaming updates // Function to fetch DLCs for a game with streaming updates
const streamGameDlcs = async (gameId: string): Promise<void> => { const streamGameDlcs = async (gameId: string): Promise<void> => {
@@ -672,22 +678,20 @@ function App() {
// Handle DLC selection confirmation // Handle DLC selection confirmation
const handleDlcConfirm = async (selectedDlcs: DlcInfo[]) => { const handleDlcConfirm = async (selectedDlcs: DlcInfo[]) => {
// The dialog has already started its exit animation // The dialog has already started its exit animation
// Just make sure it's marked as invisible setDlcDialog((prev) => ({ ...prev, visible: false }));
setDlcDialog((prev) => ({ ...prev, visible: false }))
const gameId = dlcDialog.gameId const gameId = dlcDialog.gameId;
const game = games.find((g) => g.id === gameId) const game = games.find((g) => g.id === gameId);
if (!game) return if (!game) return;
// Update local state to show installation in progress // Update local state to show installation in progress
setGames((prevGames) => setGames((prevGames) =>
prevGames.map((g) => (g.id === gameId ? { ...g, installing: true } : g)) prevGames.map((g) => (g.id === gameId ? { ...g, installing: true } : g))
) );
try { try {
if (dlcDialog.isEditMode) { if (dlcDialog.isEditMode) {
// If in edit mode, we're updating existing cream_api.ini // If in edit mode, we're updating existing cream_api.ini
// Show progress dialog for editing
setProgressDialog({ setProgressDialog({
visible: true, visible: true,
title: `Updating DLCs for ${game.title}`, title: `Updating DLCs for ${game.title}`,
@@ -695,13 +699,13 @@ function App() {
progress: 30, progress: 30,
showInstructions: false, showInstructions: false,
instructions: undefined, instructions: undefined,
}) });
// Call the backend to update the DLC configuration // Call the backend to update the DLC configuration
await invoke('update_dlc_configuration_command', { await invoke('update_dlc_configuration_command', {
gamePath: game.path, gamePath: game.path,
dlcs: selectedDlcs, dlcs: selectedDlcs,
}) });
// Update progress dialog for completion // Update progress dialog for completion
setProgressDialog((prev) => ({ setProgressDialog((prev) => ({
@@ -709,21 +713,22 @@ function App() {
title: `Update Complete: ${game.title}`, title: `Update Complete: ${game.title}`,
message: 'DLC configuration updated successfully!', message: 'DLC configuration updated successfully!',
progress: 100, progress: 100,
})) }));
// The ProgressDialog component will now handle the exit animation // Most importantly: directly update the local state instead of waiting for a full scan
// when progress reaches 100% after a delay // This is what prevents the need for a full scan
// But we still need to reset installing state with a delay
setTimeout(() => { setTimeout(() => {
// Reset installing state // Reset installing state and update the game in the local state
setGames((prevGames) => setGames((prevGames) =>
prevGames.map((g) => (g.id === gameId ? { ...g, installing: false } : g)) prevGames.map((g) => (g.id === gameId ? {
) ...g,
}, 2000) installing: false,
// No other properties should need updating for a DLC config change
} : g))
);
}, 2000);
} else { } else {
// We're doing a fresh install with selected DLCs // We're doing a fresh install with selected DLCs - original code unchanged
// Show progress dialog for installation right away
setProgressDialog({ setProgressDialog({
visible: true, visible: true,
title: `Installing CreamLinux for ${game.title}`, title: `Installing CreamLinux for ${game.title}`,
@@ -731,38 +736,32 @@ function App() {
progress: 0, progress: 0,
showInstructions: false, showInstructions: false,
instructions: undefined, instructions: undefined,
}) });
// Invoke the installation with the selected DLCs
await invoke('install_cream_with_dlcs_command', { await invoke('install_cream_with_dlcs_command', {
gameId, gameId,
selectedDlcs, selectedDlcs,
}).catch((err) => { }).catch((err) => {
console.error(`Error installing CreamLinux with selected DLCs:`, err) console.error(`Error installing CreamLinux with selected DLCs:`, err);
throw err throw err;
}) });
// We don't need to manually close the dialog or update the game state
// because the backend will emit progress events that handle this
} }
} catch (error) { } catch (error) {
console.error('Error processing DLC selection:', error) console.error('Error processing DLC selection:', error);
// Show error in progress dialog // Show error in progress dialog
setProgressDialog((prev) => ({ setProgressDialog((prev) => ({
...prev, ...prev,
message: `Error: ${error}`, message: `Error: ${error}`,
progress: 100, progress: 100,
})) }));
// Reset installing state // Reset installing state
setGames((prevGames) => setGames((prevGames) =>
prevGames.map((g) => (g.id === gameId ? { ...g, installing: false } : g)) prevGames.map((g) => (g.id === gameId ? { ...g, installing: false } : g))
) );
// ProgressDialog will handle exit animation automatically
}
} }
};
// Update DLCs being streamed with enabled state // Update DLCs being streamed with enabled state
useEffect(() => { useEffect(() => {