-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: PoC of mod download/install through vuex store
- Loading branch information
1 parent
5e73a77
commit 81bdd75
Showing
3 changed files
with
87 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ActionTree, GetterTree } from 'vuex'; | ||
|
||
import { State as RootState } from '../index'; | ||
import StatusEnum from '../../model/enums/StatusEnum'; | ||
import { ImmutableProfile } from '../../model/Profile'; | ||
import ThunderstoreCombo from '../../model/ThunderstoreCombo'; | ||
import ThunderstoreDownloaderProvider from '../../providers/ror2/downloading/ThunderstoreDownloaderProvider'; | ||
|
||
interface Progress { | ||
progress: number; | ||
status: number; // StatusEnum | ||
} | ||
|
||
interface ModProgressItem { | ||
mod: ThunderstoreCombo; | ||
installProgress: Progress; | ||
downloadProgress: Progress; | ||
} | ||
|
||
interface State { | ||
allDownloads: ModProgressItem[]; | ||
} | ||
|
||
/** | ||
* State for Mod Downloadning/Installation. | ||
*/ | ||
export default { | ||
namespaced: true, | ||
|
||
state: (): State => ({ | ||
allDownloads: [], | ||
}), | ||
|
||
getters: <GetterTree<State, RootState>>{ | ||
activeDownload(state): ModProgressItem { | ||
return state.allDownloads.slice(-1)[0]; // Last element of the array | ||
}, | ||
allDownloads(state): ModProgressItem[] { | ||
return state.allDownloads; | ||
}, | ||
}, | ||
mutations: {}, | ||
actions: <ActionTree<State, RootState>>{ | ||
async downloadAndInstallMod( | ||
{dispatch, getters, state}, | ||
params: { | ||
profile: ImmutableProfile, | ||
mods: ThunderstoreCombo[], | ||
} | ||
) { | ||
params.mods.forEach((mod) => { | ||
state.allDownloads.push({ | ||
mod: mod, | ||
installProgress: { progress: 0, status: StatusEnum.PENDING }, | ||
downloadProgress: { progress: 0, status: StatusEnum.PENDING } | ||
}); | ||
ThunderstoreDownloaderProvider.instance.download( | ||
params.profile, | ||
mod.getMod(), | ||
mod.getVersion(), | ||
false, | ||
(progress, modName, status) => { | ||
const index = state.allDownloads.findIndex((modProgressItem) => modProgressItem.mod.getMod().getFullName() === modName); | ||
state.allDownloads[index].downloadProgress = { progress: progress, status: status }; | ||
}, | ||
() => {} | ||
); | ||
|
||
}) | ||
}, | ||
}, | ||
} |