mirror of
https://github.com/modrinth/code.git
synced 2026-08-26 01:26:23 +00:00
* feat: implement instance share page + search_users backend call * feat: invite players modal * feat: use tanstack queries for friends sync across app pages * feat: base shared instances implementation * fix: admon style * feat: impl instance admonitions like server panel * fix: impl get + del usage * feat: support modpack links * feat: invite notif accepting * fix: lint + fmt * feat: impl install to play * feat: impl usage of UpdateToPlayModal * feat: warnings on deleting/disabling shared-instance version content * fix: send instance name * feat: align with backend * feat: shared instances qa * feat: wrong account protection * feat: qa * fix: smartly apply updates * fix: install bug * fix: 401/404 differentiation * fix: fmt+prepr * feat: qa * feat: qa * fix: signing out messes up revoke/deleted checks * feat: qa * fix: fmt + lint * feat: lock content if part of shared instance * fix: lint * [do not merge] feat: rough invite links impl temp (#6666) * fix: wrong cmd * feat: invite page * fix: server-manager DTO mismatch * fix: drop anonymous invite link acceptance * refactor: structured shared-instance unavailable errors * refactor: centralise error presentations * refactor: dedupe shared instance diff detection * fix: logging in reqwests * refactor: move app.vue shared instances into handler * refactor: break up Share.vue * refactor: split up shared instances state outside of instance index * refactor: dedicated shared instances install/update modals + split up page * refactor: centralized managed content * refactor: split up install shared to own runner + shared.rs split up * refactor: dedupe sql for instance metadata enrichmnt * refactor: friends composable + dedupe friends logic across usages * chore: reduced unused code * fix: align with backend * fix: lint * fix: file sha changes * fix: invite links not working due to icon signed * feat: qa * feat: reporting frontend dummy * fix: try use header * remove: file hash field * fix: pin box * feat: malware warning for shared instances * fix: cache rule * feat: config files syncing * feat: disable config sharing * fix: header * fix: use mark ready * fix: dont cause push update for configs * fix: lint * feat: sharing page in settings * feat: move config + change flow * fix: qa * fix: lint prepr * feat: proxy file upload thru shared instances backend * fix: use collapisible * fix: push config * fix: config * feat: swap out sign in modal for new one * fix: report flow * fix: exclude configs.zip from external warnings * fix: nuxi init * fix: config bundle downloading * fix: error notif * fix: polling * fix: qa * fix: lint + prepr * feat: shared instances moderation frontend + hook up report flow * fix: report copy * fix: lint * fix: lint * fix: modrinth ids being undefined * feat: instance quarantining * fix: prepr + fmt * fix: quarantined -> locked terminology * fix: missing endpoint impls + fmt * fix: missing api in build.rs * fix: share tab jittery * fix: fmt *PT bug * fix: invites count as users even if pending * fix: prepr * fix: invite page owner in users list * fix: lint * fix: qa * fix: lint * fix: members stale not clearing * fix: invite use joined_at field * fix: lint * fix: qa --------- Co-authored-by: sychic <47618543+Sychic@users.noreply.github.com>
279 lines
8.0 KiB
Vue
279 lines
8.0 KiB
Vue
<script setup>
|
|
import {
|
|
DownloadIcon,
|
|
GameIcon,
|
|
PlayIcon,
|
|
SpinnerIcon,
|
|
StopCircleIcon,
|
|
TimerIcon,
|
|
} from '@modrinth/assets'
|
|
import { Avatar, ButtonStyled, injectNotificationManager, useRelativeTime } from '@modrinth/ui'
|
|
import { convertFileSrc } from '@tauri-apps/api/core'
|
|
import dayjs from 'dayjs'
|
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
|
|
import { trackEvent } from '@/helpers/analytics'
|
|
import { process_listener } from '@/helpers/events'
|
|
import { install_existing_instance, install_pack_to_existing_instance } from '@/helpers/install'
|
|
import { kill, run } from '@/helpers/instance'
|
|
import { get_by_instance_id } from '@/helpers/process'
|
|
import { showInstanceInFolder } from '@/helpers/utils.js'
|
|
import { handleSevereError } from '@/store/error.js'
|
|
|
|
const { handleError } = injectNotificationManager()
|
|
const formatRelativeTime = useRelativeTime()
|
|
|
|
const props = defineProps({
|
|
instance: {
|
|
type: Object,
|
|
default() {
|
|
return {}
|
|
},
|
|
},
|
|
compact: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
first: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
})
|
|
|
|
const playing = ref(false)
|
|
const loading = ref(false)
|
|
const modLoading = computed(
|
|
() =>
|
|
loading.value ||
|
|
currentEvent.value === 'installing' ||
|
|
(currentEvent.value === 'launched' && !playing.value),
|
|
)
|
|
const installing = computed(() => props.instance.install_stage.includes('installing'))
|
|
const installed = computed(() => props.instance.install_stage === 'installed')
|
|
|
|
const router = useRouter()
|
|
|
|
const seeInstance = async () => {
|
|
await router.push(`/instance/${encodeURIComponent(props.instance.id)}`)
|
|
}
|
|
|
|
const checkProcess = async () => {
|
|
const runningProcesses = await get_by_instance_id(props.instance.id).catch(handleError)
|
|
|
|
playing.value = runningProcesses.length > 0
|
|
}
|
|
|
|
const play = async (e, context) => {
|
|
e?.stopPropagation()
|
|
if (props.instance.quarantined) return
|
|
loading.value = true
|
|
await run(props.instance.id)
|
|
.catch((err) => handleSevereError(err, { instanceId: props.instance.id }))
|
|
.finally(() => {
|
|
trackEvent('InstanceStart', {
|
|
loader: props.instance.loader,
|
|
game_version: props.instance.game_version,
|
|
source: context,
|
|
})
|
|
})
|
|
loading.value = false
|
|
}
|
|
|
|
const stop = async (e, context) => {
|
|
e?.stopPropagation()
|
|
playing.value = false
|
|
|
|
await kill(props.instance.id).catch(handleError)
|
|
|
|
trackEvent('InstanceStop', {
|
|
loader: props.instance.loader,
|
|
game_version: props.instance.game_version,
|
|
source: context,
|
|
})
|
|
}
|
|
|
|
const repair = async (e) => {
|
|
e?.stopPropagation()
|
|
if (props.instance.quarantined) return
|
|
|
|
if (
|
|
props.instance.install_stage !== 'pack_installed' &&
|
|
(props.instance.link?.type === 'modrinth_modpack' ||
|
|
props.instance.link?.type === 'server_project_modpack')
|
|
) {
|
|
await install_pack_to_existing_instance(props.instance.id, {
|
|
type: 'fromVersionId',
|
|
project_id: props.instance.link.project_id ?? props.instance.link.server_project_id ?? '',
|
|
version_id: props.instance.link.version_id ?? props.instance.link.content_version_id ?? '',
|
|
title: props.instance.name,
|
|
}).catch(handleError)
|
|
} else {
|
|
await install_existing_instance(props.instance.id, false).catch(handleError)
|
|
}
|
|
}
|
|
|
|
const openFolder = async () => {
|
|
await showInstanceInFolder(props.instance.id)
|
|
}
|
|
|
|
const addContent = async () => {
|
|
if (props.instance.quarantined) return
|
|
await router.push({
|
|
path: `/browse/${props.instance.loader === 'vanilla' ? 'datapack' : 'mod'}`,
|
|
query: { i: props.instance.id },
|
|
})
|
|
}
|
|
|
|
defineExpose({
|
|
play,
|
|
stop,
|
|
seeInstance,
|
|
openFolder,
|
|
addContent,
|
|
instance: props.instance,
|
|
})
|
|
|
|
const currentEvent = ref(null)
|
|
|
|
const unlisten = await process_listener((e) => {
|
|
if (e.instance_id === props.instance.id) {
|
|
currentEvent.value = e.event
|
|
if (e.event === 'finished') {
|
|
playing.value = false
|
|
}
|
|
}
|
|
})
|
|
|
|
onMounted(() => {
|
|
checkProcess()
|
|
})
|
|
onUnmounted(() => unlisten())
|
|
</script>
|
|
|
|
<template>
|
|
<template v-if="compact">
|
|
<div
|
|
class="card-shadow grid grid-cols-[auto_1fr_auto] bg-bg-raised rounded-xl p-3 pl-4 gap-2 cursor-pointer hover:brightness-90 transition-all"
|
|
@click="seeInstance"
|
|
@mouseenter="checkProcess"
|
|
>
|
|
<Avatar
|
|
size="48px"
|
|
:src="instance.icon_path ? convertFileSrc(instance.icon_path) : null"
|
|
:tint-by="instance.id"
|
|
alt="Mod card"
|
|
/>
|
|
<div class="h-full flex items-center font-bold text-contrast leading-normal">
|
|
<span class="line-clamp-2">{{ instance.name }}</span>
|
|
</div>
|
|
<div class="flex items-center">
|
|
<ButtonStyled v-if="playing" color="red" circular @mousehover="checkProcess">
|
|
<button v-tooltip="'Stop'" @click="(e) => stop(e, 'InstanceCard')">
|
|
<StopCircleIcon />
|
|
</button>
|
|
</ButtonStyled>
|
|
<ButtonStyled v-else-if="modLoading" color="standard" circular>
|
|
<button v-tooltip="'Instance is loading...'" disabled>
|
|
<SpinnerIcon class="animate-spin" />
|
|
</button>
|
|
</ButtonStyled>
|
|
<ButtonStyled
|
|
v-else-if="!instance.quarantined"
|
|
:color="first ? 'brand' : 'standard'"
|
|
circular
|
|
>
|
|
<button
|
|
v-tooltip="'Play'"
|
|
@click="(e) => play(e, 'InstanceCard')"
|
|
@mousehover="checkProcess"
|
|
>
|
|
<!-- Translate for optical centering -->
|
|
<PlayIcon class="translate-x-[1px]" />
|
|
</button>
|
|
</ButtonStyled>
|
|
</div>
|
|
<div class="flex items-center col-span-3 gap-1 text-secondary font-semibold">
|
|
<TimerIcon />
|
|
<span class="text-sm">
|
|
<template v-if="instance.last_played">
|
|
Played {{ formatRelativeTime(dayjs(instance.last_played).toISOString()) }}
|
|
</template>
|
|
<template v-else> Never played </template>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
<div v-else>
|
|
<div
|
|
class="button-base bg-bg-raised p-4 rounded-xl flex gap-3 group"
|
|
@click="seeInstance"
|
|
@mouseenter="checkProcess"
|
|
>
|
|
<div class="relative flex items-center justify-center">
|
|
<Avatar
|
|
size="48px"
|
|
:src="instance.icon_path ? convertFileSrc(instance.icon_path) : null"
|
|
:tint-by="instance.id"
|
|
alt="Mod card"
|
|
:class="`transition-all ${modLoading || installing ? `brightness-[0.25] scale-[0.85]` : `group-hover:brightness-75`}`"
|
|
/>
|
|
<div class="absolute inset-0 flex items-center justify-center">
|
|
<ButtonStyled v-if="playing" size="large" color="red" circular>
|
|
<button
|
|
v-tooltip="'Stop'"
|
|
:class="{ 'scale-100 opacity-100': playing }"
|
|
class="transition-all scale-75 origin-bottom opacity-0 card-shadow"
|
|
@click="(e) => stop(e, 'InstanceCard')"
|
|
@mousehover="checkProcess"
|
|
>
|
|
<StopCircleIcon />
|
|
</button>
|
|
</ButtonStyled>
|
|
<SpinnerIcon
|
|
v-else-if="modLoading || installing"
|
|
v-tooltip="modLoading ? 'Instance is loading...' : 'Installing...'"
|
|
class="animate-spin w-8 h-8"
|
|
tabindex="-1"
|
|
/>
|
|
<ButtonStyled
|
|
v-else-if="!installed && !instance.quarantined"
|
|
size="large"
|
|
color="brand"
|
|
circular
|
|
>
|
|
<button
|
|
v-tooltip="'Repair'"
|
|
class="transition-all scale-75 group-hover:scale-100 group-focus-within:scale-100 origin-bottom opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 card-shadow"
|
|
@click="(e) => repair(e)"
|
|
>
|
|
<DownloadIcon />
|
|
</button>
|
|
</ButtonStyled>
|
|
<ButtonStyled v-else-if="!instance.quarantined" size="large" color="brand" circular>
|
|
<button
|
|
v-tooltip="'Play'"
|
|
class="transition-all scale-75 group-hover:scale-100 group-focus-within:scale-100 origin-bottom opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 card-shadow"
|
|
@click="(e) => play(e, 'InstanceCard')"
|
|
@mousehover="checkProcess"
|
|
>
|
|
<PlayIcon class="translate-x-[2px]" />
|
|
</button>
|
|
</ButtonStyled>
|
|
</div>
|
|
</div>
|
|
<div class="flex flex-col gap-1">
|
|
<p class="m-0 text-md font-bold text-contrast leading-tight line-clamp-1">
|
|
{{ instance.name }}
|
|
</p>
|
|
<div class="flex items-center col-span-3 gap-1 text-secondary font-semibold mt-auto">
|
|
<GameIcon class="shrink-0" />
|
|
<span class="text-sm capitalize">
|
|
{{ instance.loader }} {{ instance.game_version }}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|