Migrate to SQLite for Internal Launcher Data (#1300)

* initial migration

* barebones profiles

* Finish profiles

* Add back file watcher

* UI support progress

* Finish most of cache

* Fix options page

* Fix forge, finish modrinth auth

* Accounts, process cache

* Run SQLX prepare

* Finish

* Run lint + actions

* Fix version to be compat with windows

* fix lint

* actually fix lint

* actually fix lint again
This commit is contained in:
Geometrically
2024-07-24 11:03:19 -07:00
committed by GitHub
parent 90f74427d9
commit 49a20a303a
156 changed files with 9208 additions and 8547 deletions

View File

@@ -15,15 +15,15 @@
</Button>
<div v-if="offline" class="status">
<span class="circle stopped" />
<div class="running-text clickable" @click="refreshInternet()">
<div class="running-text">
<span> Offline </span>
</div>
</div>
<div v-if="selectedProfile" class="status">
<div v-if="selectedProcess" class="status">
<span class="circle running" />
<div ref="profileButton" class="running-text">
<router-link :to="`/instance/${encodeURIComponent(selectedProfile.path)}`">
{{ selectedProfile.metadata.name }}
<router-link :to="`/instance/${encodeURIComponent(selectedProcess.profile.path)}`">
{{ selectedProcess.profile.name }}
</router-link>
<div
v-if="currentProcesses.length > 1"
@@ -34,7 +34,12 @@
<DropdownIcon />
</div>
</div>
<Button v-tooltip="'Stop instance'" icon-only class="icon-button stop" @click="stop()">
<Button
v-tooltip="'Stop instance'"
icon-only
class="icon-button stop"
@click="stop(selectedProcess)"
>
<StopCircleIcon />
</Button>
<Button v-tooltip="'View logs'" icon-only class="icon-button" @click="goToTerminal()">
@@ -75,17 +80,17 @@
class="profile-card"
>
<Button
v-for="profile in currentProcesses"
:key="profile.id"
v-for="process in currentProcesses"
:key="process.pid"
class="profile-button"
@click="selectProfile(profile)"
@click="selectedProcess(process)"
>
<div class="text"><span class="circle running" /> {{ profile.metadata.name }}</div>
<div class="text"><span class="circle running" /> {{ process.profile.name }}</div>
<Button
v-tooltip="'Stop instance'"
icon-only
class="icon-button stop"
@click.stop="stop(profile.path)"
@click.stop="stop(process)"
>
<StopCircleIcon />
</Button>
@@ -93,7 +98,7 @@
v-tooltip="'View logs'"
icon-only
class="icon-button"
@click.stop="goToTerminal(profile.path)"
@click.stop="goToTerminal(process.profile.path)"
>
<TerminalSquareIcon />
</Button>
@@ -106,19 +111,15 @@
import { DownloadIcon, StopCircleIcon, TerminalSquareIcon, DropdownIcon } from '@modrinth/assets'
import { Button, Card } from '@modrinth/ui'
import { onBeforeUnmount, onMounted, ref } from 'vue'
import {
get_all_running_profiles as getRunningProfiles,
kill_by_uuid as killProfile,
get_uuids_by_profile_path as getProfileProcesses,
} from '@/helpers/process'
import { loading_listener, process_listener, offline_listener } from '@/helpers/events'
import { get_all as getRunningProcesses, kill as killProcess } from '@/helpers/process'
import { loading_listener, process_listener } from '@/helpers/events'
import { useRouter } from 'vue-router'
import { progress_bars_list } from '@/helpers/state.js'
import { refreshOffline, isOffline } from '@/helpers/utils.js'
import ProgressBar from '@/components/ui/ProgressBar.vue'
import { handleError } from '@/store/notifications.js'
import { mixpanel_track } from '@/helpers/mixpanel'
import { ChatIcon } from '@/assets/icons'
import { get_many } from '@/helpers/profile.js'
const router = useRouter()
const card = ref(null)
@@ -129,38 +130,44 @@ const showCard = ref(false)
const showProfiles = ref(false)
const currentProcesses = ref(await getRunningProfiles().catch(handleError))
const selectedProfile = ref(currentProcesses.value[0])
const currentProcesses = ref([])
const selectedProcess = ref()
const offline = ref(await isOffline().catch(handleError))
const refreshInternet = async () => {
offline.value = await refreshOffline().catch(handleError)
const refresh = async () => {
const processes = await getRunningProcesses().catch(handleError)
const profiles = await get_many(processes.map((x) => x.profile_path)).catch(handleError)
currentProcesses.value = processes.map((x) => ({
profile: profiles.find((prof) => x.profile_path === prof.path),
...x,
}))
if (!selectedProcess.value || !currentProcesses.value.includes(selectedProcess.value)) {
selectedProcess.value = currentProcesses.value[0]
}
}
await refresh()
const offline = ref(!navigator.onLine)
window.addEventListener('offline', () => {
offline.value = true
})
window.addEventListener('online', () => {
offline.value = false
})
const unlistenProcess = await process_listener(async () => {
await refresh()
})
const unlistenRefresh = await offline_listener(async (b) => {
offline.value = b
await refresh()
})
const refresh = async () => {
currentProcesses.value = await getRunningProfiles().catch(handleError)
if (!currentProcesses.value.includes(selectedProfile.value)) {
selectedProfile.value = currentProcesses.value[0]
}
}
const stop = async (path) => {
const stop = async (process) => {
try {
const processes = await getProfileProcesses(path ?? selectedProfile.value.path)
await killProfile(processes[0])
console.log(process.pid)
await killProcess(process.pid).catch(handleError)
mixpanel_track('InstanceStop', {
loader: currentProcesses.value[0].metadata.loader,
game_version: currentProcesses.value[0].metadata.game_version,
loader: process.profile.loader,
game_version: process.profile.game_version,
source: 'AppBar',
})
} catch (e) {
@@ -170,7 +177,7 @@ const stop = async (path) => {
}
const goToTerminal = (path) => {
router.push(`/instance/${encodeURIComponent(path ?? selectedProfile.value.path)}/logs`)
router.push(`/instance/${encodeURIComponent(path ?? selectedProcess.value.profile.path)}/logs`)
}
const currentLoadingBars = ref([])
@@ -182,8 +189,8 @@ const refreshInfo = async () => {
if (x.bar_type.type === 'java_download') {
x.title = 'Downloading Java ' + x.bar_type.version
}
if (x.bar_type.profile_name) {
x.title = x.bar_type.profile_name
if (x.bar_type.profile_path) {
x.title = x.bar_type.profile_path
}
if (x.bar_type.pack_name) {
x.title = x.bar_type.pack_name
@@ -215,8 +222,8 @@ const unlistenLoading = await loading_listener(async () => {
await refreshInfo()
})
const selectProfile = (profile) => {
selectedProfile.value = profile
const selectProcess = (process) => {
selectedProcess.value = process
showProfiles.value = false
}
@@ -267,7 +274,6 @@ onBeforeUnmount(() => {
window.removeEventListener('click', handleClickOutsideProfile)
unlistenProcess()
unlistenLoading()
unlistenRefresh()
})
</script>