Fix java installs (#1123)

* Fix java installs

* Finish java installs
This commit is contained in:
Geometrically
2024-04-18 20:28:52 -07:00
committed by GitHub
parent 2877919639
commit 49cecf837b
12 changed files with 104 additions and 305 deletions

View File

@@ -37,12 +37,7 @@
<script setup>
import { Modal, PlusIcon, CheckIcon, Button, XIcon } from 'omorphia'
import { ref } from 'vue'
import {
find_jre_17_jres,
find_jre_18plus_jres,
find_jre_8_jres,
get_all_jre,
} from '@/helpers/jre.js'
import { find_filtered_jres } from '@/helpers/jre.js'
import { handleError } from '@/store/notifications.js'
import { mixpanel_track } from '@/helpers/mixpanel'
import { useTheming } from '@/store/theme.js'
@@ -55,15 +50,10 @@ const currentSelected = ref({})
defineExpose({
show: async (version, currentSelectedJava) => {
if (version <= 8 && !!version) {
chosenInstallOptions.value = await find_jre_8_jres().catch(handleError)
} else if (version >= 18) {
chosenInstallOptions.value = await find_jre_18plus_jres().catch(handleError)
} else if (version) {
chosenInstallOptions.value = await find_jre_17_jres().catch(handleError)
} else {
chosenInstallOptions.value = await get_all_jre().catch(handleError)
}
chosenInstallOptions.value = await find_filtered_jres(version).catch(handleError)
console.log(chosenInstallOptions.value)
console.log(version)
currentSelected.value = currentSelectedJava
if (!currentSelected.value) {

View File

@@ -61,13 +61,7 @@ import {
FolderSearchIcon,
DownloadIcon,
} from 'omorphia'
import {
auto_install_java,
find_jre_17_jres,
find_jre_8_jres,
get_jre,
test_jre,
} from '@/helpers/jre.js'
import { auto_install_java, find_filtered_jres, get_jre, test_jre } from '@/helpers/jre.js'
import { ref } from 'vue'
import { open } from '@tauri-apps/api/dialog'
import JavaDetectionModal from '@/components/ui/JavaDetectionModal.vue'
@@ -82,7 +76,10 @@ const props = defineProps({
},
modelValue: {
type: Object,
required: true,
default: () => ({
path: '',
version: '',
}),
},
disabled: {
type: Boolean,
@@ -153,16 +150,9 @@ async function autoDetect() {
if (!props.compact) {
detectJavaModal.value.show(props.version, props.modelValue)
} else {
if (props.version == 8) {
let versions = await find_jre_8_jres().catch(handleError)
if (versions.length > 0) {
emit('update:modelValue', versions[0])
}
} else {
let versions = await find_jre_17_jres().catch(handleError)
if (versions.length > 0) {
emit('update:modelValue', versions[0])
}
let versions = await find_filtered_jres(props.version).catch(handleError)
if (versions.length > 0) {
emit('update:modelValue', versions[0])
}
}
}
@@ -170,7 +160,6 @@ async function autoDetect() {
async function reinstallJava() {
installingJava.value = true
const path = await auto_install_java(props.version).catch(handleError)
console.log('java path: ' + path)
let result = await get_jre(path)
console.log('java result ' + result)

View File

@@ -198,6 +198,17 @@ const refreshInfo = async () => {
return x
},
)
currentLoadingBars.value.sort((a, b) => {
if (a.loading_bar_uuid < b.loading_bar_uuid) {
return -1
}
if (a.loading_bar_uuid > b.loading_bar_uuid) {
return 1
}
return 0
})
if (currentLoadingBars.value.length === 0) {
showCard.value = false
} else if (currentLoadingBarCount < currentLoadingBars.value.length) {

View File

@@ -1,13 +1,11 @@
<script setup>
import { Button } from 'omorphia'
import { onMounted, ref } from 'vue'
import { ref } from 'vue'
import { get, set } from '@/helpers/settings.js'
import mixpanel from 'mixpanel-browser'
import GalleryImage from '@/components/ui/tutorial/GalleryImage.vue'
import LoginCard from '@/components/ui/tutorial/LoginCard.vue'
import StickyTitleBar from '@/components/ui/tutorial/StickyTitleBar.vue'
import { auto_install_java, get_jre } from '@/helpers/jre.js'
import { handleError } from '@/store/notifications.js'
const page = ref(1)
@@ -40,29 +38,6 @@ const finishOnboarding = async () => {
await set(settings)
props.finish()
}
async function fetchSettings() {
const fetchSettings = await get().catch(handleError)
if (!fetchSettings.java_globals) {
fetchSettings.java_globals = {}
}
if (!fetchSettings.java_globals.JAVA_17) {
const path1 = await auto_install_java(17).catch(handleError)
fetchSettings.java_globals.JAVA_17 = await get_jre(path1).catch(handleError)
}
if (!fetchSettings.java_globals.JAVA_8) {
const path2 = await auto_install_java(8).catch(handleError)
fetchSettings.java_globals.JAVA_8 = await get_jre(path2).catch(handleError)
}
await set(fetchSettings).catch(handleError)
}
onMounted(async () => {
await fetchSettings()
})
</script>
<template>

View File

@@ -14,43 +14,10 @@ JavaVersion {
*/
/// Get all JREs that exist on the system
// Returns an array of JavaVersion
export async function get_all_jre() {
return await invoke('plugin:jre|jre_get_all_jre')
}
// Finds all the installation of Java 7, if it exists
// Returns [JavaVersion]
export async function find_jre_8_jres() {
const jres = await invoke('plugin:jre|jre_get_all_jre')
const version = '1.8'
const allowHigher = false
return await invoke('plugin:jre|jre_find_filtered_jres', { jres, version, allowHigher })
}
// Finds the installation of Java 17, if it exists
// Returns [JavaVersion]
export async function find_jre_17_jres() {
const jres = await invoke('plugin:jre|jre_get_all_jre')
const version = '1.17'
const allowHigher = false
return await invoke('plugin:jre|jre_find_filtered_jres', { jres, version, allowHigher })
}
// Finds the highest version of Java 18+, if it exists
// Returns [JavaVersion]
export async function find_jre_18plus_jres() {
const jres = await invoke('plugin:jre|jre_get_all_jre')
const version = '1.18'
const allowHigher = true
return await invoke('plugin:jre|jre_find_filtered_jres', { jres, version, allowHigher })
}
// Validates globals. Recommend directing the user to reassigned the globals if this returns false
// Returns [JavaVersion]
export async function validate_globals() {
return await invoke('plugin:jre|jre_validate_globals')
export async function find_filtered_jres(version) {
return await invoke('plugin:jre|jre_find_filtered_jres', { version })
}
// Gets java version from a specific path by trying to run 'java -version' on it.
@@ -65,15 +32,6 @@ export async function test_jre(path, majorVersion, minorVersion) {
return await invoke('plugin:jre|jre_test_jre', { path, majorVersion, minorVersion })
}
// Autodetect Java globals, by searching the users computer.
// Returns a *NEW* JavaGlobals that can be put into Settings
export async function autodetect_java_globals() {
const java8 = await find_jre_8_jres()
const java17 = await find_jre_17_jres()
const java18plus = await find_jre_18plus_jres()
return await invoke('plugin:jre|jre_autodetect_java_globals', { java8, java17, java18plus })
}
// Automatically installs specified java version
export async function auto_install_java(javaVersion) {
return await invoke('plugin:jre|jre_auto_install_java', { javaVersion })

View File

@@ -31,17 +31,12 @@ const themeStore = useTheming()
const accessSettings = async () => {
const settings = await get()
if (!settings.java_globals.JAVA_8) settings.java_globals.JAVA_8 = { path: '', version: '' }
if (!settings.java_globals.JAVA_17) settings.java_globals.JAVA_17 = { path: '', version: '' }
settings.javaArgs = settings.custom_java_args.join(' ')
settings.envArgs = settings.custom_env_args.map((x) => x.join('=')).join(' ')
return settings
}
// const launcherVersion = await get_launcher_version().catch(handleError)
const fetchSettings = await accessSettings().catch(handleError)
const settings = ref(fetchSettings)
@@ -63,24 +58,16 @@ watch(
mixpanel_opt_in_tracking()
}
if (setSettings.java_globals.JAVA_8?.path === '') {
setSettings.java_globals.JAVA_8 = undefined
}
if (setSettings.java_globals.JAVA_17?.path === '') {
setSettings.java_globals.JAVA_17 = undefined
}
for (const [key, value] of Object.entries(setSettings.java_globals)) {
if (value?.path === '') {
value.path = undefined
}
if (setSettings.java_globals.JAVA_8?.path) {
setSettings.java_globals.JAVA_8.path = setSettings.java_globals.JAVA_8.path.replace(
'java.exe',
'javaw.exe',
)
}
if (setSettings.java_globals.JAVA_17?.path) {
setSettings.java_globals.JAVA_17.path = setSettings.java_globals.JAVA_17?.path.replace(
'java.exe',
'javaw.exe',
)
if (value?.path) {
value.path = value.path.replace('java.exe', 'javaw.exe')
}
console.log(`${key}: ${value}`)
}
setSettings.custom_java_args = setSettings.javaArgs.trim().split(/\s+/).filter(Boolean)
@@ -386,6 +373,10 @@ async function refreshDir() {
<span class="label__title size-card-header">Java settings</span>
</h3>
</div>
<label for="java-21">
<span class="label__title">Java 21 location</span>
</label>
<JavaSelector id="java-17" v-model="settings.java_globals.JAVA_21" :version="21" />
<label for="java-17">
<span class="label__title">Java 17 location</span>
</label>