|
3 | 3 | * We do not need to recalculate on a per-usage basis. |
4 | 4 | */ |
5 | 5 | import { getStore } from '@r2/providers/generic/store/StoreProvider'; |
6 | | -import { computed, ref, watch } from 'vue'; |
| 6 | +import { computed, onMounted, ref, watch } from 'vue'; |
7 | 7 | import ManifestV2 from '@r2/model/ManifestV2'; |
8 | 8 | import ThunderstoreMod from '@r2/model/ThunderstoreMod'; |
| 9 | +import VersionNumber from '@r2/model/VersionNumber'; |
| 10 | +import * as PackageDb from "@r2/r2mm/manager/PackageDexieStore"; |
| 11 | + |
| 12 | +type ConcerningPackage = { |
| 13 | + fullName: string; |
| 14 | + latestVersion: string; |
| 15 | +} |
9 | 16 |
|
10 | 17 | const store = getStore<any>(); |
11 | 18 |
|
| 19 | +const activeGame = computed(() => store.state.activeGame); |
| 20 | + |
12 | 21 | const localModList = computed<ManifestV2[]>(() => store.state.profile.modList); |
13 | | -const onlineModList = computed<Map<string, ThunderstoreMod>>(() => { |
| 22 | +const onlineModList = computed<Map<string, ConcerningPackage>>(() => { |
14 | 23 | const mods: ThunderstoreMod[] = store.state.tsMods.mods; |
15 | | - return new Map<string, ThunderstoreMod>(mods.map(value => [value.getFullName(), value])); |
| 24 | + return new Map<string, ConcerningPackage>(mods.map(value => [value.getFullName(), { |
| 25 | + fullName: value.getFullName(), |
| 26 | + latestVersion: value.getLatestVersion(), |
| 27 | + }])); |
16 | 28 | }); |
17 | 29 |
|
18 | | -const allConcerningPackages = computed<ManifestV2[]>(() => { |
19 | | - return localModList.value.filter(value => (value.isOnlineSource() && !onlineModList.value.has(value.getName()))); |
20 | | -}); |
| 30 | +const allConcerningPackages = ref<ManifestV2[]>([]); |
| 31 | +const activeConcerningPackages = ref<ManifestV2[]>([]); |
| 32 | + |
| 33 | +async function updateConcerningPackages() { |
| 34 | + const game = activeGame.value; |
| 35 | + const localMods = localModList.value; |
| 36 | + const concerningPackages = []; |
21 | 37 |
|
22 | | -const activeConcerningPackages = computed<ManifestV2[]>(() => { |
23 | | - return allConcerningPackages.value.filter(value => !value.isTrustedPackage() && (value.isOnlineSource() && !onlineModList.value.has(value.getName()))); |
| 38 | + for (const mod of localMods) { |
| 39 | + if (!mod.isOnlineSource()) { |
| 40 | + continue; |
| 41 | + } |
| 42 | + if (!onlineModList.value.has(mod.getName())) { |
| 43 | + concerningPackages.push(mod); |
| 44 | + continue; |
| 45 | + } |
| 46 | + const packageVersionNumbers = await PackageDb.getPackageVersionNumbers( |
| 47 | + game.internalFolderName, |
| 48 | + mod.getName() |
| 49 | + ); |
| 50 | + const dnf = !packageVersionNumbers.find(ver => ver === mod.getVersionNumber().toString()); |
| 51 | + if (dnf) { |
| 52 | + concerningPackages.push(mod); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + allConcerningPackages.value = concerningPackages; |
| 57 | + activeConcerningPackages.value = concerningPackages.filter(value => !value.isTrustedPackage()); |
| 58 | +} |
| 59 | + |
| 60 | +watch([activeGame, localModList], async () => { |
| 61 | + await updateConcerningPackages(); |
24 | 62 | }); |
25 | 63 |
|
26 | 64 | export function useConcerningPackageComposable() { |
27 | 65 |
|
| 66 | + onMounted(async () => { |
| 67 | + await updateConcerningPackages(); |
| 68 | + }); |
| 69 | + |
28 | 70 | const hasConcerningPackages = computed<boolean>(() => activeConcerningPackages.value.length > 0); |
29 | 71 |
|
30 | 72 | function isConcerningPackage(mod: ManifestV2) { |
|
0 commit comments