game action hook

This commit is contained in:
Novattz
2026-01-17 17:56:07 +01:00
parent ef7dfdd6c5
commit a786530572

View File

@@ -4,6 +4,7 @@ import { listen } from '@tauri-apps/api/event'
import { ActionType } from '@/components/buttons/ActionButton' import { ActionType } from '@/components/buttons/ActionButton'
import { Game, DlcInfo } from '@/types' import { Game, DlcInfo } from '@/types'
import { InstallationInstructions } from '@/contexts/AppContext' import { InstallationInstructions } from '@/contexts/AppContext'
import { useUnlockerSelection } from './useUnlockerSelection'
/** /**
* Hook for managing game action operations * Hook for managing game action operations
@@ -79,22 +80,38 @@ export function useGameActions() {
setProgressDialog((prev) => ({ ...prev, visible: false })) setProgressDialog((prev) => ({ ...prev, visible: false }))
}, []) }, [])
// Unlocker selection hook for native games
const {
selectionState,
showUnlockerSelection,
handleSelectCreamLinux,
handleSelectSmokeAPI,
closeDialog: closeUnlockerDialog,
} = useUnlockerSelection()
// Unified handler for game actions (install/uninstall) // Unified handler for game actions (install/uninstall)
const handleGameAction = useCallback( const handleGameAction = useCallback(
async (gameId: string, action: ActionType, games: Game[]) => { async (gameId: string, action: ActionType, games: Game[]) => {
try { try {
// For CreamLinux installation, we should NOT call process_game_action directly // Find the game
// Instead, we show the DLC selection dialog first, which is handled in AppProvider const game = games.find((g) => g.id === gameId)
if (!game) return
// For CreamLinux installation, DLC dialog is handled in AppProvider
if (action === 'install_cream') { if (action === 'install_cream') {
return return
} }
// For other actions (uninstall_cream, install_smoke, uninstall_smoke) // Handle generic "install_unlocker" action for native games
// Find game to get title if (action === 'install_unlocker') {
const game = games.find((g) => g.id === gameId) showUnlockerSelection(game, (chosenAction: ActionType) => {
if (!game) return // User chose, now proceed with that action
handleGameAction(gameId, chosenAction, games)
})
return
}
// Get title based on action // For other actions (uninstall_cream, install_smoke, uninstall_smoke)
const isCream = action.includes('cream') const isCream = action.includes('cream')
const isInstall = action.includes('install') const isInstall = action.includes('install')
const product = isCream ? 'CreamLinux' : 'SmokeAPI' const product = isCream ? 'CreamLinux' : 'SmokeAPI'
@@ -138,7 +155,7 @@ export function useGameActions() {
throw error throw error
} }
}, },
[] [showUnlockerSelection]
) )
// Handle DLC selection confirmation // Handle DLC selection confirmation
@@ -231,5 +248,9 @@ export function useGameActions() {
handleCloseProgressDialog, handleCloseProgressDialog,
handleGameAction, handleGameAction,
handleDlcConfirm, handleDlcConfirm,
unlockerSelectionDialog: selectionState,
handleSelectCreamLinux,
handleSelectSmokeAPI,
closeUnlockerDialog,
} }
} }