Skip to content

Commit

Permalink
fix: Reduce the duration of wrong state on the install button in curs…
Browse files Browse the repository at this point in the history
…eforge and modrinth
  • Loading branch information
ci010 committed Dec 22, 2022
1 parent 6a15a89 commit bf1aa59
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
24 changes: 13 additions & 11 deletions xmcl-keystone-ui/src/views/CurseforgeProjectFilesTile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@
<v-btn
text
icon
:loading="isDownloading"
:loading="installingVersion || isDownloading"
@click="onClick(source)"
@mouseenter="onMouseEnter($event, hasDownloaded)"
@mouseleave="onMouseLeave($event, hasDownloaded)"
>
<template #loader>
<v-progress-circular
:indeterminate="installingVersion && !name"
:value="percentage"
:size="24"
:width="2"
Expand All @@ -70,21 +71,22 @@ import { File } from '@xmcl/curseforge'
import { useTask } from '@/composables/task'
import { getColorForReleaseType } from '@/util/color'
import { getLocalDateString } from '@/util/date'
import { useServiceBusy } from '@/composables'
import { CurseForgeServiceKey } from '@xmcl/runtime-api'
const props = withDefaults(
defineProps<{
source: File
isDownloaded(file: File): boolean
install(file: File): Promise<void>
onMouseEnter(e: MouseEvent, downloaded: boolean): void
onMouseLeave(e: MouseEvent, downloaded: boolean): void
}>(), {},
)
const props = defineProps<{
source: File
isDownloaded(file: File): boolean
install(file: File): Promise<void>
onMouseEnter(e: MouseEvent, downloaded: boolean): void
onMouseLeave(e: MouseEvent, downloaded: boolean): void
}>()
const { name, progress, total } = useTask(t => t.path === 'installCurseforgeFile' && t.param.fileId === props.source.id)
const isDownloading = computed(() => !!name.value)
const percentage = computed(() => progress.value / total.value * 100)
const percentage = computed(() => name.value ? (progress.value / total.value * 100) : -1)
const hasDownloaded = computed(() => props.isDownloaded(props.source))
const installingVersion = useServiceBusy(CurseForgeServiceKey, 'installFile', computed(() => props.source.id.toString()))
const releases = ['', 'R', 'A', 'B']
const getColor = getColorForReleaseType
const onClick = (file: File) => {
Expand Down
8 changes: 6 additions & 2 deletions xmcl-keystone-ui/src/views/ModrinthProjectVersionsTile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
v-if="!isDownloaded(version)"
icon
text
:loading="relatedTasks[version.id]"
:loading="installingVersion || relatedTasks[version.id]"
:disabled="isDownloaded(version)"
@click.stop="onInstall(version)"
>
<template #loader>
<v-progress-circular
:size="24"
:width="3"
:value="relatedTasks[version.id].progress / relatedTasks[version.id].total * 100"
:indeterminate="installingVersion && !relatedTasks[version.id]"
:value="relatedTasks[version.id] ? (relatedTasks[version.id].progress / relatedTasks[version.id].total * 100) : undefined"
/>
</template>
<v-icon class="material-icons-outlined">
Expand Down Expand Up @@ -91,6 +92,8 @@ import Markdown from 'markdown-it'
import { getLocalDateString } from '@/util/date'
import { getColorForReleaseType } from '@/util/color'
import { TaskItem } from '@/entities/task'
import { useServiceBusy } from '@/composables'
import { ModrinthServiceKey } from '@xmcl/runtime-api'
const props = defineProps<{
source: ProjectVersion
Expand All @@ -105,6 +108,7 @@ const { t } = useI18n()
const markdown = new Markdown({
html: true,
})
const installingVersion = useServiceBusy(ModrinthServiceKey, 'installVersion', computed(() => props.source.id))
const render = (s: string) => {
return markdown.render(s)
}
Expand Down
2 changes: 0 additions & 2 deletions xmcl-runtime/lib/resourceCore/loadResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export async function loadResources(folder: string, files: string[], context: Re

const toUpdate: ResourceEntryCache[] = []
const toCheck: ResourceEntryCache[] = []
console.profile()
await Promise.all(files.map(async (file) => {
const filePath = join(folder, file)
const fstat = await stat(filePath).catch(() => undefined)
Expand Down Expand Up @@ -93,7 +92,6 @@ export async function loadResources(folder: string, files: string[], context: Re
}).map(p => p.catch((e) => {
context.logger.warn('Fail to load resource %o', e)
})))
console.profileEnd()

// remaining file should be removed
const toRemove: ResourceEntryCache[] = Object.values(caches)
Expand Down
1 change: 1 addition & 0 deletions xmcl-runtime/lib/services/CurseForgeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class CurseForgeService extends StatefulService<CurseforgeState> implemen
return deps
}

@Singleton((o) => o.file.id)
async installFile({ file, type, instancePath, ignoreDependencies }: InstallFileOptions): Promise<InstallFileResult> {
requireString(type)
requireObject(file)
Expand Down

0 comments on commit bf1aa59

Please sign in to comment.