* fixes

* prettier

* more bugs

* changes

* more fixes

* prettier, fmt, clippy

* fix regressed error

* println, console.log

* fix imports

---------

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
Co-authored-by: Jai A <jaiagr+gpg@pm.me>
This commit is contained in:
Wyatt Verchere
2023-08-04 20:33:50 -07:00
committed by GitHub
parent 6a76811bed
commit a35dd67b77
27 changed files with 357 additions and 100 deletions

View File

@@ -24,7 +24,7 @@ import { offline_listener, command_listener, warning_listener } from '@/helpers/
import { MinimizeIcon, MaximizeIcon } from '@/assets/icons'
import { type } from '@tauri-apps/api/os'
import { appWindow } from '@tauri-apps/api/window'
import { isDev, isOffline } from '@/helpers/utils.js'
import { isDev, getOS, isOffline } from '@/helpers/utils.js'
import {
mixpanel_track,
mixpanel_init,
@@ -44,9 +44,9 @@ import OnboardingScreen from '@/components/ui/tutorial/OnboardingScreen.vue'
const themeStore = useTheming()
const urlModal = ref(null)
const isLoading = ref(true)
const offline = ref(false)
const videoPlaying = ref(true)
const videoPlaying = ref(false)
const offline = ref(false)
const showOnboarding = ref(false)
const onboardingVideo = ref()
@@ -56,6 +56,9 @@ defineExpose({
isLoading.value = false
const { theme, opt_out_analytics, collapsed_navigation, advanced_rendering, onboarded_new } =
await get()
const os = await getOS()
// video should play if the user is not on linux, and has not onboarded
videoPlaying.value = !onboarded_new && os !== 'Linux'
const dev = await isDev()
const version = await getVersion()
showOnboarding.value = !onboarded_new

View File

@@ -12,7 +12,7 @@
<UploadIcon />
Select icon
</Button>
<Button @click="reset_icon">
<Button :disabled="!display_icon" @click="reset_icon">
<XIcon />
Remove icon
</Button>
@@ -73,7 +73,7 @@
<CodeIcon />
{{ showAdvanced ? 'Hide advanced' : 'Show advanced' }}
</Button>
<Button @click="$refs.modal.hide()">
<Button @click="hide()">
<XIcon />
Cancel
</Button>
@@ -202,7 +202,7 @@ import {
FolderSearchIcon,
UpdatedIcon,
} from 'omorphia'
import { computed, ref, shallowRef } from 'vue'
import { computed, onUnmounted, ref, shallowRef } from 'vue'
import { get_loaders } from '@/helpers/tags'
import { create } from '@/helpers/profile'
import { open } from '@tauri-apps/api/dialog'
@@ -219,7 +219,11 @@ import { mixpanel_track } from '@/helpers/mixpanel'
import { useTheming } from '@/store/state.js'
import { listen } from '@tauri-apps/api/event'
import { install_from_file } from '@/helpers/pack.js'
import { get_importable_instances, import_instance } from '@/helpers/import.js'
import {
get_default_launcher_path,
get_importable_instances,
import_instance,
} from '@/helpers/import.js'
const themeStore = useTheming()
@@ -234,9 +238,10 @@ const showAdvanced = ref(false)
const creating = ref(false)
const showSnapshots = ref(false)
const creationType = ref('from file')
const isShowing = ref(false)
defineExpose({
show: () => {
show: async () => {
game_version.value = ''
specified_loader_version.value = ''
profile_name.value = ''
@@ -247,12 +252,42 @@ defineExpose({
loader_version.value = 'stable'
icon.value = null
display_icon.value = null
isShowing.value = true
modal.value.show()
unlistener.value = await listen('tauri://file-drop', async (event) => {
// Only if modal is showing
if (!isShowing.value) return
if (creationType.value !== 'from file') return
hide()
if (event.payload && event.payload.length > 0 && event.payload[0].endsWith('.mrpack')) {
await install_from_file(event.payload[0]).catch(handleError)
mixpanel_track('InstanceCreate', {
source: 'CreationModalFileDrop',
})
}
})
mixpanel_track('InstanceCreateStart', { source: 'CreationModal' })
},
})
const unlistener = ref(null)
const hide = () => {
isShowing.value = false
modal.value.hide()
if (unlistener.value) {
unlistener.value()
unlistener.value = null
}
}
onUnmounted(() => {
if (unlistener.value) {
unlistener.value()
unlistener.value = null
}
})
const [fabric_versions, forge_versions, quilt_versions, all_game_versions, loaders] =
await Promise.all([
get_fabric_versions().then(shallowRef).catch(handleError),
@@ -303,7 +338,7 @@ const create_instance = async () => {
loader_version.value === 'other' ? specified_loader_version.value : loader_version.value
const loaderVersion = loader.value === 'vanilla' ? null : loader_version_value ?? 'stable'
modal.value.hide()
hide()
creating.value = false
await create(
@@ -366,8 +401,7 @@ const toggle_advanced = () => {
const openFile = async () => {
const newProject = await open({ multiple: false })
if (!newProject) return
modal.value.hide()
hide()
await install_from_file(newProject).catch(handleError)
mixpanel_track('InstanceCreate', {
@@ -375,16 +409,6 @@ const openFile = async () => {
})
}
listen('tauri://file-drop', async (event) => {
modal.value.hide()
if (event.payload && event.payload.length > 0 && event.payload[0].endsWith('.mrpack')) {
await install_from_file(event.payload[0]).catch(handleError)
mixpanel_track('InstanceCreate', {
source: 'CreationModalFileDrop',
})
}
})
const profiles = ref(
new Map([
['MultiMC', []],
@@ -406,6 +430,27 @@ const profileOptions = ref([
{ name: 'PrismLauncher', path: '' },
])
// Attempt to get import profiles on default paths
const promises = profileOptions.value.map(async (option) => {
const path = await get_default_launcher_path(option.name).catch(handleError)
if (!path || path === '') return
// Try catch to allow failure and simply ignore default path attempt
try {
const instances = await get_importable_instances(option.name, path)
if (!instances) return
profileOptions.value.find((profile) => profile.name === option.name).path = path
profiles.value.set(
option.name,
instances.map((name) => ({ name, selected: false }))
)
} catch (error) {
// Allow failure silently
}
})
await Promise.all(promises)
const selectLauncherPath = async () => {
selectedProfileType.value.path = await open({ multiple: false, directory: true })
@@ -419,10 +464,14 @@ const reload = async () => {
selectedProfileType.value.name,
selectedProfileType.value.path
).catch(handleError)
profiles.value.set(
selectedProfileType.value.name,
instances.map((name) => ({ name, selected: false }))
)
if (instances) {
profiles.value.set(
selectedProfileType.value.name,
instances.map((name) => ({ name, selected: false }))
)
} else {
profiles.value.set(selectedProfileType.value.name, [])
}
}
const setPath = () => {

View File

@@ -99,6 +99,8 @@ function setJavaInstall(javaInstall) {
align-items: center;
justify-content: center;
}
padding: 0.5rem;
}
}

View File

@@ -65,7 +65,6 @@ const profiles = ref([])
async function install(instance) {
instance.installing = true
console.log(versions.value)
const version = versions.value.find((v) => {
return (
v.game_versions.includes(instance.metadata.game_version) &&
@@ -264,7 +263,7 @@ const check_valid = computed(() => {
<UploadIcon />
<span class="no-wrap"> Select icon </span>
</Button>
<Button @click="reset_icon()">
<Button :disabled="!display_icon" @click="reset_icon()">
<XIcon />
<span class="no-wrap"> Remove icon </span>
</Button>

View File

@@ -10,7 +10,11 @@ import {
UpdatedIcon,
} from 'omorphia'
import { ref } from 'vue'
import { get_importable_instances, import_instance } from '@/helpers/import.js'
import {
get_default_launcher_path,
get_importable_instances,
import_instance,
} from '@/helpers/import.js'
import { open } from '@tauri-apps/api/dialog'
import { handleError } from '@/store/state.js'
@@ -46,6 +50,27 @@ const profileOptions = ref([
{ name: 'PrismLauncher', path: '' },
])
// Attempt to get import profiles on default paths
const promises = profileOptions.value.map(async (option) => {
const path = await get_default_launcher_path(option.name).catch(handleError)
if (!path || path === '') return
// Try catch to allow failure and simply ignore default path attempt
try {
const instances = await get_importable_instances(option.name, path)
if (!instances) return
profileOptions.value.find((profile) => profile.name === option.name).path = path
profiles.value.set(
option.name,
instances.map((name) => ({ name, selected: false }))
)
} catch (error) {
// Allow failure silently
}
})
Promise.all(promises)
const selectLauncherPath = async () => {
selectedProfileType.value.path = await open({ multiple: false, directory: true })

View File

@@ -62,7 +62,8 @@ export async function process_listener(callback) {
ProfilePayload {
uuid: unique identification of the process in the state (currently identified by path, but that will change)
name: name of the profile
path: path to profile
profile_path: relative path to profile (used for path identification)
path: path to profile (used for opening the profile in the OS file explorer)
event: event type ("Created", "Added", "Edited", "Removed")
}
*/

View File

@@ -11,6 +11,11 @@ export async function isDev() {
return await invoke('is_dev')
}
// One of 'Windows', 'Linux', 'MacOS'
export async function getOS() {
return await invoke('plugin:utils|get_os')
}
export async function showInFolder(path) {
return await invoke('plugin:utils|show_in_folder', { path })
}

View File

@@ -1,6 +1,6 @@
<script setup>
import { ref, watch } from 'vue'
import { Card, Slider, DropdownSelect, Checkbox, Toggle } from 'omorphia'
import { Card, Slider, DropdownSelect, Toggle } from 'omorphia'
import { handleError, useTheming } from '@/store/state'
import { get, set } from '@/helpers/settings'
import { get_max_memory } from '@/helpers/jre'
@@ -336,7 +336,16 @@ watch(
Overwrites the option.txt file to start in full screen when launched.
</span>
</label>
<Checkbox id="fullscreen" v-model="settings.force_fullscreen" />
<Toggle
id="fullscreen"
:model-value="settings.force_fullscreen"
:checked="settings.force_fullscreen"
@update:model-value="
(e) => {
settings.force_fullscreen = e
}
"
/>
</div>
<div class="adjacent-input">
<label for="width">

View File

@@ -284,7 +284,7 @@ const handleOptionsClick = async (args) => {
}
const unlistenProfiles = await profile_listener(async (event) => {
if (event.path === route.params.id) {
if (event.profile_path_id === route.params.id) {
if (event.event === 'removed') {
await router.push({
path: '/',

View File

@@ -15,7 +15,7 @@
<CheckIcon v-else />
{{ copied ? 'Copied' : 'Copy' }}
</Button>
<Button color="primary" :disabled="offline" @click="share">
<Button color="primary" :disabled="offline || !logs[selectedLogIndex]" @click="share">
<ShareIcon />
Share
</Button>

View File

@@ -336,7 +336,7 @@ import {
ShareModal,
CodeIcon,
} from 'omorphia'
import { computed, ref, watch } from 'vue'
import { computed, onUnmounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import {
add_project_from_path,
@@ -353,7 +353,6 @@ import { listen } from '@tauri-apps/api/event'
import { convertFileSrc } from '@tauri-apps/api/tauri'
import { showProfileInFolder } from '@/helpers/utils.js'
import { MenuIcon, ToggleIcon, TextInputIcon, AddProjectImage } from '@/assets/icons'
import { install_from_file } from '@/helpers/pack'
const router = useRouter()
@@ -785,18 +784,15 @@ watch(selectAll, () => {
}
})
listen('tauri://file-drop', async (event) => {
if (event.payload && event.payload.length > 0 && event.payload[0].endsWith('.mrpack')) {
await install_from_file(event.payload[0]).catch(handleError)
} else {
for (const file of event.payload) {
await add_project_from_path(props.instance.path, file, 'mod').catch(handleError)
}
initProjects(await get(props.instance.path).catch(handleError))
const unlisten = await listen('tauri://file-drop', async (event) => {
for (const file of event.payload) {
if (file.endsWith('.mrpack')) continue
await add_project_from_path(props.instance.path, file, 'mod').catch(handleError)
}
mixpanel_track('InstanceCreate', {
source: 'FileDrop',
})
initProjects(await get(props.instance.path).catch(handleError))
})
onUnmounted(() => {
unlisten()
})
</script>

View File

@@ -42,7 +42,7 @@
</button>
<button
class="btn btn-primary"
:disabled="!isValid || editing"
:disabled="!isValid || !isChanged || editing"
@click="saveGvLoaderEdits()"
>
<SaveIcon />
@@ -71,7 +71,11 @@
<UploadIcon />
Select icon
</button>
<button class="btn" @click="resetIcon">
<button
:disabled="!(!icon || (icon && icon.startsWith('http')) ? icon : convertFileSrc(icon))"
class="btn"
@click="resetIcon"
>
<TrashIcon />
Remove icon
</button>
@@ -93,8 +97,8 @@
<button
id="edit-versions"
class="btn"
@click="$refs.changeVersionsModal.show()"
:disabled="offline"
@click="$refs.changeVersionsModal.show()"
>
<EditIcon />
Edit versions
@@ -640,6 +644,15 @@ const isValid = computed(() => {
)
})
const isChanged = computed(() => {
return (
loader.value != props.instance.metadata.loader ||
gameVersion.value != props.instance.metadata.game_version ||
JSON.stringify(selectableLoaderVersions.value[loaderVersionIndex.value]) !=
JSON.stringify(props.instance.metadata.loader_version)
)
})
watch(loader, () => (loaderVersionIndex.value = 0))
const editing = ref(false)