Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions apps/app-frontend/src/pages/instance/Mods.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { get_project_versions, get_version } from '@/helpers/cache.js'
import { profile_listener } from '@/helpers/events.js'
import {
add_project_from_path,
add_project_from_version,
duplicate,
edit,
get,
Expand Down Expand Up @@ -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) {
const item = projects.value.find((p) => p.file_name === id)
if (!item?.has_update || !item.project?.id || !item.version?.id) return
Expand Down Expand Up @@ -570,9 +599,11 @@ async function handleModalUpdate(
} else if (updatingProject.value) {
const mod = updatingProject.value
mod.update_version_id = selectedVersion.id
await updateProject(mod)
if (mod.has_update && mod.update_version_id === selectedVersion.id) {
await updateProject(mod)
} else {
await switchProjectVersion(mod, selectedVersion)
}
resetUpdateState()
}
Expand Down
Loading