import { PackageInfo , InstallResultData } from '@/types/base' ; import { ipcRenderer } from 'electron' ; export default { state : { basePackagesList : [ ] , isInstalling : false , uninstalledPackagesList : [ ] , selectedInstalledPackagesList : [ ] , currentStep : 0 , pkgInstallStep : 0 , pkgInstallStatuses : [ ] , installResult : [ ] , packageDetailVisible : false , currentPackageInfo : { } , } , reducers : { updateBasePackagesList ( prevState , basePackagesList ) { prevState . basePackagesList = basePackagesList ; } , updateInstallStatus ( prevState , isInstalling ) { prevState . isInstalling = isInstalling ; } , updateUninstalledPackagesList ( prevState , uninstalledPackagesList ) { prevState . uninstalledPackagesList = uninstalledPackagesList ; } , updateCurrentStep ( prevState , step ) { prevState . currentStep = step ; } , updatePkgInstallStep ( prevState , step ) { prevState . pkgInstallStep = step ; } , updatePkgInstallStepStatus ( prevState , { step , status } ) { prevState . pkgInstallStatuses [ step ] . status = status ; } , initStep ( prevState , selectedInstalledPackagesList ) { prevState . currentStep = 1 ; prevState . pkgInstallStep = 0 ; prevState . pkgInstallStatuses = selectedInstalledPackagesList . map ( ( { id } ) => ( { id , status : 'wait' } ) ) ; prevState . selectedInstalledPackagesList = selectedInstalledPackagesList ; prevState . installResult = [ ] ; } , updateInstallResult ( prevState , installResult ) { prevState . installResult = installResult ; } , setPackageDetailVisible ( prevState , packageDetailVisible ) { prevState . packageDetailVisible = packageDetailVisible ; } , setCurrentPackageInfo ( prevState , packageInfo ) { prevState . currentPackageInfo = packageInfo ; } , } , effects : ( dispatch ) => ( { async getBasePackages ( force = false ) { const data = await ipcRenderer . invoke ( 'get-base-packages-info' , force ) ; dispatch . dashboard . updateBasePackagesList ( data ) ; const packagesList = data . filter ( ( basePackage ) => { return basePackage . versionStatus !== 'installed' ; } ) ; dispatch . dashboard . updateUninstalledPackagesList ( packagesList ) ; } , async clearCaches ( { processChannel , installChannel } ) { await ipcRenderer . invoke ( 'clear-base-packages-install-cache' , { processChannel , installChannel } ) ; } , async getCaches ( { processChannel , installChannel } ) { const { processCaches } = await ipcRenderer . invoke ( 'get-node-install-cache' , { processChannel , installChannel } ) ; if ( Array . isArray ( processCaches ) ) { processCaches . forEach ( ( { currentIndex , status , result } ) => { if ( status === 'done' ) { dispatch . dashboard . updateCurrentStep ( 2 ) ; dispatch . dashboard . updateInstallResult ( result ) ; } else { dispatch . dashboard . updatePkgInstallStepStatus ( { status , step : currentIndex } ) ; } } ) ; } } , } ) , } ;