mirror of
https://github.com/modrinth/code.git
synced 2026-07-31 21:26:40 +00:00
install version matching filters if possible (#6932)
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
|||||||
preferencesDiffer,
|
preferencesDiffer,
|
||||||
provideBrowseManager,
|
provideBrowseManager,
|
||||||
requestInstall,
|
requestInstall,
|
||||||
|
resolveInstallPlan,
|
||||||
stripServerRuntimeInstallFilters,
|
stripServerRuntimeInstallFilters,
|
||||||
stripServerRuntimeInstallOverrides,
|
stripServerRuntimeInstallOverrides,
|
||||||
useBrowseSearch,
|
useBrowseSearch,
|
||||||
@@ -798,6 +799,27 @@ async function chooseInstanceInstallVersion(
|
|||||||
return { versionId: selectedVersion.id }
|
return { versionId: selectedVersion.id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function chooseFilterMatchingInstallVersion(
|
||||||
|
project: Labrinth.Search.v3.ResultSearchProject,
|
||||||
|
projectTypeValue: string,
|
||||||
|
) {
|
||||||
|
const plan = await resolveInstallPlan({
|
||||||
|
project: {
|
||||||
|
project_id: project.project_id,
|
||||||
|
title: project.title,
|
||||||
|
icon_url: project.icon_url,
|
||||||
|
},
|
||||||
|
contentType: projectTypeValue as BrowseInstallContentType,
|
||||||
|
selectedFilters: searchState.currentFilters.value,
|
||||||
|
providedFilters: combinedProvidedFilters.value,
|
||||||
|
overriddenProvidedFilterTypes: searchState.overriddenProvidedFilterTypes.value,
|
||||||
|
targetPreferences: {},
|
||||||
|
getProjectVersions: getInstallProjectVersions,
|
||||||
|
})
|
||||||
|
|
||||||
|
return { versionId: plan.versionId }
|
||||||
|
}
|
||||||
|
|
||||||
function getCardActions(
|
function getCardActions(
|
||||||
result: Labrinth.Search.v3.ResultSearchProject,
|
result: Labrinth.Search.v3.ResultSearchProject,
|
||||||
currentProjectType: string,
|
currentProjectType: string,
|
||||||
@@ -927,7 +949,9 @@ function getCardActions(
|
|||||||
try {
|
try {
|
||||||
const selectedInstall = instance.value
|
const selectedInstall = instance.value
|
||||||
? await chooseInstanceInstallVersion(projectResult, currentProjectType)
|
? await chooseInstanceInstallVersion(projectResult, currentProjectType)
|
||||||
: { versionId: null as string | null }
|
: isModpack
|
||||||
|
? await chooseFilterMatchingInstallVersion(projectResult, currentProjectType)
|
||||||
|
: { versionId: null as string | null }
|
||||||
if (selectedInstall === null) {
|
if (selectedInstall === null) {
|
||||||
setProjectInstalling(projectResult.project_id, false)
|
setProjectInstalling(projectResult.project_id, false)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import type { Labrinth } from '@modrinth/api-client'
|
import type { Labrinth } from '@modrinth/api-client'
|
||||||
import type { ContentInstallInstance, ContentInstallProjectInfo, ContentItem } from '@modrinth/ui'
|
import type { ContentInstallInstance, ContentInstallProjectInfo, ContentItem } from '@modrinth/ui'
|
||||||
import { createContext, defineMessage, useVIntl } from '@modrinth/ui'
|
import {
|
||||||
|
createContext,
|
||||||
|
defineMessage,
|
||||||
|
getLatestMatchingInstallVersion,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||||
import { openUrl } from '@tauri-apps/plugin-opener'
|
import { openUrl } from '@tauri-apps/plugin-opener'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
@@ -813,7 +818,22 @@ export function createContentInstall(opts: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (project.project_type === 'modpack') {
|
if (project.project_type === 'modpack') {
|
||||||
const version = versionId ?? project.versions[project.versions.length - 1]
|
let version = versionId ?? null
|
||||||
|
if (!version) {
|
||||||
|
const hasHints = !!(hints?.preferredGameVersion || hints?.preferredLoader)
|
||||||
|
if (hasHints) {
|
||||||
|
const versions = (await get_version_many(
|
||||||
|
project.versions,
|
||||||
|
'must_revalidate',
|
||||||
|
)) as Labrinth.Versions.v2.Version[]
|
||||||
|
const matching = getLatestMatchingInstallVersion(versions, {
|
||||||
|
gameVersions: hints?.preferredGameVersion ? [hints.preferredGameVersion] : undefined,
|
||||||
|
loaders: hints?.preferredLoader ? [hints.preferredLoader] : undefined,
|
||||||
|
})
|
||||||
|
version = matching?.id ?? null
|
||||||
|
}
|
||||||
|
version ??= project.versions[project.versions.length - 1]
|
||||||
|
}
|
||||||
const packs = await list()
|
const packs = await list()
|
||||||
const existingPack = packs.find((pack) => pack.link?.project_id === project.id)
|
const existingPack = packs.find((pack) => pack.link?.project_id === project.id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user