fix: switching vers fix (#5574)
This commit is contained in:
@@ -92,6 +92,7 @@ import { get_project_versions, get_version } from '@/helpers/cache.js'
|
|||||||
import { profile_listener } from '@/helpers/events.js'
|
import { profile_listener } from '@/helpers/events.js'
|
||||||
import {
|
import {
|
||||||
add_project_from_path,
|
add_project_from_path,
|
||||||
|
add_project_from_version,
|
||||||
duplicate,
|
duplicate,
|
||||||
edit,
|
edit,
|
||||||
get,
|
get,
|
||||||
@@ -351,6 +352,34 @@ async function updateProject(mod: ContentItem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function switchProjectVersion(mod: ContentItem, version: Labrinth.Versions.v2.Version) {
|
||||||
|
try {
|
||||||
|
await remove_project(props.instance.path, mod.file_path!)
|
||||||
|
const newPath = await add_project_from_version(props.instance.path, version.id)
|
||||||
|
|
||||||
|
const profile = await get(props.instance.path).catch(handleError)
|
||||||
|
if (profile) {
|
||||||
|
await installVersionDependencies(profile, version).catch(handleError)
|
||||||
|
}
|
||||||
|
|
||||||
|
mod.file_path = newPath
|
||||||
|
if (mod.version) {
|
||||||
|
mod.version.id = version.id
|
||||||
|
mod.version.version_number = version.version_number
|
||||||
|
}
|
||||||
|
|
||||||
|
trackEvent('InstanceProjectSwitchVersion', {
|
||||||
|
loader: props.instance.loader,
|
||||||
|
game_version: props.instance.game_version,
|
||||||
|
id: mod.project?.id,
|
||||||
|
name: mod.project?.title ?? mod.file_name,
|
||||||
|
project_type: mod.project_type,
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err as Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleUpdate(id: string) {
|
async function handleUpdate(id: string) {
|
||||||
const item = projects.value.find((p) => p.file_name === id)
|
const item = projects.value.find((p) => p.file_name === id)
|
||||||
if (!item?.has_update || !item.project?.id || !item.version?.id) return
|
if (!item?.has_update || !item.project?.id || !item.version?.id) return
|
||||||
@@ -570,9 +599,11 @@ async function handleModalUpdate(
|
|||||||
} else if (updatingProject.value) {
|
} else if (updatingProject.value) {
|
||||||
const mod = updatingProject.value
|
const mod = updatingProject.value
|
||||||
|
|
||||||
mod.update_version_id = selectedVersion.id
|
if (mod.has_update && mod.update_version_id === selectedVersion.id) {
|
||||||
|
await updateProject(mod)
|
||||||
await updateProject(mod)
|
} else {
|
||||||
|
await switchProjectVersion(mod, selectedVersion)
|
||||||
|
}
|
||||||
|
|
||||||
resetUpdateState()
|
resetUpdateState()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user