Skip to content

Commit

Permalink
fix: Install java if user does not have java
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Oct 29, 2023
1 parent a7a0e8e commit 2f03b90
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
24 changes: 21 additions & 3 deletions xmcl-keystone-ui/src/composables/instanceJavaDiagnose.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { JavaRecord } from '@xmcl/runtime-api'
import { JavaRecord, JavaServiceKey } from '@xmcl/runtime-api'
import { InjectionKey, Ref } from 'vue'
import { useDialog } from './dialog'
import { JavaRecommendation } from './instanceJava'
import { JavaCompatibleState, JavaRecommendation } from './instanceJava'
import { JavaIssueDialogKey } from './java'
import { LaunchMenuItem } from './launchButton'
import { useNotifier } from './notifier'
import { useService } from './service'

export const kInstanceJavaDiagnose: InjectionKey<ReturnType<typeof useInstanceJavaDiagnose>> = Symbol('InstanceJavaDiagnose')

export function useInstanceJavaDiagnose(all: Ref<JavaRecord[]>, java: Ref<JavaRecord | undefined>, javaRecommendation: Ref<JavaRecommendation | undefined>) {
const { t } = useI18n()
const { subscribeTask } = useNotifier()
const { installDefaultJava } = useService(JavaServiceKey)
const issue: Ref<LaunchMenuItem | undefined> = computed(() => {
if (all.value.length === 0) {
return {
Expand All @@ -23,6 +27,13 @@ export function useInstanceJavaDiagnose(all: Ref<JavaRecord[]>, java: Ref<JavaRe
}
}
if (javaRecommendation.value) {
if (javaRecommendation.value.recommendedLevel && javaRecommendation.value.recommendedLevel >= 1 &&
javaRecommendation.value.recommendedDownload) {
return {
title: t('diagnosis.incompatibleJava.name', { version: javaRecommendation.value.requirement, javaVersion: javaRecommendation.value.selectedJava?.version || '' }),
description: t('diagnosis.incompatibleJava.message'),
}
}
return {
title: t('diagnosis.incompatibleJava.name', { version: javaRecommendation.value.requirement, javaVersion: javaRecommendation.value.selectedJava?.version || '' }),
description: t('diagnosis.incompatibleJava.message'),
Expand All @@ -37,7 +48,14 @@ export function useInstanceJavaDiagnose(all: Ref<JavaRecord[]>, java: Ref<JavaRe

function fix() {
if (issue.value) {
showJavaDialog()
if (javaRecommendation.value && javaRecommendation.value.recommendedLevel && javaRecommendation.value.recommendedLevel >= 1 &&
javaRecommendation.value.recommendedDownload) {
const promise = installDefaultJava(javaRecommendation.value.recommendedDownload)
subscribeTask(promise, t('java.modifyInstance'))
return promise
} else {
showJavaDialog()
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/src/composables/launchTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export function useLaunchTask(path: Ref<string>, version: Ref<Instance['runtime'
if (i.state === TaskState.Cancelled || i.state === TaskState.Succeed || i.state === TaskState.Failed) {
return false
}
if (i.path === 'installJre') {
return true
}
if (i.path === 'installVersion' && p?.id === version.value.minecraft) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/lib/services/JavaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class JavaService extends StatefulService<JavaState> implements IJavaServ
apiHost,
destination: dest,
...downloadOptions,
}).setName('installJre')
}).setName('installJre', { version: target.majorVersion })
await ensureFile(location)
await this.submit(task)
if (this.app.platform.os !== 'windows') {
Expand Down

0 comments on commit 2f03b90

Please sign in to comment.