0.8.0 beta fixes (#2154)
* initial fixes * 0.8.0 beta fixes * run actions * run fmt * Fix windows build * Add purge cache opt * add must revalidate to project req * lint + clippy * fix processes, open folder * Update migrator to use old launcher cache for perf * fix empty dirs not moving * fix lint + create natives dir if not exist * fix large request batches * finish * Fix deep linking on mac * fix comp err * fix comp err (2) --------- Signed-off-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
parent
3a4843fb46
commit
910e219c0e
1
.github/workflows/app-release.yml
vendored
1
.github/workflows/app-release.yml
vendored
@ -3,6 +3,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
- 0.8.0-beta-fixes
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
88
Cargo.lock
generated
88
Cargo.lock
generated
@ -129,7 +129,6 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tokio",
|
"tokio",
|
||||||
"xz2",
|
|
||||||
"zstd 0.13.2",
|
"zstd 0.13.2",
|
||||||
"zstd-safe 7.2.0",
|
"zstd-safe 7.2.0",
|
||||||
]
|
]
|
||||||
@ -504,6 +503,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706"
|
checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
|
"regex-automata 0.4.7",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1052,6 +1052,17 @@ version = "2.6.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2"
|
checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dbus"
|
||||||
|
version = "0.9.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"libdbus-sys",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "debugid"
|
name = "debugid"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
@ -2609,6 +2620,16 @@ version = "0.2.155"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libdbus-sys"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
@ -2679,17 +2700,6 @@ dependencies = [
|
|||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lzma-sys"
|
|
||||||
version = "0.1.20"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
"pkg-config",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mac"
|
name = "mac"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -2980,6 +2990,15 @@ dependencies = [
|
|||||||
"minimal-lexical",
|
"minimal-lexical",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "normpath"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8911957c4b1549ac0dc74e30db9c8b0e66ddcd6d7acc33098f4c63a64a6d7ed"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "notify"
|
name = "notify"
|
||||||
version = "6.1.1"
|
version = "6.1.1"
|
||||||
@ -3215,6 +3234,19 @@ dependencies = [
|
|||||||
"windows-sys 0.42.0",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opener"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d0812e5e4df08da354c851a3376fead46db31c2214f849d3de356d774d057681"
|
||||||
|
dependencies = [
|
||||||
|
"bstr",
|
||||||
|
"dbus",
|
||||||
|
"normpath",
|
||||||
|
"url",
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl"
|
name = "openssl"
|
||||||
version = "0.10.65"
|
version = "0.10.65"
|
||||||
@ -5481,7 +5513,6 @@ dependencies = [
|
|||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"toml 0.8.15",
|
"toml 0.8.15",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-appender",
|
|
||||||
"tracing-error",
|
"tracing-error",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"url",
|
"url",
|
||||||
@ -5505,6 +5536,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"objc",
|
"objc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"opener",
|
||||||
"os_info",
|
"os_info",
|
||||||
"paste",
|
"paste",
|
||||||
"sentry",
|
"sentry",
|
||||||
@ -5819,18 +5851,6 @@ dependencies = [
|
|||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-appender"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-channel",
|
|
||||||
"thiserror",
|
|
||||||
"time",
|
|
||||||
"tracing-subscriber",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-attributes"
|
name = "tracing-attributes"
|
||||||
version = "0.1.27"
|
version = "0.1.27"
|
||||||
@ -6527,6 +6547,15 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.59.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "windows-targets"
|
||||||
version = "0.42.2"
|
version = "0.42.2"
|
||||||
@ -6898,15 +6927,6 @@ dependencies = [
|
|||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xz2"
|
|
||||||
version = "0.1.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
|
|
||||||
dependencies = [
|
|
||||||
"lzma-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zbus"
|
name = "zbus"
|
||||||
version = "3.15.2"
|
version = "3.15.2"
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en" class="dark-mode">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Modrinth App</title>
|
<title>Modrinth App</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/src/assets/stylesheets/global.scss" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@ -1,16 +1,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref, onMounted } from 'vue'
|
import { computed, ref, onMounted } from 'vue'
|
||||||
import { RouterView, RouterLink, useRouter, useRoute } from 'vue-router'
|
import { RouterView, RouterLink, useRouter, useRoute } from 'vue-router'
|
||||||
import {
|
import { HomeIcon, SearchIcon, LibraryIcon, PlusIcon, SettingsIcon, XIcon } from '@modrinth/assets'
|
||||||
HomeIcon,
|
import { Button, Notifications } from '@modrinth/ui'
|
||||||
SearchIcon,
|
|
||||||
LibraryIcon,
|
|
||||||
PlusIcon,
|
|
||||||
SettingsIcon,
|
|
||||||
FileIcon,
|
|
||||||
XIcon,
|
|
||||||
} from '@modrinth/assets'
|
|
||||||
import { Button, Notifications, Card } from '@modrinth/ui'
|
|
||||||
import { useLoading, useTheming } from '@/store/state'
|
import { useLoading, useTheming } from '@/store/state'
|
||||||
import AccountsCard from '@/components/ui/AccountsCard.vue'
|
import AccountsCard from '@/components/ui/AccountsCard.vue'
|
||||||
import InstanceCreationModal from '@/components/ui/InstanceCreationModal.vue'
|
import InstanceCreationModal from '@/components/ui/InstanceCreationModal.vue'
|
||||||
@ -22,10 +14,10 @@ import ErrorModal from '@/components/ui/ErrorModal.vue'
|
|||||||
import ModrinthLoadingIndicator from '@/components/modrinth-loading-indicator'
|
import ModrinthLoadingIndicator from '@/components/modrinth-loading-indicator'
|
||||||
import { handleError, useNotifications } from '@/store/notifications.js'
|
import { handleError, useNotifications } from '@/store/notifications.js'
|
||||||
import { command_listener, warning_listener } from '@/helpers/events.js'
|
import { command_listener, warning_listener } from '@/helpers/events.js'
|
||||||
import { MinimizeIcon, MaximizeIcon, ChatIcon } from '@/assets/icons'
|
import { MinimizeIcon, MaximizeIcon } from '@/assets/icons'
|
||||||
import { type } from '@tauri-apps/api/os'
|
import { type } from '@tauri-apps/api/os'
|
||||||
import { appWindow } from '@tauri-apps/api/window'
|
import { appWindow } from '@tauri-apps/api/window'
|
||||||
import { isDev, getOS, showLauncherLogsFolder } from '@/helpers/utils.js'
|
import { isDev, getOS } from '@/helpers/utils.js'
|
||||||
import {
|
import {
|
||||||
mixpanel_track,
|
mixpanel_track,
|
||||||
mixpanel_init,
|
mixpanel_init,
|
||||||
@ -37,17 +29,18 @@ import { getVersion } from '@tauri-apps/api/app'
|
|||||||
import { window as TauriWindow } from '@tauri-apps/api'
|
import { window as TauriWindow } from '@tauri-apps/api'
|
||||||
import { TauriEvent } from '@tauri-apps/api/event'
|
import { TauriEvent } from '@tauri-apps/api/event'
|
||||||
import URLConfirmModal from '@/components/ui/URLConfirmModal.vue'
|
import URLConfirmModal from '@/components/ui/URLConfirmModal.vue'
|
||||||
import OnboardingScreen from '@/components/ui/tutorial/OnboardingScreen.vue'
|
|
||||||
import { install_from_file } from './helpers/pack'
|
import { install_from_file } from './helpers/pack'
|
||||||
import { useError } from '@/store/error.js'
|
import { useError } from '@/store/error.js'
|
||||||
import ModInstallModal from '@/components/ui/install_flow/ModInstallModal.vue'
|
import ModInstallModal from '@/components/ui/install_flow/ModInstallModal.vue'
|
||||||
import IncompatibilityWarningModal from '@/components/ui/install_flow/IncompatibilityWarningModal.vue'
|
import IncompatibilityWarningModal from '@/components/ui/install_flow/IncompatibilityWarningModal.vue'
|
||||||
import InstallConfirmModal from '@/components/ui/install_flow/InstallConfirmModal.vue'
|
import InstallConfirmModal from '@/components/ui/install_flow/InstallConfirmModal.vue'
|
||||||
import { useInstall } from '@/store/install.js'
|
import { useInstall } from '@/store/install.js'
|
||||||
|
import { invoke } from '@tauri-apps/api/tauri'
|
||||||
|
import { get_opening_command, initialize_state } from '@/helpers/state'
|
||||||
|
|
||||||
const themeStore = useTheming()
|
const themeStore = useTheming()
|
||||||
|
|
||||||
const urlModal = ref(null)
|
const urlModal = ref(null)
|
||||||
const isLoading = ref(true)
|
|
||||||
|
|
||||||
const offline = ref(!navigator.onLine)
|
const offline = ref(!navigator.onLine)
|
||||||
window.addEventListener('offline', () => {
|
window.addEventListener('offline', () => {
|
||||||
@ -60,14 +53,12 @@ window.addEventListener('online', () => {
|
|||||||
const showOnboarding = ref(false)
|
const showOnboarding = ref(false)
|
||||||
const nativeDecorations = ref(false)
|
const nativeDecorations = ref(false)
|
||||||
|
|
||||||
const onboardingVideo = ref()
|
|
||||||
|
|
||||||
const failureText = ref(null)
|
|
||||||
const os = ref('')
|
const os = ref('')
|
||||||
|
|
||||||
defineExpose({
|
const stateInitialized = ref(false)
|
||||||
initialize: async () => {
|
|
||||||
isLoading.value = false
|
async function setupApp() {
|
||||||
|
stateInitialized.value = true
|
||||||
const {
|
const {
|
||||||
native_decorations,
|
native_decorations,
|
||||||
theme,
|
theme,
|
||||||
@ -75,22 +66,27 @@ defineExpose({
|
|||||||
collapsed_navigation,
|
collapsed_navigation,
|
||||||
advanced_rendering,
|
advanced_rendering,
|
||||||
onboarded,
|
onboarded,
|
||||||
|
default_page,
|
||||||
} = await get()
|
} = await get()
|
||||||
// video should play if the user is not on linux, and has not onboarded
|
|
||||||
|
if (default_page && default_page !== 'Home') {
|
||||||
|
await router.push({ name: default_page })
|
||||||
|
}
|
||||||
|
|
||||||
os.value = await getOS()
|
os.value = await getOS()
|
||||||
const dev = await isDev()
|
const dev = await isDev()
|
||||||
const version = await getVersion()
|
const version = await getVersion()
|
||||||
showOnboarding.value = !onboarded
|
showOnboarding.value = !onboarded
|
||||||
|
|
||||||
nativeDecorations.value = native_decorations
|
nativeDecorations.value = native_decorations
|
||||||
if (os.value !== 'MacOS') appWindow.setDecorations(native_decorations)
|
if (os.value !== 'MacOS') await appWindow.setDecorations(native_decorations)
|
||||||
|
|
||||||
themeStore.setThemeState(theme)
|
themeStore.setThemeState(theme)
|
||||||
themeStore.collapsedNavigation = collapsed_navigation
|
themeStore.collapsedNavigation = collapsed_navigation
|
||||||
themeStore.advancedRendering = advanced_rendering
|
themeStore.advancedRendering = advanced_rendering
|
||||||
|
|
||||||
mixpanel_init('014c7d6a336d0efaefe3aca91063748d', { debug: dev, persistence: 'localStorage' })
|
mixpanel_init('014c7d6a336d0efaefe3aca91063748d', { debug: dev, persistence: 'localStorage' })
|
||||||
if (telemetry) {
|
if (!telemetry) {
|
||||||
mixpanel_opt_out_tracking()
|
mixpanel_opt_out_tracking()
|
||||||
}
|
}
|
||||||
mixpanel_track('Launched', { version, dev, onboarded })
|
mixpanel_track('Launched', { version, dev, onboarded })
|
||||||
@ -111,16 +107,23 @@ defineExpose({
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (showOnboarding.value) {
|
get_opening_command().then(handleCommand)
|
||||||
onboardingVideo.value.play()
|
}
|
||||||
}
|
|
||||||
},
|
const stateFailed = ref(false)
|
||||||
failure: async (e) => {
|
initialize_state()
|
||||||
isLoading.value = false
|
.then(() => {
|
||||||
failureText.value = e
|
setupApp().catch((err) => {
|
||||||
os.value = await getOS()
|
stateFailed.value = true
|
||||||
},
|
console.error(err)
|
||||||
})
|
error.showError(err, false, 'state_init')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
stateFailed.value = true
|
||||||
|
console.error('Failed to initialize app', err)
|
||||||
|
error.showError(err, false, 'state_init')
|
||||||
|
})
|
||||||
|
|
||||||
const handleClose = async () => {
|
const handleClose = async () => {
|
||||||
await TauriWindow.getCurrent().close()
|
await TauriWindow.getCurrent().close()
|
||||||
@ -140,6 +143,7 @@ const route = useRoute()
|
|||||||
const isOnBrowse = computed(() => route.path.startsWith('/browse'))
|
const isOnBrowse = computed(() => route.path.startsWith('/browse'))
|
||||||
|
|
||||||
const loading = useLoading()
|
const loading = useLoading()
|
||||||
|
loading.setEnabled(false)
|
||||||
|
|
||||||
const notifications = useNotifications()
|
const notifications = useNotifications()
|
||||||
const notificationsWrapper = ref()
|
const notificationsWrapper = ref()
|
||||||
@ -153,6 +157,8 @@ const installConfirmModal = ref()
|
|||||||
const incompatibilityWarningModal = ref()
|
const incompatibilityWarningModal = ref()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
invoke('show_window')
|
||||||
|
|
||||||
notifications.setNotifs(notificationsWrapper.value)
|
notifications.setNotifs(notificationsWrapper.value)
|
||||||
|
|
||||||
error.setErrorModal(errorModal.value)
|
error.setErrorModal(errorModal.value)
|
||||||
@ -204,7 +210,10 @@ document.querySelector('body').addEventListener('auxclick', function (e) {
|
|||||||
|
|
||||||
const accounts = ref(null)
|
const accounts = ref(null)
|
||||||
|
|
||||||
command_listener(async (e) => {
|
command_listener(handleCommand)
|
||||||
|
async function handleCommand(e) {
|
||||||
|
if (!e) return
|
||||||
|
|
||||||
if (e.event === 'RunMRPack') {
|
if (e.event === 'RunMRPack') {
|
||||||
// RunMRPack should directly install a local mrpack given a path
|
// RunMRPack should directly install a local mrpack given a path
|
||||||
if (e.path.endsWith('.mrpack')) {
|
if (e.path.endsWith('.mrpack')) {
|
||||||
@ -217,53 +226,12 @@ command_listener(async (e) => {
|
|||||||
// Other commands are URL-based (deep linking)
|
// Other commands are URL-based (deep linking)
|
||||||
urlModal.value.show(e)
|
urlModal.value.show(e)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="failureText" class="failure dark-mode">
|
<SplashScreen v-if="!stateFailed" ref="splashScreen" data-tauri-drag-region />
|
||||||
<div class="appbar-failure dark-mode">
|
<div v-if="stateInitialized" class="container">
|
||||||
<Button v-if="os != 'MacOS'" icon-only @click="TauriWindow.getCurrent().close()">
|
|
||||||
<XIcon />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div class="error-view dark-mode">
|
|
||||||
<Card class="error-text">
|
|
||||||
<div class="label">
|
|
||||||
<h3>
|
|
||||||
<span class="label__title size-card-header">Failed to initialize</span>
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
<div class="error-div">
|
|
||||||
Modrinth App failed to load correctly. This may be because of a corrupted file, or because
|
|
||||||
the app is missing crucial files.
|
|
||||||
</div>
|
|
||||||
<div class="error-div">You may be able to fix it one of the following ways:</div>
|
|
||||||
<ul class="error-div">
|
|
||||||
<li>Ennsuring you are connected to the internet, then try restarting the app.</li>
|
|
||||||
<li>Redownloading the app.</li>
|
|
||||||
</ul>
|
|
||||||
<div class="error-div">
|
|
||||||
If it still does not work, you can seek support using the link below. You should provide
|
|
||||||
the following error, as well as any recent launcher logs in the folder below.
|
|
||||||
</div>
|
|
||||||
<div class="error-div">The following error was provided:</div>
|
|
||||||
|
|
||||||
<Card class="error-message">
|
|
||||||
{{ failureText.message }}
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<div class="button-row push-right">
|
|
||||||
<Button @click="showLauncherLogsFolder"><FileIcon />Open launcher logs</Button>
|
|
||||||
|
|
||||||
<a class="btn" href="https://support.modrinth.com"> <ChatIcon /> Get support </a>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<SplashScreen v-else-if="isLoading" app-loading />
|
|
||||||
<OnboardingScreen v-else-if="showOnboarding" :finish="() => (showOnboarding = false)" />
|
|
||||||
<div v-else class="container">
|
|
||||||
<div class="nav-container">
|
<div class="nav-container">
|
||||||
<div class="nav-section">
|
<div class="nav-section">
|
||||||
<suspense>
|
<suspense>
|
||||||
@ -449,53 +417,6 @@ command_listener(async (e) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.failure {
|
|
||||||
height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
overflow: hidden;
|
|
||||||
background-color: var(--color-bg);
|
|
||||||
|
|
||||||
.appbar-failure {
|
|
||||||
display: flex; /* Change to flex to align items horizontally */
|
|
||||||
justify-content: flex-end; /* Align items to the right */
|
|
||||||
height: 3.25rem;
|
|
||||||
//no select
|
|
||||||
user-select: none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.error-view {
|
|
||||||
display: flex; /* Change to flex to align items horizontally */
|
|
||||||
justify-content: center;
|
|
||||||
width: 100%;
|
|
||||||
background-color: var(--color-bg);
|
|
||||||
|
|
||||||
color: var(--color-base);
|
|
||||||
|
|
||||||
.card {
|
|
||||||
background-color: var(--color-raised-bg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.error-text {
|
|
||||||
display: flex;
|
|
||||||
max-width: 60%;
|
|
||||||
gap: 0.25rem;
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
.error-div {
|
|
||||||
// spaced out
|
|
||||||
margin: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.error-message {
|
|
||||||
margin: 0.5rem;
|
|
||||||
background-color: var(--color-button-bg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-container {
|
.nav-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@ -580,3 +501,33 @@ command_listener(async (e) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<style>
|
||||||
|
.mac {
|
||||||
|
.nav-container {
|
||||||
|
padding-top: calc(var(--gap-md) + 1.75rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.account-card,
|
||||||
|
.card-section {
|
||||||
|
top: calc(var(--gap-md) + 1.75rem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.windows {
|
||||||
|
.fake-appbar {
|
||||||
|
height: 2.5rem !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.window-controls {
|
||||||
|
display: flex !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-card {
|
||||||
|
right: 8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-card {
|
||||||
|
right: 8rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
BIN
apps/app-frontend/src/assets/loading/cube.png
Normal file
BIN
apps/app-frontend/src/assets/loading/cube.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 937 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.0 MiB |
@ -69,35 +69,6 @@ input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.mac {
|
|
||||||
.nav-container {
|
|
||||||
padding-top: calc(var(--gap-md) + 1.75rem);
|
|
||||||
}
|
|
||||||
|
|
||||||
.account-card,
|
|
||||||
.card-section {
|
|
||||||
top: calc(var(--gap-md) + 1.75rem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.windows {
|
|
||||||
.fake-appbar {
|
|
||||||
height: 2.5rem !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.window-controls {
|
|
||||||
display: flex !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info-card {
|
|
||||||
right: 8rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.profile-card {
|
|
||||||
right: 8rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
* {
|
* {
|
||||||
scrollbar-width: auto;
|
scrollbar-width: auto;
|
||||||
scrollbar-color: var(--color-scrollbar) var(--color-bg);
|
scrollbar-color: var(--color-scrollbar) var(--color-bg);
|
||||||
@ -135,3 +106,5 @@ img {
|
|||||||
-moz-user-select: none;
|
-moz-user-select: none;
|
||||||
-ms-user-select: none;
|
-ms-user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@import '@modrinth/assets/omorphia.scss';
|
||||||
|
|||||||
@ -40,11 +40,13 @@ export default defineComponent({
|
|||||||
const loading = useLoading()
|
const loading = useLoading()
|
||||||
|
|
||||||
watch(loading, (newValue) => {
|
watch(loading, (newValue) => {
|
||||||
|
if (newValue.barEnabled) {
|
||||||
if (newValue.loading) {
|
if (newValue.loading) {
|
||||||
indicator.start()
|
indicator.start()
|
||||||
} else {
|
} else {
|
||||||
indicator.finish()
|
indicator.finish()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return () =>
|
return () =>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { XIcon, IssuesIcon, LogInIcon } from '@modrinth/assets'
|
import { XIcon, IssuesIcon, LogInIcon, UpdatedIcon } from '@modrinth/assets'
|
||||||
import { Modal } from '@modrinth/ui'
|
import { Modal } from '@modrinth/ui'
|
||||||
import { ChatIcon } from '@/assets/icons'
|
import { ChatIcon } from '@/assets/icons'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
@ -7,9 +7,11 @@ import { login as login_flow, set_default_user } from '@/helpers/auth.js'
|
|||||||
import { handleError } from '@/store/notifications.js'
|
import { handleError } from '@/store/notifications.js'
|
||||||
import mixpanel from 'mixpanel-browser'
|
import mixpanel from 'mixpanel-browser'
|
||||||
import { handleSevereError } from '@/store/error.js'
|
import { handleSevereError } from '@/store/error.js'
|
||||||
|
import { cancel_directory_change } from '@/helpers/settings.js'
|
||||||
|
|
||||||
const errorModal = ref()
|
const errorModal = ref()
|
||||||
const error = ref()
|
const error = ref()
|
||||||
|
const closable = ref(true)
|
||||||
|
|
||||||
const title = ref('An error occurred')
|
const title = ref('An error occurred')
|
||||||
const errorType = ref('unknown')
|
const errorType = ref('unknown')
|
||||||
@ -17,7 +19,9 @@ const supportLink = ref('https://support.modrinth.com')
|
|||||||
const metadata = ref({})
|
const metadata = ref({})
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
async show(errorVal) {
|
async show(errorVal, canClose = true, source = null) {
|
||||||
|
closable.value = canClose
|
||||||
|
|
||||||
if (errorVal.message && errorVal.message.includes('Minecraft authentication error:')) {
|
if (errorVal.message && errorVal.message.includes('Minecraft authentication error:')) {
|
||||||
title.value = 'Unable to sign in to Minecraft'
|
title.value = 'Unable to sign in to Minecraft'
|
||||||
errorType.value = 'minecraft_auth'
|
errorType.value = 'minecraft_auth'
|
||||||
@ -37,6 +41,22 @@ defineExpose({
|
|||||||
title.value = 'Sign in to Minecraft'
|
title.value = 'Sign in to Minecraft'
|
||||||
errorType.value = 'minecraft_sign_in'
|
errorType.value = 'minecraft_sign_in'
|
||||||
supportLink.value = 'https://support.modrinth.com'
|
supportLink.value = 'https://support.modrinth.com'
|
||||||
|
} else if (errorVal.message && errorVal.message.includes('Move directory error:')) {
|
||||||
|
title.value = 'Could not change app directory'
|
||||||
|
errorType.value = 'directory_move'
|
||||||
|
supportLink.value = 'https://support.modrinth.com'
|
||||||
|
|
||||||
|
if (errorVal.message.includes('directory is not writeable')) {
|
||||||
|
metadata.value.readOnly = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorVal.message.includes('Not enough space')) {
|
||||||
|
metadata.value.notEnoughSpace = true
|
||||||
|
}
|
||||||
|
} else if (source === 'state_init') {
|
||||||
|
title.value = 'Error initializing Modrinth App'
|
||||||
|
errorType.value = 'state_init'
|
||||||
|
supportLink.value = 'https://support.modrinth.com'
|
||||||
} else {
|
} else {
|
||||||
title.value = 'An error occurred'
|
title.value = 'An error occurred'
|
||||||
errorType.value = 'unknown'
|
errorType.value = 'unknown'
|
||||||
@ -67,10 +87,23 @@ async function loginMinecraft() {
|
|||||||
handleSevereError(err)
|
handleSevereError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function cancelDirectoryChange() {
|
||||||
|
try {
|
||||||
|
await cancel_directory_change()
|
||||||
|
window.location.reload()
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function retryDirectoryChange() {
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Modal ref="errorModal" :header="title">
|
<Modal ref="errorModal" :header="title" :closable="closable">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="markdown-body">
|
<div class="markdown-body">
|
||||||
<template v-if="errorType === 'minecraft_auth'">
|
<template v-if="errorType === 'minecraft_auth'">
|
||||||
@ -125,30 +158,40 @@ async function loginMinecraft() {
|
|||||||
<LogInIcon /> Try signing in again
|
<LogInIcon /> Try signing in again
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
</template>
|
||||||
|
<template v-if="errorType === 'directory_move'">
|
||||||
|
<template v-if="metadata.readOnly">
|
||||||
|
<h3>Change directory permissions</h3>
|
||||||
<p>
|
<p>
|
||||||
If nothing is working and you need help, visit
|
It looks like the Modrinth App is unable to write to the directory you selected.
|
||||||
<a :href="supportLink">our support page</a>
|
Please adjust the permissions of the directory and try again or cancel the directory
|
||||||
and start a chat using the widget in the bottom right and we will be more than happy to
|
change.
|
||||||
assist! Make sure to provide the following debug information to the agent:
|
|
||||||
</p>
|
</p>
|
||||||
<details>
|
</template>
|
||||||
<summary>Debug information</summary>
|
<template v-else-if="metadata.notEnoughSpace">
|
||||||
{{ error.message ?? error }}
|
<h3>Not enough space</h3>
|
||||||
</details>
|
<p>
|
||||||
|
It looks like there is not enough space on the disk containing the dirctory you
|
||||||
|
selected Please free up some space and try again or cancel the directory change.
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<p>
|
||||||
|
The Modrinth App is unable to migrate to the new directory you selected. Please
|
||||||
|
contact support for help or cancel the directory change.
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="cta-button">
|
||||||
|
<button class="btn" @click="retryDirectoryChange">
|
||||||
|
<UpdatedIcon /> Retry directory change
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-danger" @click="cancelDirectoryChange">
|
||||||
|
<XIcon /> Cancel directory change
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div v-else-if="errorType === 'minecraft_sign_in'">
|
<div v-else-if="errorType === 'minecraft_sign_in'">
|
||||||
<div class="warning-banner">
|
|
||||||
<div class="warning-banner__title">
|
|
||||||
<IssuesIcon />
|
|
||||||
<span>Installed the app before April 23rd, 2024?</span>
|
|
||||||
</div>
|
|
||||||
<div class="warning-banner__description">
|
|
||||||
Modrinth has updated our sign-in workflow to allow for better stability, security, and
|
|
||||||
performance. You must sign in again so your credentials can be upgraded to this new
|
|
||||||
flow.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p>
|
<p>
|
||||||
To play this instance, you must sign in through Microsoft below. If you don't have a
|
To play this instance, you must sign in through Microsoft below. If you don't have a
|
||||||
Minecraft account, you can purchase the game on the
|
Minecraft account, you can purchase the game on the
|
||||||
@ -162,13 +205,43 @@ async function loginMinecraft() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<template v-else-if="errorType === 'state_init'">
|
||||||
|
<p>
|
||||||
|
Modrinth App failed to load correctly. This may be because of a corrupted file, or
|
||||||
|
because the app is missing crucial files.
|
||||||
|
</p>
|
||||||
|
<p>You may be able to fix it through one of the following ways:</p>
|
||||||
|
<ul>
|
||||||
|
<li>Ennsuring you are connected to the internet, then try restarting the app.</li>
|
||||||
|
<li>Redownloading the app.</li>
|
||||||
|
</ul>
|
||||||
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
{{ error.message ?? error }}
|
{{ error.message ?? error }}
|
||||||
</template>
|
</template>
|
||||||
|
<template
|
||||||
|
v-if="
|
||||||
|
errorType === 'directory_move' ||
|
||||||
|
errorType === 'minecraft_auth' ||
|
||||||
|
errorType === 'state_init'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<hr />
|
||||||
|
<p>
|
||||||
|
If nothing is working and you need help, visit
|
||||||
|
<a :href="supportLink">our support page</a>
|
||||||
|
and start a chat using the widget in the bottom right and we will be more than happy to
|
||||||
|
assist! Make sure to provide the following debug information to the agent:
|
||||||
|
</p>
|
||||||
|
<details>
|
||||||
|
<summary>Debug information</summary>
|
||||||
|
{{ error.message ?? error }}
|
||||||
|
</details>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-group push-right">
|
<div class="input-group push-right">
|
||||||
<a :href="supportLink" class="btn" @click="errorModal.hide()"><ChatIcon /> Get support</a>
|
<a :href="supportLink" class="btn" @click="errorModal.hide()"><ChatIcon /> Get support</a>
|
||||||
<button class="btn" @click="errorModal.hide()"><XIcon /> Close</button>
|
<button v-if="closable" class="btn" @click="errorModal.hide()"><XIcon /> Close</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
@ -191,6 +264,7 @@ async function loginMinecraft() {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.warning-banner {
|
.warning-banner {
|
||||||
|
|||||||
@ -81,9 +81,9 @@
|
|||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
v-for="process in currentProcesses"
|
v-for="process in currentProcesses"
|
||||||
:key="process.pid"
|
:key="process.uuid"
|
||||||
class="profile-button"
|
class="profile-button"
|
||||||
@click="selectedProcess(process)"
|
@click="selectProcess(process)"
|
||||||
>
|
>
|
||||||
<div class="text"><span class="circle running" /> {{ process.profile.name }}</div>
|
<div class="text"><span class="circle running" /> {{ process.profile.name }}</div>
|
||||||
<Button
|
<Button
|
||||||
@ -162,8 +162,7 @@ const unlistenProcess = await process_listener(async () => {
|
|||||||
|
|
||||||
const stop = async (process) => {
|
const stop = async (process) => {
|
||||||
try {
|
try {
|
||||||
console.log(process.pid)
|
await killProcess(process.uuid).catch(handleError)
|
||||||
await killProcess(process.pid).catch(handleError)
|
|
||||||
|
|
||||||
mixpanel_track('InstanceStop', {
|
mixpanel_track('InstanceStop', {
|
||||||
loader: process.profile.loader,
|
loader: process.profile.loader,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -16,11 +16,16 @@ const installing = ref(false)
|
|||||||
defineExpose({
|
defineExpose({
|
||||||
async show(event) {
|
async show(event) {
|
||||||
if (event.event === 'InstallVersion') {
|
if (event.event === 'InstallVersion') {
|
||||||
version.value = await get_version(event.id).catch(handleError)
|
version.value = await get_version(event.id, 'must_revalidate').catch(handleError)
|
||||||
project.value = await get_project(version.value.project_id).catch(handleError)
|
project.value = await get_project(version.value.project_id, 'must_revalidate').catch(
|
||||||
|
handleError,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
project.value = await get_project(event.id).catch(handleError)
|
project.value = await get_project(event.id, 'must_revalidate').catch(handleError)
|
||||||
version.value = await get_version(project.value.versions[0]).catch(handleError)
|
version.value = await get_version(
|
||||||
|
project.value.versions[project.value.versions.length - 1],
|
||||||
|
'must_revalidate',
|
||||||
|
).catch(handleError)
|
||||||
}
|
}
|
||||||
categories.value = (await get_categories().catch(handleError)).filter(
|
categories.value = (await get_categories().catch(handleError)).filter(
|
||||||
(cat) => project.value.categories.includes(cat.name) && cat.project_type === 'mod',
|
(cat) => project.value.categories.includes(cat.name) && cat.project_type === 'mod',
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -1,140 +0,0 @@
|
|||||||
<script setup>
|
|
||||||
import { LogInIcon } from '@modrinth/assets'
|
|
||||||
import { Button, Card } from '@modrinth/ui'
|
|
||||||
import { login as login_flow, set_default_user } from '@/helpers/auth.js'
|
|
||||||
import { handleError } from '@/store/notifications.js'
|
|
||||||
import mixpanel from 'mixpanel-browser'
|
|
||||||
import { ref } from 'vue'
|
|
||||||
import { handleSevereError } from '@/store/error.js'
|
|
||||||
const loading = ref(false)
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
nextPage: {
|
|
||||||
type: Function,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
prevPage: {
|
|
||||||
type: Function,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
async function login() {
|
|
||||||
try {
|
|
||||||
loading.value = true
|
|
||||||
const loggedIn = await login_flow()
|
|
||||||
|
|
||||||
if (loggedIn) {
|
|
||||||
await set_default_user(loggedIn.id).catch(handleError)
|
|
||||||
}
|
|
||||||
|
|
||||||
await mixpanel.track('AccountLogIn')
|
|
||||||
loading.value = false
|
|
||||||
props.nextPage()
|
|
||||||
} catch (err) {
|
|
||||||
loading.value = false
|
|
||||||
handleSevereError(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="login-card">
|
|
||||||
<img
|
|
||||||
src="https://launcher-files.modrinth.com/assets/default_profile.png"
|
|
||||||
class="logo"
|
|
||||||
alt="Minecraft art"
|
|
||||||
/>
|
|
||||||
<Card class="logging-in">
|
|
||||||
<h2>Sign into Minecraft</h2>
|
|
||||||
<p>
|
|
||||||
Sign in with your Microsoft account to launch Minecraft with your mods and modpacks. If you
|
|
||||||
don't have a Minecraft account, you can purchase the game on the
|
|
||||||
<a
|
|
||||||
href="https://www.minecraft.net/en-us/store/minecraft-java-bedrock-edition-pc"
|
|
||||||
class="link"
|
|
||||||
>
|
|
||||||
Minecraft website
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<div class="action-row">
|
|
||||||
<Button class="transparent" large @click="prevPage"> Back </Button>
|
|
||||||
<div class="sign-in-pair">
|
|
||||||
<Button color="primary" large :disabled="loading" @click="login">
|
|
||||||
<LogInIcon />
|
|
||||||
{{ loading ? 'Loading...' : 'Sign in' }}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<Button class="transparent" large @click="nextPage()"> Finish</Button>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.login-card {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
margin: auto;
|
|
||||||
padding: var(--gap-lg);
|
|
||||||
width: 30rem;
|
|
||||||
|
|
||||||
img {
|
|
||||||
width: 100%;
|
|
||||||
border-radius: var(--radius-lg) var(--radius-lg) 0 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.logging-in {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
vertical-align: center;
|
|
||||||
gap: var(--gap-md);
|
|
||||||
background-color: var(--color-raised-bg);
|
|
||||||
width: 100%;
|
|
||||||
border-radius: 0 0 var(--radius-lg) var(--radius-lg);
|
|
||||||
|
|
||||||
h2,
|
|
||||||
p {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.link {
|
|
||||||
color: var(--color-blue);
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button-row {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-row {
|
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: var(--gap-md);
|
|
||||||
margin-top: var(--gap-md);
|
|
||||||
|
|
||||||
.transparent {
|
|
||||||
padding: 0 var(--gap-md);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.sign-in-pair {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: var(--gap-sm);
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@ -1,284 +0,0 @@
|
|||||||
<script setup>
|
|
||||||
import { Button } from '@modrinth/ui'
|
|
||||||
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'
|
|
||||||
|
|
||||||
const page = ref(1)
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
finish: {
|
|
||||||
type: Function,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const flow = ref('')
|
|
||||||
|
|
||||||
const nextPage = (newFlow) => {
|
|
||||||
page.value++
|
|
||||||
mixpanel.track('OnboardingPage', { page: page.value })
|
|
||||||
|
|
||||||
if (newFlow) {
|
|
||||||
flow.value = newFlow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const prevPage = () => {
|
|
||||||
page.value--
|
|
||||||
}
|
|
||||||
|
|
||||||
const finishOnboarding = async () => {
|
|
||||||
mixpanel.track('OnboardingFinish')
|
|
||||||
const settings = await get()
|
|
||||||
settings.onboarded = true
|
|
||||||
await set(settings)
|
|
||||||
props.finish()
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="onboarding">
|
|
||||||
<StickyTitleBar />
|
|
||||||
<GalleryImage
|
|
||||||
v-if="page === 1"
|
|
||||||
:gallery="[
|
|
||||||
{
|
|
||||||
url: 'https://launcher-files.modrinth.com/onboarding/home.png',
|
|
||||||
title: 'Discovery',
|
|
||||||
subtitle: 'See the latest and greatest mods and modpacks to play with from Modrinth',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: 'https://launcher-files.modrinth.com/onboarding/discover.png',
|
|
||||||
title: 'Profile Management',
|
|
||||||
subtitle:
|
|
||||||
'Play, manage and search through all the amazing profiles downloaded on your computer at any time, even offline!',
|
|
||||||
},
|
|
||||||
]"
|
|
||||||
logo
|
|
||||||
>
|
|
||||||
<Button color="primary" @click="nextPage"> Get started </Button>
|
|
||||||
</GalleryImage>
|
|
||||||
<LoginCard v-else-if="page === 2" :next-page="finishOnboarding" :prev-page="prevPage" />
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.sleek-primary {
|
|
||||||
background-color: var(--color-brand-highlight);
|
|
||||||
transition: all ease-in-out 0.1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navigation-controls {
|
|
||||||
flex-grow: 1;
|
|
||||||
width: min-content;
|
|
||||||
}
|
|
||||||
|
|
||||||
.window-controls {
|
|
||||||
z-index: 20;
|
|
||||||
display: none;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.25rem;
|
|
||||||
|
|
||||||
.titlebar-button {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all ease-in-out 0.1s;
|
|
||||||
background-color: var(--color-raised-bg);
|
|
||||||
color: var(--color-base);
|
|
||||||
|
|
||||||
&.close {
|
|
||||||
&:hover,
|
|
||||||
&:active {
|
|
||||||
background-color: var(--color-red);
|
|
||||||
color: var(--color-accent-contrast);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover,
|
|
||||||
&:active {
|
|
||||||
background-color: var(--color-button-bg);
|
|
||||||
color: var(--color-contrast);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
--appbar-height: 3.25rem;
|
|
||||||
--sidebar-width: 4.5rem;
|
|
||||||
|
|
||||||
height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
.view {
|
|
||||||
width: calc(100% - var(--sidebar-width));
|
|
||||||
|
|
||||||
.appbar {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
background: var(--color-raised-bg);
|
|
||||||
box-shadow: var(--shadow-inset-sm), var(--shadow-floating);
|
|
||||||
padding: var(--gap-md);
|
|
||||||
height: 3.25rem;
|
|
||||||
gap: var(--gap-sm);
|
|
||||||
user-select: none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.router-view {
|
|
||||||
width: 100%;
|
|
||||||
height: calc(100% - 3.125rem);
|
|
||||||
overflow: auto;
|
|
||||||
overflow-x: hidden;
|
|
||||||
background-color: var(--color-bg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
height: 100%;
|
|
||||||
background-color: var(--color-raised-bg);
|
|
||||||
box-shadow: var(--shadow-inset-sm), var(--shadow-floating);
|
|
||||||
padding: var(--gap-md);
|
|
||||||
width: var(--sidebar-width);
|
|
||||||
max-width: var(--sidebar-width);
|
|
||||||
min-width: var(--sidebar-width);
|
|
||||||
|
|
||||||
--sidebar-width: 4.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pages-list {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-start;
|
|
||||||
justify-content: flex-start;
|
|
||||||
width: 100%;
|
|
||||||
gap: 0.5rem;
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
background-color: var(--color-raised-bg);
|
|
||||||
height: 3rem !important;
|
|
||||||
width: 3rem !important;
|
|
||||||
padding: 0.75rem;
|
|
||||||
border-radius: var(--radius-md);
|
|
||||||
box-shadow: none;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: 1.5rem !important;
|
|
||||||
height: 1.5rem !important;
|
|
||||||
max-width: 1.5rem !important;
|
|
||||||
max-height: 1.5rem !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.active {
|
|
||||||
background-color: var(--color-button-bg);
|
|
||||||
box-shadow: var(--shadow-floating);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.sleek-primary {
|
|
||||||
background-color: var(--color-brand-highlight);
|
|
||||||
transition: all ease-in-out 0.1s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-section {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: flex-start;
|
|
||||||
align-items: center;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
gap: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sticky-tip {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
right: 1rem;
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
.intro-card {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: var(--gap-xl);
|
|
||||||
|
|
||||||
.app-logo {
|
|
||||||
width: 100%;
|
|
||||||
height: auto;
|
|
||||||
display: block;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
color: var(--color-contrast);
|
|
||||||
text-align: left;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.actions {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: flex-end;
|
|
||||||
gap: var(--gap-sm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.final-tip {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 50%;
|
|
||||||
right: 50%;
|
|
||||||
transform: translate(50%, 50%);
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
.onboarding {
|
|
||||||
background:
|
|
||||||
top linear-gradient(0deg, #31375f, rgba(8, 14, 55, 0)),
|
|
||||||
url(https://cdn.modrinth.com/landing-new/landing-lower.webp);
|
|
||||||
background-size: cover;
|
|
||||||
height: 100vh;
|
|
||||||
min-height: 100vh;
|
|
||||||
max-height: 100vh;
|
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
padding: var(--gap-xl);
|
|
||||||
padding-top: calc(2.5rem + var(--gap-lg));
|
|
||||||
}
|
|
||||||
|
|
||||||
.first-tip {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
.whole-page-shadow {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100vw;
|
|
||||||
height: 100%;
|
|
||||||
backdrop-filter: brightness(0.5);
|
|
||||||
-webkit-backdrop-filter: brightness(0.5);
|
|
||||||
z-index: 9;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@ -1,81 +0,0 @@
|
|||||||
<script setup>
|
|
||||||
import { Button } from '@modrinth/ui'
|
|
||||||
import { XIcon } from '@modrinth/assets'
|
|
||||||
import { appWindow } from '@tauri-apps/api/window'
|
|
||||||
import { saveWindowState, StateFlags } from 'tauri-plugin-window-state-api'
|
|
||||||
import { window } from '@tauri-apps/api'
|
|
||||||
import { MinimizeIcon, MaximizeIcon } from '@/assets/icons'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div data-tauri-drag-region class="fake-appbar">
|
|
||||||
<section class="window-controls">
|
|
||||||
<Button class="titlebar-button" icon-only @click="() => appWindow.minimize()">
|
|
||||||
<MinimizeIcon />
|
|
||||||
</Button>
|
|
||||||
<Button class="titlebar-button" icon-only @click="() => appWindow.toggleMaximize()">
|
|
||||||
<MaximizeIcon />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
class="titlebar-button close"
|
|
||||||
icon-only
|
|
||||||
@click="
|
|
||||||
() => {
|
|
||||||
saveWindowState(StateFlags.ALL)
|
|
||||||
window.getCurrent().close()
|
|
||||||
}
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<XIcon />
|
|
||||||
</Button>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.fake-appbar {
|
|
||||||
position: absolute;
|
|
||||||
width: 100vw;
|
|
||||||
top: 0;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: flex-end;
|
|
||||||
align-items: center;
|
|
||||||
height: 2.25rem;
|
|
||||||
background-color: var(--color-raised-bg);
|
|
||||||
-webkit-app-region: drag;
|
|
||||||
z-index: 10000;
|
|
||||||
}
|
|
||||||
|
|
||||||
.window-controls {
|
|
||||||
display: none;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
.titlebar-button {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all ease-in-out 0.1s;
|
|
||||||
background-color: var(--color-raised-bg);
|
|
||||||
color: var(--color-base);
|
|
||||||
border-radius: 0;
|
|
||||||
height: 2.25rem;
|
|
||||||
|
|
||||||
&.close {
|
|
||||||
&:hover,
|
|
||||||
&:active {
|
|
||||||
background-color: var(--color-red);
|
|
||||||
color: var(--color-accent-contrast);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover,
|
|
||||||
&:active {
|
|
||||||
background-color: var(--color-button-bg);
|
|
||||||
color: var(--color-contrast);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@ -1,49 +1,53 @@
|
|||||||
import { invoke } from '@tauri-apps/api/tauri'
|
import { invoke } from '@tauri-apps/api/tauri'
|
||||||
|
|
||||||
export async function get_project(id) {
|
export async function get_project(id, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_project', { id })
|
return await invoke('plugin:cache|get_project', { id, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_project_many(ids) {
|
export async function get_project_many(ids, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_project_many', { ids })
|
return await invoke('plugin:cache|get_project_many', { ids, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_version(id) {
|
export async function get_version(id, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_version', { id })
|
return await invoke('plugin:cache|get_version', { id, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_version_many(ids) {
|
export async function get_version_many(ids, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_version_many', { ids })
|
return await invoke('plugin:cache|get_version_many', { ids, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_user(id) {
|
export async function get_user(id, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_user', { id })
|
return await invoke('plugin:cache|get_user', { id, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_user_many(ids) {
|
export async function get_user_many(ids, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_user_many', { ids })
|
return await invoke('plugin:cache|get_user_many', { ids, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_team(id) {
|
export async function get_team(id, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_team', { id })
|
return await invoke('plugin:cache|get_team', { id, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_team_many(ids) {
|
export async function get_team_many(ids, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_team_many', { ids })
|
return await invoke('plugin:cache|get_team_many', { ids, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_organization(id) {
|
export async function get_organization(id, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_organization', { id })
|
return await invoke('plugin:cache|get_organization', { id, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_organization_many(ids) {
|
export async function get_organization_many(ids, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_organization_many', { ids })
|
return await invoke('plugin:cache|get_organization_many', { ids, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_search_results(id) {
|
export async function get_search_results(id, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_search_results', { id })
|
return await invoke('plugin:cache|get_search_results', { id, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_search_results_many(ids) {
|
export async function get_search_results_many(ids, cacheBehaviour) {
|
||||||
return await invoke('plugin:cache|get_search_results_many', { ids })
|
return await invoke('plugin:cache|get_search_results_many', { ids, cacheBehaviour })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function purge_cache_types(cacheTypes) {
|
||||||
|
return await invoke('plugin:cache|purge_cache_types', { cacheTypes })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,6 @@ export async function get_all() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Kills a process by UUID
|
/// Kills a process by UUID
|
||||||
export async function kill(pid) {
|
export async function kill(uuid) {
|
||||||
return await invoke('plugin:process|process_kill', { pid })
|
return await invoke('plugin:process|process_kill', { uuid })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,8 +51,8 @@ export async function get_many(paths) {
|
|||||||
|
|
||||||
// Get a profile's projects
|
// Get a profile's projects
|
||||||
// Returns a map of a path to profile file
|
// Returns a map of a path to profile file
|
||||||
export async function get_projects(path) {
|
export async function get_projects(path, cacheBehaviour) {
|
||||||
return await invoke('plugin:profile|profile_get_projects', { path })
|
return await invoke('plugin:profile|profile_get_projects', { path, cacheBehaviour })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a profile's full fs path
|
// Get a profile's full fs path
|
||||||
|
|||||||
@ -38,12 +38,6 @@ export async function set(settings) {
|
|||||||
return await invoke('plugin:settings|settings_set', { settings })
|
return await invoke('plugin:settings|settings_set', { settings })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes the config dir
|
export async function cancel_directory_change() {
|
||||||
// Seizes the entire application state until its done
|
return await invoke('plugin:settings|cancel_directory_change')
|
||||||
export async function change_config_dir(newConfigDir) {
|
|
||||||
return await invoke('plugin:settings|settings_change_config_dir', { newConfigDir })
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function is_dir_writeable(newConfigDir) {
|
|
||||||
return await invoke('plugin:settings|settings_is_dir_writeable', { newConfigDir })
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,15 +2,9 @@ import { createApp } from 'vue'
|
|||||||
import router from '@/routes'
|
import router from '@/routes'
|
||||||
import App from '@/App.vue'
|
import App from '@/App.vue'
|
||||||
import { createPinia } from 'pinia'
|
import { createPinia } from 'pinia'
|
||||||
import '@modrinth/assets/omorphia.scss'
|
|
||||||
import '@/assets/stylesheets/global.scss'
|
|
||||||
import FloatingVue from 'floating-vue'
|
import FloatingVue from 'floating-vue'
|
||||||
import 'floating-vue/dist/style.css'
|
import 'floating-vue/dist/style.css'
|
||||||
import { get_opening_command, initialize_state } from '@/helpers/state'
|
|
||||||
import loadCssMixin from './mixins/macCssFix.js'
|
import loadCssMixin from './mixins/macCssFix.js'
|
||||||
import { get } from '@/helpers/settings'
|
|
||||||
import { invoke } from '@tauri-apps/api'
|
|
||||||
import { isDev } from './helpers/utils.js'
|
|
||||||
import { createPlugin } from '@vintl/vintl/plugin'
|
import { createPlugin } from '@vintl/vintl/plugin'
|
||||||
|
|
||||||
const VIntlPlugin = createPlugin({
|
const VIntlPlugin = createPlugin({
|
||||||
@ -39,45 +33,4 @@ app.use(FloatingVue)
|
|||||||
app.mixin(loadCssMixin)
|
app.mixin(loadCssMixin)
|
||||||
app.use(VIntlPlugin)
|
app.use(VIntlPlugin)
|
||||||
|
|
||||||
const mountedApp = app.mount('#app')
|
app.mount('#app')
|
||||||
|
|
||||||
const raw_invoke = async (plugin, fn, args) => {
|
|
||||||
if (plugin === '') {
|
|
||||||
await invoke(fn, args)
|
|
||||||
} else {
|
|
||||||
await invoke('plugin:' + plugin + '|' + fn, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isDev()
|
|
||||||
.then((dev) => {
|
|
||||||
if (dev) {
|
|
||||||
window.raw_invoke = raw_invoke
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err)
|
|
||||||
})
|
|
||||||
|
|
||||||
initialize_state()
|
|
||||||
.then(() => {
|
|
||||||
// First, redirect to other landing page if we have that setting
|
|
||||||
get()
|
|
||||||
.then((fetchSettings) => {
|
|
||||||
if (fetchSettings?.default_page && fetchSettings?.default_page !== 'Home') {
|
|
||||||
router.push({ name: fetchSettings?.default_page })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err)
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
mountedApp.initialize()
|
|
||||||
get_opening_command().then((command) => {
|
|
||||||
console.log(JSON.stringify(command)) // change me to use whatever FE command handler is made
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error('Failed to initialize app', err)
|
|
||||||
mountedApp.failure(err)
|
|
||||||
})
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed, nextTick, ref, readonly, shallowRef, watch, onUnmounted } from 'vue'
|
import { computed, nextTick, ref, readonly, shallowRef, watch } from 'vue'
|
||||||
import { ClearIcon, SearchIcon, ClientIcon, ServerIcon, XIcon } from '@modrinth/assets'
|
import { ClearIcon, SearchIcon, ClientIcon, ServerIcon, XIcon } from '@modrinth/assets'
|
||||||
import {
|
import {
|
||||||
Pagination,
|
Pagination,
|
||||||
@ -19,7 +19,6 @@ import { useBreadcrumbs } from '@/store/breadcrumbs'
|
|||||||
import { get_categories, get_loaders, get_game_versions } from '@/helpers/tags'
|
import { get_categories, get_loaders, get_game_versions } from '@/helpers/tags'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import SearchCard from '@/components/ui/SearchCard.vue'
|
import SearchCard from '@/components/ui/SearchCard.vue'
|
||||||
import SplashScreen from '@/components/ui/SplashScreen.vue'
|
|
||||||
import { get as getInstance, get_projects as getInstanceProjects } from '@/helpers/profile.js'
|
import { get as getInstance, get_projects as getInstanceProjects } from '@/helpers/profile.js'
|
||||||
import { convertFileSrc } from '@tauri-apps/api/tauri'
|
import { convertFileSrc } from '@tauri-apps/api/tauri'
|
||||||
import { get_search_results } from '@/helpers/cache.js'
|
import { get_search_results } from '@/helpers/cache.js'
|
||||||
@ -233,14 +232,14 @@ async function refreshSearch() {
|
|||||||
if (currentPage.value !== 1) {
|
if (currentPage.value !== 1) {
|
||||||
params.push(`offset=${offset}`)
|
params.push(`offset=${offset}`)
|
||||||
}
|
}
|
||||||
let url = 'search'
|
let url = ''
|
||||||
if (params.length > 0) {
|
if (params.length > 0) {
|
||||||
for (let i = 0; i < params.length; i++) {
|
for (let i = 0; i < params.length; i++) {
|
||||||
url += i === 0 ? `?${params[i]}` : `&${params[i]}`
|
url += i === 0 ? `?${params[i]}` : `&${params[i]}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let rawResults = await get_search_results(`?${url}`)
|
let rawResults = await get_search_results(`${url}`)
|
||||||
if (!rawResults) {
|
if (!rawResults) {
|
||||||
rawResults = {
|
rawResults = {
|
||||||
result: {
|
result: {
|
||||||
@ -585,7 +584,10 @@ const isModProject = computed(() => ['modpack', 'mod'].includes(projectType.valu
|
|||||||
<ClearIcon /> Clear filters
|
<ClearIcon /> Clear filters
|
||||||
</Button>
|
</Button>
|
||||||
<div
|
<div
|
||||||
v-if="(isModProject && ignoreInstanceLoaders) || projectType === 'shader'"
|
v-if="
|
||||||
|
(isModProject && (ignoreInstanceLoaders || !instanceContext)) ||
|
||||||
|
projectType === 'shader'
|
||||||
|
"
|
||||||
class="loaders"
|
class="loaders"
|
||||||
>
|
>
|
||||||
<h2>Loaders</h2>
|
<h2>Loaders</h2>
|
||||||
@ -721,7 +723,7 @@ const isModProject = computed(() => ['modpack', 'mod'].includes(projectType.valu
|
|||||||
class="pagination-before"
|
class="pagination-before"
|
||||||
@switch-page="onSearchChange"
|
@switch-page="onSearchChange"
|
||||||
/>
|
/>
|
||||||
<SplashScreen v-if="loading" />
|
<section v-if="loading" class="offline">Loading...</section>
|
||||||
<section v-else-if="offline && results.total_hits === 0" class="offline">
|
<section v-else-if="offline && results.total_hits === 0" class="offline">
|
||||||
You are currently offline. Connect to the internet to browse Modrinth!
|
You are currently offline. Connect to the internet to browse Modrinth!
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import { LogOutIcon, LogInIcon, BoxIcon, FolderSearchIcon, UpdatedIcon } from '@modrinth/assets'
|
import { LogOutIcon, LogInIcon, BoxIcon, FolderSearchIcon, TrashIcon } from '@modrinth/assets'
|
||||||
import { Card, Slider, DropdownSelect, Toggle, Modal, Button } from '@modrinth/ui'
|
import { Card, Slider, DropdownSelect, Toggle, ConfirmModal, Button } from '@modrinth/ui'
|
||||||
import { handleError, useTheming } from '@/store/state'
|
import { handleError, useTheming } from '@/store/state'
|
||||||
import { is_dir_writeable, change_config_dir, get, set } from '@/helpers/settings'
|
import { get, set } from '@/helpers/settings'
|
||||||
import { get_java_versions, get_max_memory, set_java_version } from '@/helpers/jre'
|
import { get_java_versions, get_max_memory, set_java_version } from '@/helpers/jre'
|
||||||
import { get as getCreds, logout } from '@/helpers/mr_auth.js'
|
import { get as getCreds, logout } from '@/helpers/mr_auth.js'
|
||||||
import JavaSelector from '@/components/ui/JavaSelector.vue'
|
import JavaSelector from '@/components/ui/JavaSelector.vue'
|
||||||
@ -12,7 +12,7 @@ import { mixpanel_opt_out_tracking, mixpanel_opt_in_tracking } from '@/helpers/m
|
|||||||
import { open } from '@tauri-apps/api/dialog'
|
import { open } from '@tauri-apps/api/dialog'
|
||||||
import { getOS } from '@/helpers/utils.js'
|
import { getOS } from '@/helpers/utils.js'
|
||||||
import { getVersion } from '@tauri-apps/api/app'
|
import { getVersion } from '@tauri-apps/api/app'
|
||||||
import { get_user } from '@/helpers/cache.js'
|
import { get_user, purge_cache_types } from '@/helpers/cache.js'
|
||||||
|
|
||||||
const pageOptions = ['Home', 'Library']
|
const pageOptions = ['Home', 'Library']
|
||||||
|
|
||||||
@ -32,7 +32,6 @@ const accessSettings = async () => {
|
|||||||
const fetchSettings = await accessSettings().catch(handleError)
|
const fetchSettings = await accessSettings().catch(handleError)
|
||||||
|
|
||||||
const settings = ref(fetchSettings)
|
const settings = ref(fetchSettings)
|
||||||
// const settingsDir = ref(settings.value.loaded_config_dir)
|
|
||||||
|
|
||||||
const maxMemory = ref(Math.floor((await get_max_memory().catch(handleError)) / 1024))
|
const maxMemory = ref(Math.floor((await get_max_memory().catch(handleError)) / 1024))
|
||||||
|
|
||||||
@ -124,6 +123,25 @@ async function findLauncherDir() {
|
|||||||
settings.value.custom_dir = newDir
|
settings.value.custom_dir = newDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function purgeCache() {
|
||||||
|
await purge_cache_types([
|
||||||
|
'project',
|
||||||
|
'version',
|
||||||
|
'user',
|
||||||
|
'team',
|
||||||
|
'organization',
|
||||||
|
'loader_manifest',
|
||||||
|
'minecraft_manifest',
|
||||||
|
'categories',
|
||||||
|
'report_types',
|
||||||
|
'loaders',
|
||||||
|
'game_versions',
|
||||||
|
'donation_platforms',
|
||||||
|
'file_update',
|
||||||
|
'search_results',
|
||||||
|
]).catch(handleError)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -136,26 +154,50 @@ async function findLauncherDir() {
|
|||||||
</div>
|
</div>
|
||||||
<ModrinthLoginScreen ref="loginScreenModal" :callback="signInAfter" />
|
<ModrinthLoginScreen ref="loginScreenModal" :callback="signInAfter" />
|
||||||
<div class="adjacent-input">
|
<div class="adjacent-input">
|
||||||
<label for="theme">
|
<label for="sign-in">
|
||||||
<span class="label__title">Manage account</span>
|
<span class="label__title">Manage account</span>
|
||||||
<span v-if="credentials" class="label__description">
|
<span v-if="credentials" class="label__description">
|
||||||
You are currently logged in as {{ credentials.user.username }}.
|
You are currently logged in as {{ credentials.user.username }}.
|
||||||
</span>
|
</span>
|
||||||
<span v-else> Sign in to your Modrinth account. </span>
|
<span v-else> Sign in to your Modrinth account. </span>
|
||||||
</label>
|
</label>
|
||||||
<button v-if="credentials" class="btn" @click="logOut">
|
<button v-if="credentials" id="sign-in" class="btn" @click="logOut">
|
||||||
<LogOutIcon />
|
<LogOutIcon />
|
||||||
Sign out
|
Sign out
|
||||||
</button>
|
</button>
|
||||||
<button v-else class="btn" @click="$refs.loginScreenModal.show()">
|
<button v-else id="sign-in" class="btn" @click="$refs.loginScreenModal.show()">
|
||||||
<LogInIcon />
|
<LogInIcon />
|
||||||
Sign in
|
Sign in
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<label for="theme">
|
<ConfirmModal
|
||||||
|
ref="purgeCacheConfirmModal"
|
||||||
|
title="Are you sure you want to purge the cache?"
|
||||||
|
description="If you proceed, your entire cache will be purged. This may slow down the app temporarily."
|
||||||
|
:has-to-type="false"
|
||||||
|
proceed-label="Purge cache"
|
||||||
|
:noblur="!themeStore.advancedRendering"
|
||||||
|
@proceed="purgeCache"
|
||||||
|
/>
|
||||||
|
<div class="adjacent-input">
|
||||||
|
<label for="purge-cache">
|
||||||
|
<span class="label__title">App cache</span>
|
||||||
|
<span class="label__description">
|
||||||
|
The Modrinth app stores a cache of data to speed up loading. This can be purged to force
|
||||||
|
the app to reload data. <br />
|
||||||
|
This may slow down the app temporarily.
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<button id="purge-cache" class="btn" @click="$refs.purgeCacheConfirmModal.show()">
|
||||||
|
<TrashIcon />
|
||||||
|
Purge cache
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<label for="appDir">
|
||||||
<span class="label__title">App directory</span>
|
<span class="label__title">App directory</span>
|
||||||
<span class="label__description">
|
<span class="label__description">
|
||||||
The directory where the launcher stores all of its files.
|
The directory where the launcher stores all of its files. Changes will be applied after
|
||||||
|
restarting the launcher.
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="app-directory">
|
<div class="app-directory">
|
||||||
|
|||||||
@ -174,9 +174,13 @@ const options = ref(null)
|
|||||||
|
|
||||||
const startInstance = async (context) => {
|
const startInstance = async (context) => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
run(route.params.id).catch(handleSevereError)
|
try {
|
||||||
loading.value = false
|
await run(route.params.id)
|
||||||
playing.value = true
|
playing.value = true
|
||||||
|
} catch (err) {
|
||||||
|
handleSevereError(err)
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
|
|
||||||
mixpanel_track('InstanceStart', {
|
mixpanel_track('InstanceStart', {
|
||||||
loader: instance.value.loader,
|
loader: instance.value.loader,
|
||||||
@ -194,13 +198,19 @@ const checkProcess = async () => {
|
|||||||
// Get information on associated modrinth versions, if any
|
// Get information on associated modrinth versions, if any
|
||||||
const modrinthVersions = ref([])
|
const modrinthVersions = ref([])
|
||||||
if (!offline.value && instance.value.linked_data && instance.value.linked_data.project_id) {
|
if (!offline.value && instance.value.linked_data && instance.value.linked_data.project_id) {
|
||||||
const project = await get_project(instance.value.linked_data.project_id).catch(handleError)
|
get_project(instance.value.linked_data.project_id, 'must_revalidate')
|
||||||
|
.catch(handleError)
|
||||||
|
.then((project) => {
|
||||||
if (project && project.versions) {
|
if (project && project.versions) {
|
||||||
modrinthVersions.value = (await get_version_many(project.versions).catch(handleError)).sort(
|
get_version_many(project.versions, 'must_revalidate')
|
||||||
|
.catch(handleError)
|
||||||
|
.then((versions) => {
|
||||||
|
modrinthVersions.value = versions.sort(
|
||||||
(a, b) => dayjs(b.date_published) - dayjs(a.date_published),
|
(a, b) => dayjs(b.date_published) - dayjs(a.date_published),
|
||||||
)
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
await checkProcess()
|
await checkProcess()
|
||||||
|
|||||||
@ -25,13 +25,21 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<Button
|
||||||
|
v-tooltip="'Refresh projects'"
|
||||||
|
icon-only
|
||||||
|
:disabled="refreshingProjects"
|
||||||
|
@click="refreshProjects"
|
||||||
|
>
|
||||||
|
<UpdatedIcon />
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
v-if="canUpdatePack"
|
v-if="canUpdatePack"
|
||||||
:disabled="installing"
|
:disabled="installing"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
@click="modpackVersionModal.show()"
|
@click="modpackVersionModal.show()"
|
||||||
>
|
>
|
||||||
<UpdatedIcon />
|
<DownloadIcon />
|
||||||
{{ installing ? 'Updating' : 'Update modpack' }}
|
{{ installing ? 'Updating' : 'Update modpack' }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button v-else-if="!isPackLocked" @click="exportModal.show()">
|
<Button v-else-if="!isPackLocked" @click="exportModal.show()">
|
||||||
@ -39,7 +47,7 @@
|
|||||||
Export modpack
|
Export modpack
|
||||||
</Button>
|
</Button>
|
||||||
<Button v-if="!isPackLocked && projects.some((m) => m.outdated)" @click="updateAll">
|
<Button v-if="!isPackLocked && projects.some((m) => m.outdated)" @click="updateAll">
|
||||||
<UpdatedIcon />
|
<DownloadIcon />
|
||||||
Update all
|
Update all
|
||||||
</Button>
|
</Button>
|
||||||
<AddContentButton v-if="!isPackLocked" :instance="instance" />
|
<AddContentButton v-if="!isPackLocked" :instance="instance" />
|
||||||
@ -347,6 +355,7 @@ import {
|
|||||||
EyeIcon,
|
EyeIcon,
|
||||||
EyeOffIcon,
|
EyeOffIcon,
|
||||||
CodeIcon,
|
CodeIcon,
|
||||||
|
DownloadIcon,
|
||||||
} from '@modrinth/assets'
|
} from '@modrinth/assets'
|
||||||
import {
|
import {
|
||||||
Pagination,
|
Pagination,
|
||||||
@ -438,10 +447,10 @@ const exportModal = ref(null)
|
|||||||
const projects = ref([])
|
const projects = ref([])
|
||||||
const selectionMap = ref(new Map())
|
const selectionMap = ref(new Map())
|
||||||
|
|
||||||
const initProjects = async () => {
|
const initProjects = async (cacheBehaviour) => {
|
||||||
const newProjects = []
|
const newProjects = []
|
||||||
|
|
||||||
const profileProjects = await get_projects(props.instance.path)
|
const profileProjects = await get_projects(props.instance.path, cacheBehaviour)
|
||||||
const fetchProjects = []
|
const fetchProjects = []
|
||||||
const fetchVersions = []
|
const fetchVersions = []
|
||||||
|
|
||||||
@ -536,7 +545,7 @@ const ascending = ref(true)
|
|||||||
const sortColumn = ref('Name')
|
const sortColumn = ref('Name')
|
||||||
const currentPage = ref(1)
|
const currentPage = ref(1)
|
||||||
|
|
||||||
watch(searchFilter, () => (currentPage.value = 1))
|
watch([searchFilter, selectedProjectType], () => (currentPage.value = 1))
|
||||||
|
|
||||||
const selected = computed(() =>
|
const selected = computed(() =>
|
||||||
Array.from(selectionMap.value)
|
Array.from(selectionMap.value)
|
||||||
@ -846,18 +855,25 @@ watch(selectAll, () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const switchPage = (page) => {
|
||||||
|
currentPage.value = page
|
||||||
|
}
|
||||||
|
|
||||||
|
const refreshingProjects = ref(false)
|
||||||
|
async function refreshProjects() {
|
||||||
|
refreshingProjects.value = true
|
||||||
|
await initProjects('bypass')
|
||||||
|
refreshingProjects.value = false
|
||||||
|
}
|
||||||
|
|
||||||
const unlisten = await listen('tauri://file-drop', async (event) => {
|
const unlisten = await listen('tauri://file-drop', async (event) => {
|
||||||
for (const file of event.payload) {
|
for (const file of event.payload) {
|
||||||
if (file.endsWith('.mrpack')) continue
|
if (file.endsWith('.mrpack')) continue
|
||||||
await add_project_from_path(props.instance.path, file).catch(handleError)
|
await add_project_from_path(props.instance.path, file).catch(handleError)
|
||||||
}
|
}
|
||||||
initProjects(await get(props.instance.path).catch(handleError))
|
await initProjects()
|
||||||
})
|
})
|
||||||
|
|
||||||
const switchPage = (page) => {
|
|
||||||
currentPage.value = page
|
|
||||||
}
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
unlisten()
|
unlisten()
|
||||||
})
|
})
|
||||||
|
|||||||
@ -280,12 +280,12 @@ const installed = ref(false)
|
|||||||
const installedVersion = ref(null)
|
const installedVersion = ref(null)
|
||||||
|
|
||||||
async function fetchProjectData() {
|
async function fetchProjectData() {
|
||||||
const project = await get_project(route.params.id).catch(handleError)
|
const project = await get_project(route.params.id, 'must_revalidate').catch(handleError)
|
||||||
|
|
||||||
data.value = project
|
data.value = project
|
||||||
;[versions.value, members.value, categories.value, instance.value, instanceProjects.value] =
|
;[versions.value, members.value, categories.value, instance.value, instanceProjects.value] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
get_version_many(project.versions).catch(handleError),
|
get_version_many(project.versions, 'must_revalidate').catch(handleError),
|
||||||
get_team(project.team).catch(handleError),
|
get_team(project.team).catch(handleError),
|
||||||
get_categories().catch(handleError),
|
get_categories().catch(handleError),
|
||||||
route.query.i ? getInstance(route.query.i).catch(handleError) : Promise.resolve(),
|
route.query.i ? getInstance(route.query.i).catch(handleError) : Promise.resolve(),
|
||||||
|
|||||||
@ -15,6 +15,7 @@ export const useBreadcrumbs = defineStore('breadcrumbsStore', {
|
|||||||
},
|
},
|
||||||
// resets breadcrumbs to only included ones as to not have stale breadcrumbs
|
// resets breadcrumbs to only included ones as to not have stale breadcrumbs
|
||||||
resetToNames(breadcrumbs) {
|
resetToNames(breadcrumbs) {
|
||||||
|
if (!breadcrumbs) return
|
||||||
// names is an array of every breadcrumb.name that starts with a ?
|
// names is an array of every breadcrumb.name that starts with a ?
|
||||||
const names = breadcrumbs
|
const names = breadcrumbs
|
||||||
.filter((breadcrumb) => breadcrumb.name.charAt(0) === '?')
|
.filter((breadcrumb) => breadcrumb.name.charAt(0) === '?')
|
||||||
|
|||||||
@ -8,8 +8,8 @@ export const useError = defineStore('errorsStore', {
|
|||||||
setErrorModal(ref) {
|
setErrorModal(ref) {
|
||||||
this.errorModal = ref
|
this.errorModal = ref
|
||||||
},
|
},
|
||||||
showError(error) {
|
showError(error, closable = true, source = null) {
|
||||||
this.errorModal.show(error)
|
this.errorModal.show(error, closable, source)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -42,7 +42,7 @@ export const useInstall = defineStore('installStore', {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const install = async (projectId, versionId, instancePath, source, callback = () => {}) => {
|
export const install = async (projectId, versionId, instancePath, source, callback = () => {}) => {
|
||||||
const project = await get_project(projectId).catch(handleError)
|
const project = await get_project(projectId, 'must_revalidate').catch(handleError)
|
||||||
|
|
||||||
if (project.project_type === 'modpack') {
|
if (project.project_type === 'modpack') {
|
||||||
const version = versionId ?? project.versions[project.versions.length - 1]
|
const version = versionId ?? project.versions[project.versions.length - 1]
|
||||||
@ -68,7 +68,7 @@ export const install = async (projectId, versionId, instancePath, source, callba
|
|||||||
const [instance, instanceProjects, versions] = await Promise.all([
|
const [instance, instanceProjects, versions] = await Promise.all([
|
||||||
await get(instancePath).catch(handleError),
|
await get(instancePath).catch(handleError),
|
||||||
await get_projects(instancePath).catch(handleError),
|
await get_projects(instancePath).catch(handleError),
|
||||||
await get_version_many(project.versions),
|
await get_version_many(project.versions, 'must_revalidate'),
|
||||||
])
|
])
|
||||||
|
|
||||||
const projectVersions = versions.sort(
|
const projectVersions = versions.sort(
|
||||||
@ -165,11 +165,11 @@ export const installVersionDependencies = async (profile, version) => {
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
const depProject = await get_project(dep.project_id).catch(handleError)
|
const depProject = await get_project(dep.project_id, 'must_revalidate').catch(handleError)
|
||||||
|
|
||||||
const depVersions = (await get_version_many(depProject.versions).catch(handleError)).sort(
|
const depVersions = (
|
||||||
(a, b) => dayjs(b.date_published) - dayjs(a.date_published),
|
await get_version_many(depProject.versions, 'must_revalidate').catch(handleError)
|
||||||
)
|
).sort((a, b) => dayjs(b.date_published) - dayjs(a.date_published))
|
||||||
|
|
||||||
const latest = depVersions.find(
|
const latest = depVersions.find(
|
||||||
(v) => v.game_versions.includes(profile.game_version) && v.loaders.includes(profile.loader),
|
(v) => v.game_versions.includes(profile.game_version) && v.loaders.includes(profile.loader),
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
export const useLoading = defineStore('loadingStore', {
|
export const useLoading = defineStore('loadingStore', {
|
||||||
state: () => ({ loading: false }),
|
state: () => ({
|
||||||
|
loading: false,
|
||||||
|
barEnabled: false,
|
||||||
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
|
setEnabled(enabled) {
|
||||||
|
this.barEnabled = enabled
|
||||||
|
},
|
||||||
startLoading() {
|
startLoading() {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
},
|
},
|
||||||
|
|||||||
@ -89,7 +89,7 @@ async fn main() -> theseus::Result<()> {
|
|||||||
.await?;
|
.await?;
|
||||||
install_zipped_mrpack(pack, profile_path.to_string()).await?;
|
install_zipped_mrpack(pack, profile_path.to_string()).await?;
|
||||||
|
|
||||||
let projects = profile::get_projects(&profile_path).await?;
|
let projects = profile::get_projects(&profile_path, None).await?;
|
||||||
|
|
||||||
for (path, file) in projects {
|
for (path, file) in projects {
|
||||||
println!(
|
println!(
|
||||||
@ -102,13 +102,13 @@ async fn main() -> theseus::Result<()> {
|
|||||||
// Run a profile, running minecraft and store the RwLock to the process
|
// Run a profile, running minecraft and store the RwLock to the process
|
||||||
let process = profile::run(&profile_path).await?;
|
let process = profile::run(&profile_path).await?;
|
||||||
|
|
||||||
println!("Minecraft PID: {}", process.pid);
|
println!("Minecraft UUID: {}", process.uuid);
|
||||||
|
|
||||||
println!("All running process UUID {:?}", process::get_all().await?);
|
println!("All running process UUID {:?}", process::get_all().await?);
|
||||||
|
|
||||||
// hold the lock to the process until it ends
|
// hold the lock to the process until it ends
|
||||||
println!("Waiting for process to end...");
|
println!("Waiting for process to end...");
|
||||||
process.wait_for().await?;
|
process::wait_for(process.uuid).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,8 @@ once_cell = "1"
|
|||||||
dashmap = "6.0.1"
|
dashmap = "6.0.1"
|
||||||
paste = "1.0.15"
|
paste = "1.0.15"
|
||||||
|
|
||||||
|
opener = { version = "0.7.2", features = ["reveal", "dbus-vendored"] }
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
||||||
window-shadows = "0.2.1"
|
window-shadows = "0.2.1"
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
<string>Owner</string>
|
<string>Owner</string>
|
||||||
<key>LSItemContentTypes</key>
|
<key>LSItemContentTypes</key>
|
||||||
<array>
|
<array>
|
||||||
<string>ModrinthApp-type</string>
|
<string>com.modrinth.theseus-type</string>
|
||||||
</array>
|
</array>
|
||||||
<key>NSDocumentClass</key>
|
<key>NSDocumentClass</key>
|
||||||
<string>NSDocument</string>
|
<string>NSDocument</string>
|
||||||
@ -45,7 +45,7 @@
|
|||||||
<key>UTTypeIcons</key>
|
<key>UTTypeIcons</key>
|
||||||
<dict/>
|
<dict/>
|
||||||
<key>UTTypeIdentifier</key>
|
<key>UTTypeIdentifier</key>
|
||||||
<string>ModrinthApp-type</string>
|
<string>com.modrinth.theseus-type</string>
|
||||||
<key>UTTypeTagSpecification</key>
|
<key>UTTypeTagSpecification</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>public.filename-extension</key>
|
<key>public.filename-extension</key>
|
||||||
|
|||||||
@ -6,19 +6,20 @@ macro_rules! impl_cache_methods {
|
|||||||
$(
|
$(
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn [<get_ $variant:snake>](id: &str) -> Result<Option<$type>>
|
pub async fn [<get_ $variant:snake>](id: &str, cache_behaviour: Option<CacheBehaviour>) -> Result<Option<$type>>
|
||||||
{
|
{
|
||||||
Ok(theseus::cache::[<get_ $variant:snake>](id).await?)
|
Ok(theseus::cache::[<get_ $variant:snake>](id, cache_behaviour).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn [<get_ $variant:snake _many>](
|
pub async fn [<get_ $variant:snake _many>](
|
||||||
ids: Vec<String>,
|
ids: Vec<String>,
|
||||||
|
cache_behaviour: Option<CacheBehaviour>,
|
||||||
) -> Result<Vec<$type>>
|
) -> Result<Vec<$type>>
|
||||||
{
|
{
|
||||||
let ids = ids.iter().map(|x| &**x).collect::<Vec<&str>>();
|
let ids = ids.iter().map(|x| &**x).collect::<Vec<&str>>();
|
||||||
let entries =
|
let entries =
|
||||||
theseus::cache::[<get_ $variant:snake _many>](&*ids).await?;
|
theseus::cache::[<get_ $variant:snake _many>](&*ids, cache_behaviour).await?;
|
||||||
|
|
||||||
Ok(entries)
|
Ok(entries)
|
||||||
}
|
}
|
||||||
@ -51,6 +52,12 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
|||||||
get_organization_many,
|
get_organization_many,
|
||||||
get_search_results,
|
get_search_results,
|
||||||
get_search_results_many,
|
get_search_results_many,
|
||||||
|
purge_cache_types,
|
||||||
])
|
])
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn purge_cache_types(cache_types: Vec<CacheValueType>) -> Result<()> {
|
||||||
|
Ok(theseus::cache::purge_cache_types(&cache_types).await?)
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use crate::api::Result;
|
use crate::api::Result;
|
||||||
use theseus::prelude::*;
|
use theseus::prelude::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
||||||
tauri::plugin::Builder::new("process")
|
tauri::plugin::Builder::new("process")
|
||||||
@ -13,21 +14,23 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn process_get_all() -> Result<Vec<Process>> {
|
pub async fn process_get_all() -> Result<Vec<ProcessMetadata>> {
|
||||||
Ok(process::get_all().await?)
|
Ok(process::get_all().await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn process_get_by_profile_path(path: &str) -> Result<Vec<Process>> {
|
pub async fn process_get_by_profile_path(
|
||||||
|
path: &str,
|
||||||
|
) -> Result<Vec<ProcessMetadata>> {
|
||||||
Ok(process::get_by_profile_path(path).await?)
|
Ok(process::get_by_profile_path(path).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn process_kill(pid: i32) -> Result<()> {
|
pub async fn process_kill(uuid: Uuid) -> Result<()> {
|
||||||
Ok(process::kill(pid).await?)
|
Ok(process::kill(uuid).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn process_wait_for(pid: i32) -> Result<()> {
|
pub async fn process_wait_for(uuid: Uuid) -> Result<()> {
|
||||||
Ok(process::wait_for(pid).await?)
|
Ok(process::wait_for(uuid).await?)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,8 +63,9 @@ pub async fn profile_get_many(paths: Vec<String>) -> Result<Vec<Profile>> {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn profile_get_projects(
|
pub async fn profile_get_projects(
|
||||||
path: &str,
|
path: &str,
|
||||||
|
cache_behaviour: Option<CacheBehaviour>,
|
||||||
) -> Result<DashMap<String, ProfileFile>> {
|
) -> Result<DashMap<String, ProfileFile>> {
|
||||||
let res = profile::get_projects(path).await?;
|
let res = profile::get_projects(path, cache_behaviour).await?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ pub async fn profile_check_installed(
|
|||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let check_project_id = project_id;
|
let check_project_id = project_id;
|
||||||
|
|
||||||
if let Ok(projects) = profile::get_projects(path).await {
|
if let Ok(projects) = profile::get_projects(path, None).await {
|
||||||
Ok(projects.into_iter().any(|(_, project)| {
|
Ok(projects.into_iter().any(|(_, project)| {
|
||||||
if let Some(metadata) = &project.metadata {
|
if let Some(metadata) = &project.metadata {
|
||||||
check_project_id == metadata.project_id
|
check_project_id == metadata.project_id
|
||||||
@ -248,7 +249,7 @@ pub async fn profile_get_pack_export_candidates(
|
|||||||
// for the actual Child in the state.
|
// for the actual Child in the state.
|
||||||
// invoke('plugin:profile|profile_run', path)
|
// invoke('plugin:profile|profile_run', path)
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn profile_run(path: &str) -> Result<Process> {
|
pub async fn profile_run(path: &str) -> Result<ProcessMetadata> {
|
||||||
let process = profile::run(path).await?;
|
let process = profile::run(path).await?;
|
||||||
|
|
||||||
Ok(process)
|
Ok(process)
|
||||||
@ -262,7 +263,7 @@ pub async fn profile_run(path: &str) -> Result<Process> {
|
|||||||
pub async fn profile_run_credentials(
|
pub async fn profile_run_credentials(
|
||||||
path: &str,
|
path: &str,
|
||||||
credentials: Credentials,
|
credentials: Credentials,
|
||||||
) -> Result<Process> {
|
) -> Result<ProcessMetadata> {
|
||||||
let process = profile::run_credentials(path, &credentials).await?;
|
let process = profile::run_credentials(path, &credentials).await?;
|
||||||
|
|
||||||
Ok(process)
|
Ok(process)
|
||||||
|
|||||||
@ -3,7 +3,11 @@ use theseus::prelude::*;
|
|||||||
|
|
||||||
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
||||||
tauri::plugin::Builder::new("settings")
|
tauri::plugin::Builder::new("settings")
|
||||||
.invoke_handler(tauri::generate_handler![settings_get, settings_set])
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
settings_get,
|
||||||
|
settings_set,
|
||||||
|
cancel_directory_change
|
||||||
|
])
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,3 +26,9 @@ pub async fn settings_set(settings: Settings) -> Result<()> {
|
|||||||
settings::set(settings).await?;
|
settings::set(settings).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn cancel_directory_change() -> Result<()> {
|
||||||
|
settings::cancel_directory_change().await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@ -5,7 +5,8 @@ use theseus::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::api::Result;
|
use crate::api::Result;
|
||||||
use std::{env, path::PathBuf, process::Command};
|
use dashmap::DashMap;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
||||||
tauri::plugin::Builder::new("utils")
|
tauri::plugin::Builder::new("utils")
|
||||||
@ -44,7 +45,7 @@ pub enum OS {
|
|||||||
// Values provided should not be used directly, as they are not guaranteed to be up-to-date
|
// Values provided should not be used directly, as they are not guaranteed to be up-to-date
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn progress_bars_list(
|
pub async fn progress_bars_list(
|
||||||
) -> Result<std::collections::HashMap<uuid::Uuid, theseus::LoadingBar>> {
|
) -> Result<DashMap<uuid::Uuid, theseus::LoadingBar>> {
|
||||||
let res = theseus::EventState::list_progress_bars().await?;
|
let res = theseus::EventState::list_progress_bars().await?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
@ -71,72 +72,20 @@ pub async fn should_disable_mouseover() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn show_in_folder(path: PathBuf) -> Result<()> {
|
pub fn show_in_folder(path: PathBuf) {
|
||||||
{
|
let res = opener::reveal(path);
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
if path.is_dir() {
|
|
||||||
Command::new("explorer")
|
|
||||||
.args([&path]) // The comma after select is not a typo
|
|
||||||
.spawn()?;
|
|
||||||
} else {
|
|
||||||
Command::new("explorer")
|
|
||||||
.args(["/select,", &path.to_string_lossy()]) // The comma after select is not a typo
|
|
||||||
.spawn()?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
if let Err(e) = res {
|
||||||
{
|
tracing::error!("Failed to open folder: {}", e);
|
||||||
use std::fs::metadata;
|
|
||||||
|
|
||||||
let mut path = path;
|
|
||||||
let path_string = path.to_string_lossy().to_string();
|
|
||||||
|
|
||||||
if metadata(&path)?.is_dir() {
|
|
||||||
Command::new("xdg-open").arg(&path).spawn()?;
|
|
||||||
} else if path_string.contains(',') {
|
|
||||||
// see https://gitlab.freedesktop.org/dbus/dbus/-/issues/76
|
|
||||||
path.pop();
|
|
||||||
Command::new("xdg-open").arg(&path).spawn()?;
|
|
||||||
} else {
|
|
||||||
Command::new("dbus-send")
|
|
||||||
.args([
|
|
||||||
"--session",
|
|
||||||
"--dest=org.freedesktop.FileManager1",
|
|
||||||
"--type=method_call",
|
|
||||||
"/org/freedesktop/FileManager1",
|
|
||||||
"org.freedesktop.FileManager1.ShowItems",
|
|
||||||
format!("array:string:file://{}", path_string).as_str(),
|
|
||||||
"string:\"\"",
|
|
||||||
])
|
|
||||||
.spawn()?;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
{
|
|
||||||
if path.is_dir() {
|
|
||||||
Command::new("open").args([&path]).spawn()?;
|
|
||||||
} else {
|
|
||||||
Command::new("open")
|
|
||||||
.args(["-R", &path.as_os_str().to_string_lossy()])
|
|
||||||
.spawn()?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok::<(), theseus::Error>(())
|
|
||||||
}?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn show_launcher_logs_folder() -> Result<()> {
|
pub fn show_launcher_logs_folder() {
|
||||||
let path = DirectoryInfo::launcher_logs_dir().unwrap_or_default();
|
let path = DirectoryInfo::launcher_logs_dir().unwrap_or_default();
|
||||||
// failure to get folder just opens filesystem
|
// failure to get folder just opens filesystem
|
||||||
// (ie: if in debug mode only and launcher_logs never created)
|
// (ie: if in debug mode only and launcher_logs never created)
|
||||||
show_in_folder(path)
|
show_in_folder(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get opening command
|
// Get opening command
|
||||||
@ -144,9 +93,28 @@ pub fn show_launcher_logs_folder() -> Result<()> {
|
|||||||
// This should be called once and only when the app is done booting up and ready to receive a command
|
// This should be called once and only when the app is done booting up and ready to receive a command
|
||||||
// Returns a Command struct- see events.js
|
// Returns a Command struct- see events.js
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub async fn get_opening_command(
|
||||||
|
state: tauri::State<'_, crate::macos::deep_link::InitialPayload>,
|
||||||
|
) -> Result<Option<CommandPayload>> {
|
||||||
|
let payload = state.payload.lock().await;
|
||||||
|
|
||||||
|
return if let Some(payload) = payload.as_ref() {
|
||||||
|
tracing::info!("opening command {payload}");
|
||||||
|
|
||||||
|
Ok(Some(handler::parse_command(payload).await?))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
pub async fn get_opening_command() -> Result<Option<CommandPayload>> {
|
pub async fn get_opening_command() -> Result<Option<CommandPayload>> {
|
||||||
// Tauri is not CLI, we use arguments as path to file to call
|
// Tauri is not CLI, we use arguments as path to file to call
|
||||||
let cmd_arg = env::args_os().nth(1);
|
let cmd_arg = std::env::args_os().nth(1);
|
||||||
|
|
||||||
|
tracing::info!("opening command {cmd_arg:?}");
|
||||||
|
|
||||||
let cmd_arg = cmd_arg.map(|path| path.to_string_lossy().to_string());
|
let cmd_arg = cmd_arg.map(|path| path.to_string_lossy().to_string());
|
||||||
if let Some(cmd) = cmd_arg {
|
if let Some(cmd) = cmd_arg {
|
||||||
|
|||||||
6
apps/app/src/macos/deep_link.rs
Normal file
6
apps/app/src/macos/deep_link.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
|
pub struct InitialPayload {
|
||||||
|
pub payload: Arc<Mutex<Option<String>>>,
|
||||||
|
}
|
||||||
@ -1,2 +1,3 @@
|
|||||||
|
pub mod deep_link;
|
||||||
pub mod delegate;
|
pub mod delegate;
|
||||||
pub mod window_ext;
|
pub mod window_ext;
|
||||||
|
|||||||
@ -16,12 +16,25 @@ mod macos;
|
|||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
|
async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
|
||||||
theseus::EventState::init(app).await?;
|
theseus::EventState::init(app.clone()).await?;
|
||||||
State::init().await?;
|
State::init().await?;
|
||||||
|
|
||||||
|
let state = State::get().await?;
|
||||||
|
app.asset_protocol_scope()
|
||||||
|
.allow_directory(state.directories.caches_dir(), true)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should be call once Vue has mounted the app
|
||||||
|
#[tracing::instrument(skip_all)]
|
||||||
|
#[tauri::command]
|
||||||
|
fn show_window(app: tauri::AppHandle) {
|
||||||
|
let win = app.get_window("main").unwrap();
|
||||||
|
win.show().unwrap();
|
||||||
|
win.set_focus().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn is_dev() -> bool {
|
fn is_dev() -> bool {
|
||||||
cfg!(debug_assertions)
|
cfg!(debug_assertions)
|
||||||
@ -76,41 +89,84 @@ fn main() {
|
|||||||
}))
|
}))
|
||||||
.plugin(tauri_plugin_window_state::Builder::default().build())
|
.plugin(tauri_plugin_window_state::Builder::default().build())
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
// Register deep link handler, allowing reading of modrinth:// links
|
#[cfg(target_os = "macos")]
|
||||||
if let Err(e) = tauri_plugin_deep_link::register(
|
let res = {
|
||||||
|
use macos::deep_link::InitialPayload;
|
||||||
|
let mtx = std::sync::Arc::new(tokio::sync::Mutex::new(None));
|
||||||
|
|
||||||
|
app.manage(InitialPayload {
|
||||||
|
payload: mtx.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
let mtx_copy = mtx.clone();
|
||||||
|
macos::delegate::register_open_file(move |filename| {
|
||||||
|
let mtx_copy = mtx_copy.clone();
|
||||||
|
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
tracing::info!("Handling file open {filename}");
|
||||||
|
|
||||||
|
let mut payload = mtx_copy.lock().await;
|
||||||
|
if payload.is_none() {
|
||||||
|
*payload = Some(filename.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = api::utils::handle_command(filename).await;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mtx_copy = mtx.clone();
|
||||||
|
tauri_plugin_deep_link::register(
|
||||||
|
"modrinth",
|
||||||
|
move |request: String| {
|
||||||
|
let mtx_copy = mtx_copy.clone();
|
||||||
|
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
tracing::info!("Handling deep link {request}");
|
||||||
|
|
||||||
|
let mut payload = mtx_copy.lock().await;
|
||||||
|
if payload.is_none() {
|
||||||
|
*payload = Some(request.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = api::utils::handle_command(request).await;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
let res = tauri_plugin_deep_link::register(
|
||||||
"modrinth",
|
"modrinth",
|
||||||
|request: String| {
|
|request: String| {
|
||||||
|
tracing::info!("Handling deep link {request}");
|
||||||
tauri::async_runtime::spawn(api::utils::handle_command(
|
tauri::async_runtime::spawn(api::utils::handle_command(
|
||||||
request,
|
request,
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
) {
|
);
|
||||||
// Allow it to fail- see https://github.com/FabianLars/tauri-plugin-deep-link/issues/19
|
|
||||||
|
if let Err(e) = res {
|
||||||
tracing::error!("Error registering deep link handler: {}", e);
|
tracing::error!("Error registering deep link handler: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
let win = app.get_window("main").unwrap();
|
if let Some(window) = app.get_window("main") {
|
||||||
|
// Hide window to prevent white flash on startup
|
||||||
|
window.hide().unwrap();
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
{
|
{
|
||||||
use window_shadows::set_shadow;
|
use window_shadows::set_shadow;
|
||||||
set_shadow(&win, true).unwrap();
|
set_shadow(&window, true).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
use macos::window_ext::WindowExt;
|
use macos::window_ext::WindowExt;
|
||||||
win.set_transparent_titlebar(true);
|
window.set_transparent_titlebar(true);
|
||||||
win.position_traffic_lights(9.0, 16.0);
|
window.position_traffic_lights(9.0, 16.0);
|
||||||
|
}
|
||||||
macos::delegate::register_open_file(|filename| {
|
|
||||||
tauri::async_runtime::spawn(api::utils::handle_command(
|
|
||||||
filename,
|
|
||||||
));
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show app now that we are setup
|
|
||||||
win.show().unwrap();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
@ -148,6 +204,7 @@ fn main() {
|
|||||||
toggle_decorations,
|
toggle_decorations,
|
||||||
api::auth::auth_login,
|
api::auth::auth_login,
|
||||||
api::mr_auth::modrinth_auth_login,
|
api::mr_auth::modrinth_auth_login,
|
||||||
|
show_window,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
builder
|
builder
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "Modrinth App",
|
"productName": "Modrinth App",
|
||||||
"version": "0.8.0-1"
|
"version": "0.8.0"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
@ -18,11 +18,7 @@
|
|||||||
},
|
},
|
||||||
"protocol": {
|
"protocol": {
|
||||||
"asset": true,
|
"asset": true,
|
||||||
"assetScope": [
|
"assetScope": []
|
||||||
"$APPDATA/caches/icons/*",
|
|
||||||
"$APPDATA/caches/icons/*",
|
|
||||||
"$APPDATA/caches/icons/*"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"shell": {
|
"shell": {
|
||||||
"open": true
|
"open": true
|
||||||
|
|||||||
12
packages/app-lib/.sqlx/query-31938d27442f1f628fdcb81d16678c4e5c108c62462f16e8f3a84f4efabd529c.json
generated
Normal file
12
packages/app-lib/.sqlx/query-31938d27442f1f628fdcb81d16678c4e5c108c62462f16e8f3a84f4efabd529c.json
generated
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "\n DELETE FROM cache\n WHERE data_type IN (SELECT value FROM json_each($1))\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "31938d27442f1f628fdcb81d16678c4e5c108c62462f16e8f3a84f4efabd529c"
|
||||||
|
}
|
||||||
@ -17,7 +17,7 @@ sha2 = "0.10.8"
|
|||||||
url = "2.2"
|
url = "2.2"
|
||||||
uuid = { version = "1.1", features = ["serde", "v4"] }
|
uuid = { version = "1.1", features = ["serde", "v4"] }
|
||||||
zip = "0.6.5"
|
zip = "0.6.5"
|
||||||
async_zip = { version = "0.0.17", features = ["full"] }
|
async_zip = { version = "0.0.17", features = ["chrono", "tokio-fs", "deflate", "bzip2", "zstd", "deflate64"] }
|
||||||
flate2 = "1.0.28"
|
flate2 = "1.0.28"
|
||||||
tempfile = "3.5.0"
|
tempfile = "3.5.0"
|
||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
@ -35,7 +35,6 @@ thiserror = "1.0"
|
|||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["chrono", "env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["chrono", "env-filter"] }
|
||||||
tracing-error = "0.2.0"
|
tracing-error = "0.2.0"
|
||||||
tracing-appender = "0.2.3"
|
|
||||||
|
|
||||||
paste = { version = "1.0" }
|
paste = { version = "1.0" }
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
DROP INDEX modrinth_users_active;
|
||||||
|
DROP INDEX minecraft_users_active;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
use crate::state::{
|
use crate::state::{
|
||||||
CachedEntry, Organization, Project, SearchResults, TeamMember, User,
|
CacheBehaviour, CacheValueType, CachedEntry, Organization, Project,
|
||||||
Version,
|
SearchResults, TeamMember, User, Version,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! impl_cache_methods {
|
macro_rules! impl_cache_methods {
|
||||||
@ -10,15 +10,17 @@ macro_rules! impl_cache_methods {
|
|||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn [<get_ $variant:snake>](
|
pub async fn [<get_ $variant:snake>](
|
||||||
id: &str,
|
id: &str,
|
||||||
|
cache_behaviour: Option<CacheBehaviour>,
|
||||||
) -> crate::Result<Option<$type>>
|
) -> crate::Result<Option<$type>>
|
||||||
{
|
{
|
||||||
let state = crate::State::get().await?;
|
let state = crate::State::get().await?;
|
||||||
Ok(CachedEntry::[<get_ $variant:snake _many>](&[id], None, &state.pool, &state.api_semaphore).await?.into_iter().next())
|
Ok(CachedEntry::[<get_ $variant:snake _many>](&[id], cache_behaviour, &state.pool, &state.api_semaphore).await?.into_iter().next())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn [<get_ $variant:snake _many>](
|
pub async fn [<get_ $variant:snake _many>](
|
||||||
ids: &[&str],
|
ids: &[&str],
|
||||||
|
cache_behaviour: Option<CacheBehaviour>,
|
||||||
) -> crate::Result<Vec<$type>>
|
) -> crate::Result<Vec<$type>>
|
||||||
{
|
{
|
||||||
let state = crate::State::get().await?;
|
let state = crate::State::get().await?;
|
||||||
@ -40,3 +42,12 @@ impl_cache_methods!(
|
|||||||
(Organization, Organization),
|
(Organization, Organization),
|
||||||
(SearchResults, SearchResults)
|
(SearchResults, SearchResults)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
pub async fn purge_cache_types(
|
||||||
|
cache_types: &[CacheValueType],
|
||||||
|
) -> crate::Result<()> {
|
||||||
|
let state = crate::State::get().await?;
|
||||||
|
CachedEntry::purge_cache_types(cache_types, &state.pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ pub async fn get_minecraft_versions() -> crate::Result<VersionManifest> {
|
|||||||
Ok(minecraft_versions)
|
Ok(minecraft_versions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument]
|
// #[tracing::instrument]
|
||||||
pub async fn get_loader_versions(loader: &str) -> crate::Result<Manifest> {
|
pub async fn get_loader_versions(loader: &str) -> crate::Result<Manifest> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let loaders = CachedEntry::get_loader_manifest(
|
let loaders = CachedEntry::get_loader_manifest(
|
||||||
|
|||||||
@ -14,11 +14,11 @@ pub mod tags;
|
|||||||
|
|
||||||
pub mod data {
|
pub mod data {
|
||||||
pub use crate::state::{
|
pub use crate::state::{
|
||||||
Credentials, Dependency, DirectoryInfo, Hooks, JavaVersion, LinkedData,
|
CacheBehaviour, CacheValueType, Credentials, Dependency, DirectoryInfo,
|
||||||
MemorySettings, ModLoader, ModrinthCredentials,
|
Hooks, JavaVersion, LinkedData, MemorySettings, ModLoader,
|
||||||
ModrinthCredentialsResult, Organization, Process, ProfileFile, Project,
|
ModrinthCredentials, ModrinthCredentialsResult, Organization,
|
||||||
ProjectType, SearchResult, SearchResults, Settings, TeamMember, Theme,
|
ProcessMetadata, ProfileFile, Project, ProjectType, SearchResult,
|
||||||
User, Version, WindowSize,
|
SearchResults, Settings, TeamMember, Theme, User, Version, WindowSize,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -174,8 +174,7 @@ async fn load_instance_cfg(file_path: &Path) -> crate::Result<MMCInstance> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument]
|
// #[tracing::instrument]
|
||||||
|
|
||||||
pub async fn import_mmc(
|
pub async fn import_mmc(
|
||||||
mmc_base_path: PathBuf, // path to base mmc folder
|
mmc_base_path: PathBuf, // path to base mmc folder
|
||||||
instance_folder: String, // instance folder in mmc_base_path
|
instance_folder: String, // instance folder in mmc_base_path
|
||||||
|
|||||||
@ -104,7 +104,7 @@ pub async fn get_importable_instances(
|
|||||||
// Import an instance from a launcher type and base path
|
// Import an instance from a launcher type and base path
|
||||||
// Note: this *deletes* the submitted empty profile
|
// Note: this *deletes* the submitted empty profile
|
||||||
|
|
||||||
#[tracing::instrument]
|
// #[tracing::instrument]
|
||||||
pub async fn import_instance(
|
pub async fn import_instance(
|
||||||
profile_path: &str, // This should be a blank profile
|
profile_path: &str, // This should be a blank profile
|
||||||
launcher_type: ImportLauncherType,
|
launcher_type: ImportLauncherType,
|
||||||
@ -257,7 +257,7 @@ pub async fn copy_dotminecraft(
|
|||||||
crate::api::profile::get_full_path(profile_path_id).await?;
|
crate::api::profile::get_full_path(profile_path_id).await?;
|
||||||
|
|
||||||
// Gets all subfiles recursively in src
|
// Gets all subfiles recursively in src
|
||||||
let subfiles = get_all_subfiles(&dotminecraft).await?;
|
let subfiles = get_all_subfiles(&dotminecraft, true).await?;
|
||||||
let total_subfiles = subfiles.len() as u64;
|
let total_subfiles = subfiles.len() as u64;
|
||||||
|
|
||||||
let loading_bar = init_or_edit_loading(
|
let loading_bar = init_or_edit_loading(
|
||||||
@ -297,20 +297,33 @@ pub async fn copy_dotminecraft(
|
|||||||
|
|
||||||
#[async_recursion::async_recursion]
|
#[async_recursion::async_recursion]
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn get_all_subfiles(src: &Path) -> crate::Result<Vec<PathBuf>> {
|
pub async fn get_all_subfiles(
|
||||||
|
src: &Path,
|
||||||
|
include_empty_dirs: bool,
|
||||||
|
) -> crate::Result<Vec<PathBuf>> {
|
||||||
if !src.is_dir() {
|
if !src.is_dir() {
|
||||||
return Ok(vec![src.to_path_buf()]);
|
return Ok(vec![src.to_path_buf()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
let mut dir = io::read_dir(&src).await?;
|
let mut dir = io::read_dir(&src).await?;
|
||||||
|
|
||||||
|
let mut has_files = false;
|
||||||
while let Some(child) = dir
|
while let Some(child) = dir
|
||||||
.next_entry()
|
.next_entry()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| IOError::with_path(e, src))?
|
.map_err(|e| IOError::with_path(e, src))?
|
||||||
{
|
{
|
||||||
|
has_files = true;
|
||||||
let src_child = child.path();
|
let src_child = child.path();
|
||||||
files.append(&mut get_all_subfiles(&src_child).await?);
|
files.append(
|
||||||
|
&mut get_all_subfiles(&src_child, include_empty_dirs).await?,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !has_files && include_empty_dirs {
|
||||||
|
files.push(src.to_path_buf());
|
||||||
|
}
|
||||||
|
|
||||||
Ok(files)
|
Ok(files)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,11 +177,9 @@ pub async fn install_zipped_mrpack_files(
|
|||||||
|
|
||||||
let path =
|
let path =
|
||||||
std::path::Path::new(&project_path).components().next();
|
std::path::Path::new(&project_path).components().next();
|
||||||
if let Some(path) = path {
|
if let Some(Component::CurDir | Component::Normal(_)) = path
|
||||||
match path {
|
{
|
||||||
Component::CurDir | Component::Normal(_) => {
|
let path = profile::get_full_path(&profile_path)
|
||||||
let path =
|
|
||||||
profile::get_full_path(&profile_path)
|
|
||||||
.await?
|
.await?
|
||||||
.join(&project_path);
|
.join(&project_path);
|
||||||
|
|
||||||
@ -197,11 +195,7 @@ pub async fn install_zipped_mrpack_files(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
write(&path, &file, &state.io_semaphore)
|
write(&path, &file, &state.io_semaphore).await?;
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
//! Theseus process management interface
|
//! Theseus process management interface
|
||||||
|
|
||||||
use crate::state::Process;
|
use crate::state::ProcessMetadata;
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
state::{Hooks, MemorySettings, Profile, Settings, WindowSize},
|
state::{Hooks, MemorySettings, Profile, Settings, WindowSize},
|
||||||
State,
|
State,
|
||||||
};
|
};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
// Gets the Profile paths of each *running* stored process in the state
|
// Gets the Profile paths of each *running* stored process in the state
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn get_all() -> crate::Result<Vec<Process>> {
|
pub async fn get_all() -> crate::Result<Vec<ProcessMetadata>> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let processes = Process::get_all(&state.pool).await?;
|
let processes = state.process_manager.get_all();
|
||||||
Ok(processes)
|
Ok(processes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,39 +19,31 @@ pub async fn get_all() -> crate::Result<Vec<Process>> {
|
|||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn get_by_profile_path(
|
pub async fn get_by_profile_path(
|
||||||
profile_path: &str,
|
profile_path: &str,
|
||||||
) -> crate::Result<Vec<Process>> {
|
) -> crate::Result<Vec<ProcessMetadata>> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let processes =
|
let processes = state
|
||||||
Process::get_from_profile(profile_path, &state.pool).await?;
|
.process_manager
|
||||||
|
.get_all()
|
||||||
|
.into_iter()
|
||||||
|
.filter(|x| x.profile_path == profile_path)
|
||||||
|
.collect();
|
||||||
Ok(processes)
|
Ok(processes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill a child process stored in the state by UUID, as a string
|
// Kill a child process stored in the state by UUID, as a string
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn kill(pid: i32) -> crate::Result<()> {
|
pub async fn kill(uuid: Uuid) -> crate::Result<()> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let process = Process::get(pid, &state.pool).await?;
|
state.process_manager.kill(uuid).await?;
|
||||||
|
|
||||||
if let Some(process) = process {
|
|
||||||
process.kill().await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for a child process stored in the state by UUID
|
// Wait for a child process stored in the state by UUID
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn wait_for(pid: i32) -> crate::Result<()> {
|
pub async fn wait_for(uuid: Uuid) -> crate::Result<()> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let process = Process::get(pid, &state.pool).await?;
|
state.process_manager.wait_for(uuid).await?;
|
||||||
|
|
||||||
if let Some(process) = process {
|
|
||||||
process.wait_for().await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use crate::pack::install_from::{
|
|||||||
EnvType, PackDependency, PackFile, PackFileHash, PackFormat,
|
EnvType, PackDependency, PackFile, PackFileHash, PackFormat,
|
||||||
};
|
};
|
||||||
use crate::state::{
|
use crate::state::{
|
||||||
CacheBehaviour, CachedEntry, Credentials, JavaVersion, Process,
|
CacheBehaviour, CachedEntry, Credentials, JavaVersion, ProcessMetadata,
|
||||||
ProfileFile, ProjectType, SideType,
|
ProfileFile, ProjectType, SideType,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,12 +71,13 @@ pub async fn get_many(paths: &[&str]) -> crate::Result<Vec<Profile>> {
|
|||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn get_projects(
|
pub async fn get_projects(
|
||||||
path: &str,
|
path: &str,
|
||||||
|
cache_behaviour: Option<CacheBehaviour>,
|
||||||
) -> crate::Result<DashMap<String, ProfileFile>> {
|
) -> crate::Result<DashMap<String, ProfileFile>> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
|
|
||||||
if let Some(profile) = get(path).await? {
|
if let Some(profile) = get(path).await? {
|
||||||
let files = profile
|
let files = profile
|
||||||
.get_projects(None, &state.pool, &state.api_semaphore)
|
.get_projects(cache_behaviour, &state.pool, &state.api_semaphore)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(files)
|
Ok(files)
|
||||||
@ -614,10 +615,10 @@ fn pack_get_relative_path(
|
|||||||
/// Run Minecraft using a profile and the default credentials, logged in credentials,
|
/// Run Minecraft using a profile and the default credentials, logged in credentials,
|
||||||
/// failing with an error if no credentials are available
|
/// failing with an error if no credentials are available
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn run(path: &str) -> crate::Result<Process> {
|
pub async fn run(path: &str) -> crate::Result<ProcessMetadata> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
|
|
||||||
let default_account = Credentials::get_active(&state.pool)
|
let default_account = Credentials::get_default_credential(&state.pool)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| crate::ErrorKind::NoCredentialsError.as_error())?;
|
.ok_or_else(|| crate::ErrorKind::NoCredentialsError.as_error())?;
|
||||||
|
|
||||||
@ -631,7 +632,7 @@ pub async fn run(path: &str) -> crate::Result<Process> {
|
|||||||
pub async fn run_credentials(
|
pub async fn run_credentials(
|
||||||
path: &str,
|
path: &str,
|
||||||
credentials: &Credentials,
|
credentials: &Credentials,
|
||||||
) -> crate::Result<Process> {
|
) -> crate::Result<ProcessMetadata> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let settings = Settings::get(&state.pool).await?;
|
let settings = Settings::get(&state.pool).await?;
|
||||||
let profile = get(path).await?.ok_or_else(|| {
|
let profile = get(path).await?.ok_or_else(|| {
|
||||||
@ -652,7 +653,7 @@ pub async fn run_credentials(
|
|||||||
if let Some(command) = cmd.next() {
|
if let Some(command) = cmd.next() {
|
||||||
let full_path = get_full_path(&profile.path).await?;
|
let full_path = get_full_path(&profile.path).await?;
|
||||||
let result = Command::new(command)
|
let result = Command::new(command)
|
||||||
.args(&cmd.collect::<Vec<&str>>())
|
.args(cmd.collect::<Vec<&str>>())
|
||||||
.current_dir(&full_path)
|
.current_dir(&full_path)
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(|e| IOError::with_path(e, &full_path))?
|
.map_err(|e| IOError::with_path(e, &full_path))?
|
||||||
@ -715,10 +716,11 @@ pub async fn run_credentials(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn kill(path: &str) -> crate::Result<()> {
|
pub async fn kill(path: &str) -> crate::Result<()> {
|
||||||
|
let state = State::get().await?;
|
||||||
let processes = crate::api::process::get_by_profile_path(path).await?;
|
let processes = crate::api::process::get_by_profile_path(path).await?;
|
||||||
|
|
||||||
for process in processes {
|
for process in processes {
|
||||||
process.kill().await?;
|
state.process_manager.kill(process.uuid).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -920,5 +922,8 @@ pub async fn add_all_recursive_folder_paths(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn sanitize_profile_name(input: &str) -> String {
|
pub fn sanitize_profile_name(input: &str) -> String {
|
||||||
input.replace(['/', '\\', '?', '*', ':', '\'', '\"', '|', '<', '>'], "_")
|
input.replace(
|
||||||
|
['/', '\\', '?', '*', ':', '\'', '\"', '|', '<', '>', '!'],
|
||||||
|
"_",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,3 +21,18 @@ pub async fn set(settings: Settings) -> crate::Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument]
|
||||||
|
pub async fn cancel_directory_change() -> crate::Result<()> {
|
||||||
|
let pool = crate::state::db::connect().await?;
|
||||||
|
let mut settings = Settings::get(&pool).await?;
|
||||||
|
|
||||||
|
if let Some(prev_custom_dir) = settings.prev_custom_dir {
|
||||||
|
settings.prev_custom_dir = None;
|
||||||
|
settings.custom_dir = Some(prev_custom_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.update(&pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@ -108,6 +108,9 @@ pub enum ErrorKind {
|
|||||||
|
|
||||||
#[error("Error while applying migrations: {0}")]
|
#[error("Error while applying migrations: {0}")]
|
||||||
SqlxMigrate(#[from] sqlx::migrate::MigrateError),
|
SqlxMigrate(#[from] sqlx::migrate::MigrateError),
|
||||||
|
|
||||||
|
#[error("Move directory error: {0}")]
|
||||||
|
DirectoryMoveError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@ -66,7 +66,7 @@ pub async fn init_loading_unsafe(
|
|||||||
let event_state = crate::EventState::get().await?;
|
let event_state = crate::EventState::get().await?;
|
||||||
let key = LoadingBarId(Uuid::new_v4());
|
let key = LoadingBarId(Uuid::new_v4());
|
||||||
|
|
||||||
event_state.loading_bars.write().await.insert(
|
event_state.loading_bars.insert(
|
||||||
key.0,
|
key.0,
|
||||||
LoadingBar {
|
LoadingBar {
|
||||||
loading_bar_uuid: key.0,
|
loading_bar_uuid: key.0,
|
||||||
@ -121,7 +121,7 @@ pub async fn edit_loading(
|
|||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let event_state = crate::EventState::get().await?;
|
let event_state = crate::EventState::get().await?;
|
||||||
|
|
||||||
if let Some(bar) = event_state.loading_bars.write().await.get_mut(&id.0) {
|
if let Some(mut bar) = event_state.loading_bars.get_mut(&id.0) {
|
||||||
bar.bar_type = bar_type;
|
bar.bar_type = bar_type;
|
||||||
bar.total = total;
|
bar.total = total;
|
||||||
bar.message = title.to_string();
|
bar.message = title.to_string();
|
||||||
@ -152,8 +152,7 @@ pub async fn emit_loading(
|
|||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let event_state = crate::EventState::get().await?;
|
let event_state = crate::EventState::get().await?;
|
||||||
|
|
||||||
let mut loading_bar = event_state.loading_bars.write().await;
|
let mut loading_bar = match event_state.loading_bars.get_mut(&key.0) {
|
||||||
let loading_bar = match loading_bar.get_mut(&key.0) {
|
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
None => {
|
None => {
|
||||||
return Err(EventError::NoLoadingBar(key.0).into());
|
return Err(EventError::NoLoadingBar(key.0).into());
|
||||||
@ -250,7 +249,7 @@ pub async fn emit_command(command: CommandPayload) -> crate::Result<()> {
|
|||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub async fn emit_process(
|
pub async fn emit_process(
|
||||||
profile_path: &str,
|
profile_path: &str,
|
||||||
pid: u32,
|
uuid: Uuid,
|
||||||
event: ProcessPayloadType,
|
event: ProcessPayloadType,
|
||||||
message: &str,
|
message: &str,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
@ -263,7 +262,7 @@ pub async fn emit_process(
|
|||||||
"process",
|
"process",
|
||||||
ProcessPayload {
|
ProcessPayload {
|
||||||
profile_path_id: profile_path.to_string(),
|
profile_path_id: profile_path.to_string(),
|
||||||
pid,
|
uuid,
|
||||||
event,
|
event,
|
||||||
message: message.to_string(),
|
message: message.to_string(),
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
//! Theseus state management system
|
//! Theseus state management system
|
||||||
|
use dashmap::DashMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
use tokio::sync::OnceCell;
|
use tokio::sync::OnceCell;
|
||||||
use tokio::sync::RwLock;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub mod emit;
|
pub mod emit;
|
||||||
@ -14,7 +14,7 @@ pub struct EventState {
|
|||||||
/// Tauri app
|
/// Tauri app
|
||||||
#[cfg(feature = "tauri")]
|
#[cfg(feature = "tauri")]
|
||||||
pub app: tauri::AppHandle,
|
pub app: tauri::AppHandle,
|
||||||
pub loading_bars: RwLock<HashMap<Uuid, LoadingBar>>,
|
pub loading_bars: DashMap<Uuid, LoadingBar>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventState {
|
impl EventState {
|
||||||
@ -24,7 +24,7 @@ impl EventState {
|
|||||||
.get_or_try_init(|| async {
|
.get_or_try_init(|| async {
|
||||||
Ok(Arc::new(Self {
|
Ok(Arc::new(Self {
|
||||||
app,
|
app,
|
||||||
loading_bars: RwLock::new(HashMap::new()),
|
loading_bars: DashMap::new(),
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
@ -36,7 +36,7 @@ impl EventState {
|
|||||||
EVENT_STATE
|
EVENT_STATE
|
||||||
.get_or_try_init(|| async {
|
.get_or_try_init(|| async {
|
||||||
Ok(Arc::new(Self {
|
Ok(Arc::new(Self {
|
||||||
loading_bars: RwLock::new(HashMap::new()),
|
loading_bars: DashMap::new(),
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
@ -55,17 +55,10 @@ impl EventState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Values provided should not be used directly, as they are clones and are not guaranteed to be up-to-date
|
// Values provided should not be used directly, as they are clones and are not guaranteed to be up-to-date
|
||||||
pub async fn list_progress_bars() -> crate::Result<HashMap<Uuid, LoadingBar>>
|
pub async fn list_progress_bars() -> crate::Result<DashMap<Uuid, LoadingBar>>
|
||||||
{
|
{
|
||||||
let value = Self::get().await?;
|
let value = Self::get().await?;
|
||||||
let read = value.loading_bars.read().await;
|
Ok(value.loading_bars.clone())
|
||||||
|
|
||||||
let mut display_list: HashMap<Uuid, LoadingBar> = HashMap::new();
|
|
||||||
for (uuid, loading_bar) in read.iter() {
|
|
||||||
display_list.insert(*uuid, loading_bar.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(display_list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tauri")]
|
#[cfg(feature = "tauri")]
|
||||||
@ -100,10 +93,10 @@ impl Drop for LoadingBarId {
|
|||||||
let loader_uuid = self.0;
|
let loader_uuid = self.0;
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Ok(event_state) = EventState::get().await {
|
if let Ok(event_state) = EventState::get().await {
|
||||||
let mut bars = event_state.loading_bars.write().await;
|
|
||||||
|
|
||||||
#[cfg(any(feature = "tauri", feature = "cli"))]
|
#[cfg(any(feature = "tauri", feature = "cli"))]
|
||||||
if let Some(bar) = bars.remove(&loader_uuid) {
|
if let Some((_, bar)) =
|
||||||
|
event_state.loading_bars.remove(&loader_uuid)
|
||||||
|
{
|
||||||
#[cfg(feature = "tauri")]
|
#[cfg(feature = "tauri")]
|
||||||
{
|
{
|
||||||
let loader_uuid = bar.loading_bar_uuid;
|
let loader_uuid = bar.loading_bar_uuid;
|
||||||
@ -135,7 +128,7 @@ impl Drop for LoadingBarId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "tauri", feature = "cli")))]
|
#[cfg(not(any(feature = "tauri", feature = "cli")))]
|
||||||
bars.remove(&loader_uuid);
|
event_state.loading_bars.remove(&loader_uuid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -145,7 +138,11 @@ impl Drop for LoadingBarId {
|
|||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum LoadingBarType {
|
pub enum LoadingBarType {
|
||||||
StateInit,
|
LegacyDataMigration,
|
||||||
|
DirectoryMove {
|
||||||
|
old: PathBuf,
|
||||||
|
new: PathBuf,
|
||||||
|
},
|
||||||
JavaDownload {
|
JavaDownload {
|
||||||
version: u32,
|
version: u32,
|
||||||
},
|
},
|
||||||
@ -222,7 +219,7 @@ pub enum CommandPayload {
|
|||||||
#[derive(Serialize, Clone)]
|
#[derive(Serialize, Clone)]
|
||||||
pub struct ProcessPayload {
|
pub struct ProcessPayload {
|
||||||
pub profile_path_id: String,
|
pub profile_path_id: String,
|
||||||
pub pid: u32,
|
pub uuid: Uuid,
|
||||||
pub event: ProcessPayloadType,
|
pub event: ProcessPayloadType,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,9 @@ use crate::data::ModLoader;
|
|||||||
use crate::event::emit::{emit_loading, init_or_edit_loading};
|
use crate::event::emit::{emit_loading, init_or_edit_loading};
|
||||||
use crate::event::{LoadingBarId, LoadingBarType};
|
use crate::event::{LoadingBarId, LoadingBarType};
|
||||||
use crate::launcher::io::IOError;
|
use crate::launcher::io::IOError;
|
||||||
use crate::state::{Credentials, JavaVersion, Process, ProfileInstallStage};
|
use crate::state::{
|
||||||
|
Credentials, JavaVersion, ProcessMetadata, ProfileInstallStage,
|
||||||
|
};
|
||||||
use crate::util::io;
|
use crate::util::io;
|
||||||
use crate::{
|
use crate::{
|
||||||
process,
|
process,
|
||||||
@ -410,7 +412,7 @@ pub async fn launch_minecraft(
|
|||||||
credentials: &Credentials,
|
credentials: &Credentials,
|
||||||
post_exit_hook: Option<String>,
|
post_exit_hook: Option<String>,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
) -> crate::Result<Process> {
|
) -> crate::Result<ProcessMetadata> {
|
||||||
if profile.install_stage == ProfileInstallStage::PackInstalling
|
if profile.install_stage == ProfileInstallStage::PackInstalling
|
||||||
|| profile.install_stage == ProfileInstallStage::Installing
|
|| profile.install_stage == ProfileInstallStage::Installing
|
||||||
{
|
{
|
||||||
@ -508,16 +510,22 @@ pub async fn launch_minecraft(
|
|||||||
if let Some(process) = existing_processes.first() {
|
if let Some(process) = existing_processes.first() {
|
||||||
return Err(crate::ErrorKind::LauncherError(format!(
|
return Err(crate::ErrorKind::LauncherError(format!(
|
||||||
"Profile {} is already running at path: {}",
|
"Profile {} is already running at path: {}",
|
||||||
profile.path, process.pid
|
profile.path, process.uuid
|
||||||
))
|
))
|
||||||
.as_error());
|
.as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let natives_dir = state.directories.version_natives_dir(&version_jar);
|
||||||
|
if !natives_dir.exists() {
|
||||||
|
io::create_dir_all(&natives_dir).await?;
|
||||||
|
}
|
||||||
|
|
||||||
command
|
command
|
||||||
.args(
|
.args(
|
||||||
args::get_jvm_arguments(
|
args::get_jvm_arguments(
|
||||||
args.get(&d::minecraft::ArgumentType::Jvm)
|
args.get(&d::minecraft::ArgumentType::Jvm)
|
||||||
.map(|x| x.as_slice()),
|
.map(|x| x.as_slice()),
|
||||||
&state.directories.version_natives_dir(&version_jar),
|
&natives_dir,
|
||||||
&state.directories.libraries_dir(),
|
&state.directories.libraries_dir(),
|
||||||
&args::get_class_paths(
|
&args::get_class_paths(
|
||||||
&state.directories.libraries_dir(),
|
&state.directories.libraries_dir(),
|
||||||
@ -646,11 +654,8 @@ pub async fn launch_minecraft(
|
|||||||
|
|
||||||
// Create Minecraft child by inserting it into the state
|
// Create Minecraft child by inserting it into the state
|
||||||
// This also spawns the process and prepares the subsequent processes
|
// This also spawns the process and prepares the subsequent processes
|
||||||
Process::insert_new_process(
|
state
|
||||||
&profile.path,
|
.process_manager
|
||||||
command,
|
.insert_new_process(&profile.path, command, post_exit_hook)
|
||||||
post_exit_hook,
|
|
||||||
&state.pool,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,12 +15,10 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use tracing_appender::non_blocking::WorkerGuard;
|
|
||||||
|
|
||||||
// Handling for the live development logging
|
// Handling for the live development logging
|
||||||
// This will log to the console, and will not log to a file
|
// This will log to the console, and will not log to a file
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
pub fn start_logger() -> Option<WorkerGuard> {
|
pub fn start_logger() -> Option<()> {
|
||||||
use tracing_subscriber::prelude::*;
|
use tracing_subscriber::prelude::*;
|
||||||
|
|
||||||
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
||||||
@ -33,15 +31,16 @@ pub fn start_logger() -> Option<WorkerGuard> {
|
|||||||
.with(tracing_error::ErrorLayer::default());
|
.with(tracing_error::ErrorLayer::default());
|
||||||
tracing::subscriber::set_global_default(subscriber)
|
tracing::subscriber::set_global_default(subscriber)
|
||||||
.expect("setting default subscriber failed");
|
.expect("setting default subscriber failed");
|
||||||
None
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handling for the live production logging
|
// Handling for the live production logging
|
||||||
// This will log to a file in the logs directory, and will not show any logs in the console
|
// This will log to a file in the logs directory, and will not show any logs in the console
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
pub fn start_logger() -> Option<WorkerGuard> {
|
pub fn start_logger() -> Option<()> {
|
||||||
use crate::prelude::DirectoryInfo;
|
use crate::prelude::DirectoryInfo;
|
||||||
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
use chrono::Local;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
use tracing_subscriber::fmt::time::ChronoLocal;
|
use tracing_subscriber::fmt::time::ChronoLocal;
|
||||||
use tracing_subscriber::prelude::*;
|
use tracing_subscriber::prelude::*;
|
||||||
|
|
||||||
@ -53,17 +52,34 @@ pub fn start_logger() -> Option<WorkerGuard> {
|
|||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let log_file_name =
|
||||||
|
format!("session_{}.log", Local::now().format("%Y%m%d_%H%M%S"));
|
||||||
|
let log_file_path = logs_dir.join(log_file_name);
|
||||||
|
|
||||||
|
if let Err(err) = std::fs::create_dir_all(&logs_dir) {
|
||||||
|
eprintln!("Could not create logs directory: {err}");
|
||||||
|
}
|
||||||
|
|
||||||
|
let file = match OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.write(true)
|
||||||
|
.append(true)
|
||||||
|
.open(&log_file_path)
|
||||||
|
{
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Could not start open log file: {e}");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
||||||
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("theseus=info"));
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("theseus=info"));
|
||||||
|
|
||||||
let file_appender =
|
|
||||||
RollingFileAppender::new(Rotation::DAILY, logs_dir, "theseus.log");
|
|
||||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
|
||||||
|
|
||||||
let subscriber = tracing_subscriber::registry()
|
let subscriber = tracing_subscriber::registry()
|
||||||
.with(
|
.with(
|
||||||
tracing_subscriber::fmt::layer()
|
tracing_subscriber::fmt::layer()
|
||||||
.with_writer(non_blocking)
|
.with_writer(file)
|
||||||
.with_ansi(false) // disable ANSI escape codes
|
.with_ansi(false) // disable ANSI escape codes
|
||||||
.with_timer(ChronoLocal::rfc_3339()),
|
.with_timer(ChronoLocal::rfc_3339()),
|
||||||
)
|
)
|
||||||
@ -73,5 +89,5 @@ pub fn start_logger() -> Option<WorkerGuard> {
|
|||||||
tracing::subscriber::set_global_default(subscriber)
|
tracing::subscriber::set_global_default(subscriber)
|
||||||
.expect("Setting default subscriber failed");
|
.expect("Setting default subscriber failed");
|
||||||
|
|
||||||
Some(guard)
|
Some(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ use crate::util::fetch::{fetch_json, sha1_async, FetchSemaphore};
|
|||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use dashmap::DashSet;
|
use dashmap::DashSet;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -56,7 +57,7 @@ impl CacheValueType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_str(val: &str) -> CacheValueType {
|
pub fn from_string(val: &str) -> CacheValueType {
|
||||||
match val {
|
match val {
|
||||||
"project" => CacheValueType::Project,
|
"project" => CacheValueType::Project,
|
||||||
"version" => CacheValueType::Version,
|
"version" => CacheValueType::Version,
|
||||||
@ -412,7 +413,7 @@ pub struct GameVersion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CacheValue {
|
impl CacheValue {
|
||||||
fn get_entry(self) -> CachedEntry {
|
pub fn get_entry(self) -> CachedEntry {
|
||||||
CachedEntry {
|
CachedEntry {
|
||||||
id: self.get_key(),
|
id: self.get_key(),
|
||||||
alias: self.get_alias(),
|
alias: self.get_alias(),
|
||||||
@ -422,7 +423,7 @@ impl CacheValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_type(&self) -> CacheValueType {
|
pub fn get_type(&self) -> CacheValueType {
|
||||||
match self {
|
match self {
|
||||||
CacheValue::Project(_) => CacheValueType::Project,
|
CacheValue::Project(_) => CacheValueType::Project,
|
||||||
CacheValue::Version(_) => CacheValueType::Version,
|
CacheValue::Version(_) => CacheValueType::Version,
|
||||||
@ -505,7 +506,8 @@ impl CacheValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Copy, Clone)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum CacheBehaviour {
|
pub enum CacheBehaviour {
|
||||||
/// Serve expired data. If fetch fails / launcher is offline, errors are ignored
|
/// Serve expired data. If fetch fails / launcher is offline, errors are ignored
|
||||||
/// and expired data is served
|
/// and expired data is served
|
||||||
@ -529,9 +531,9 @@ pub struct CachedEntry {
|
|||||||
id: String,
|
id: String,
|
||||||
alias: Option<String>,
|
alias: Option<String>,
|
||||||
#[serde(rename = "data_type")]
|
#[serde(rename = "data_type")]
|
||||||
type_: CacheValueType,
|
pub type_: CacheValueType,
|
||||||
data: Option<CacheValue>,
|
data: Option<CacheValue>,
|
||||||
expires: i64,
|
pub expires: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_cache_methods {
|
macro_rules! impl_cache_methods {
|
||||||
@ -654,11 +656,6 @@ impl CachedEntry {
|
|||||||
pool: &SqlitePool,
|
pool: &SqlitePool,
|
||||||
fetch_semaphore: &FetchSemaphore,
|
fetch_semaphore: &FetchSemaphore,
|
||||||
) -> crate::Result<Vec<Self>> {
|
) -> crate::Result<Vec<Self>> {
|
||||||
use std::time::Instant;
|
|
||||||
let now = Instant::now();
|
|
||||||
|
|
||||||
println!("start {type_:?} keys: {keys:?}");
|
|
||||||
|
|
||||||
if keys.is_empty() {
|
if keys.is_empty() {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
@ -735,7 +732,7 @@ impl CachedEntry {
|
|||||||
return_vals.push(Self {
|
return_vals.push(Self {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
alias: row.alias,
|
alias: row.alias,
|
||||||
type_: CacheValueType::from_str(&row.data_type),
|
type_: CacheValueType::from_string(&row.data_type),
|
||||||
data: Some(data),
|
data: Some(data),
|
||||||
expires: row.expires,
|
expires: row.expires,
|
||||||
});
|
});
|
||||||
@ -743,13 +740,6 @@ impl CachedEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let time = now.elapsed();
|
|
||||||
println!(
|
|
||||||
"query {type_:?} keys: {remaining_keys:?}, elapsed: {:.2?}",
|
|
||||||
time
|
|
||||||
);
|
|
||||||
let now = Instant::now();
|
|
||||||
|
|
||||||
if !remaining_keys.is_empty() {
|
if !remaining_keys.is_empty() {
|
||||||
let res = Self::fetch_many(
|
let res = Self::fetch_many(
|
||||||
type_,
|
type_,
|
||||||
@ -787,9 +777,6 @@ impl CachedEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let time = now.elapsed();
|
|
||||||
println!("FETCH {type_:?} DONE, elapsed: {:.2?}", time);
|
|
||||||
|
|
||||||
if !expired_keys.is_empty()
|
if !expired_keys.is_empty()
|
||||||
&& (cache_behaviour == CacheBehaviour::StaleWhileRevalidate
|
&& (cache_behaviour == CacheBehaviour::StaleWhileRevalidate
|
||||||
|| cache_behaviour
|
|| cache_behaviour
|
||||||
@ -827,20 +814,50 @@ impl CachedEntry {
|
|||||||
fetch_semaphore: &FetchSemaphore,
|
fetch_semaphore: &FetchSemaphore,
|
||||||
pool: &SqlitePool,
|
pool: &SqlitePool,
|
||||||
) -> crate::Result<Vec<(Self, bool)>> {
|
) -> crate::Result<Vec<(Self, bool)>> {
|
||||||
|
async fn fetch_many_batched<T: DeserializeOwned>(
|
||||||
|
method: Method,
|
||||||
|
api_url: &str,
|
||||||
|
url: &str,
|
||||||
|
keys: &DashSet<impl Display + Eq + Hash + Serialize>,
|
||||||
|
fetch_semaphore: &FetchSemaphore,
|
||||||
|
pool: &SqlitePool,
|
||||||
|
) -> crate::Result<Vec<T>> {
|
||||||
|
const MAX_REQUEST_SIZE: usize = 1000;
|
||||||
|
|
||||||
|
let urls = keys
|
||||||
|
.iter()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.chunks(MAX_REQUEST_SIZE)
|
||||||
|
.map(|chunk| {
|
||||||
|
serde_json::to_string(&chunk)
|
||||||
|
.map(|keys| format!("{api_url}{url}{keys}"))
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
let res = futures::future::try_join_all(urls.iter().map(|url| {
|
||||||
|
fetch_json::<Vec<_>>(
|
||||||
|
method.clone(),
|
||||||
|
url,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
fetch_semaphore,
|
||||||
|
pool,
|
||||||
|
)
|
||||||
|
}))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(res.into_iter().flatten().collect())
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! fetch_original_values {
|
macro_rules! fetch_original_values {
|
||||||
($type:ident, $api_url:expr, $url_suffix:expr, $cache_variant:path) => {{
|
($type:ident, $api_url:expr, $url_suffix:expr, $cache_variant:path) => {{
|
||||||
let mut results = fetch_json::<Vec<_>>(
|
let mut results = fetch_many_batched(
|
||||||
Method::GET,
|
Method::GET,
|
||||||
&*format!(
|
|
||||||
"{}{}?ids={}",
|
|
||||||
$api_url,
|
$api_url,
|
||||||
$url_suffix,
|
&format!("{}?ids=", $url_suffix),
|
||||||
serde_json::to_string(&keys)?
|
&keys,
|
||||||
),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&fetch_semaphore,
|
&fetch_semaphore,
|
||||||
pool,
|
&pool,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -938,14 +955,11 @@ impl CachedEntry {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
CacheValueType::Team => {
|
CacheValueType::Team => {
|
||||||
let mut teams = fetch_json::<Vec<Vec<TeamMember>>>(
|
let mut teams = fetch_many_batched::<Vec<TeamMember>>(
|
||||||
Method::GET,
|
Method::GET,
|
||||||
&format!(
|
MODRINTH_API_URL_V3,
|
||||||
"{MODRINTH_API_URL_V3}teams?ids={}",
|
"teams?ids=",
|
||||||
serde_json::to_string(&keys)?
|
&keys,
|
||||||
),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
fetch_semaphore,
|
fetch_semaphore,
|
||||||
pool,
|
pool,
|
||||||
)
|
)
|
||||||
@ -980,14 +994,11 @@ impl CachedEntry {
|
|||||||
values
|
values
|
||||||
}
|
}
|
||||||
CacheValueType::Organization => {
|
CacheValueType::Organization => {
|
||||||
let mut orgs = fetch_json::<Vec<Organization>>(
|
let mut orgs = fetch_many_batched::<Organization>(
|
||||||
Method::GET,
|
Method::GET,
|
||||||
&format!(
|
MODRINTH_API_URL_V3,
|
||||||
"{MODRINTH_API_URL_V3}organizations?ids={}",
|
"organizations?ids=",
|
||||||
serde_json::to_string(&keys)?
|
&keys,
|
||||||
),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
fetch_semaphore,
|
fetch_semaphore,
|
||||||
pool,
|
pool,
|
||||||
)
|
)
|
||||||
@ -1064,8 +1075,6 @@ impl CachedEntry {
|
|||||||
false,
|
false,
|
||||||
));
|
));
|
||||||
|
|
||||||
println!("found hash {hash} {version_id} {project_id}");
|
|
||||||
|
|
||||||
vals.push((
|
vals.push((
|
||||||
CacheValue::File(CachedFile {
|
CacheValue::File(CachedFile {
|
||||||
hash,
|
hash,
|
||||||
@ -1307,7 +1316,6 @@ impl CachedEntry {
|
|||||||
false,
|
false,
|
||||||
));
|
));
|
||||||
|
|
||||||
println!("found update {hash} {game_version} {loader} {version_id}");
|
|
||||||
vals.push((
|
vals.push((
|
||||||
CacheValue::FileUpdate(CachedFileUpdate {
|
CacheValue::FileUpdate(CachedFileUpdate {
|
||||||
hash: hash.clone(),
|
hash: hash.clone(),
|
||||||
@ -1372,7 +1380,7 @@ impl CachedEntry {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn upsert_many(
|
pub(crate) async fn upsert_many(
|
||||||
items: &[Self],
|
items: &[Self],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
@ -1402,6 +1410,25 @@ impl CachedEntry {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn purge_cache_types(
|
||||||
|
cache_types: &[CacheValueType],
|
||||||
|
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
||||||
|
) -> crate::Result<()> {
|
||||||
|
let cache_types = serde_json::to_string(&cache_types)?;
|
||||||
|
|
||||||
|
sqlx::query!(
|
||||||
|
"
|
||||||
|
DELETE FROM cache
|
||||||
|
WHERE data_type IN (SELECT value FROM json_each($1))
|
||||||
|
",
|
||||||
|
cache_types,
|
||||||
|
)
|
||||||
|
.execute(exec)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cache_file_hash(
|
pub async fn cache_file_hash(
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
//! Theseus directory information
|
//! Theseus directory information
|
||||||
use crate::state::{JavaVersion, Settings};
|
use crate::event::emit::{emit_loading, init_loading};
|
||||||
|
use crate::state::{JavaVersion, Profile, Settings};
|
||||||
use crate::util::fetch::IoSemaphore;
|
use crate::util::fetch::IoSemaphore;
|
||||||
|
use crate::LoadingBarType;
|
||||||
|
use dashmap::DashSet;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::Arc;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
pub const CACHES_FOLDER_NAME: &str = "caches";
|
pub const CACHES_FOLDER_NAME: &str = "caches";
|
||||||
@ -11,7 +15,7 @@ pub const METADATA_FOLDER_NAME: &str = "meta";
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DirectoryInfo {
|
pub struct DirectoryInfo {
|
||||||
pub settings_dir: PathBuf, // Base settings directory- settings.json and icon cache.
|
pub settings_dir: PathBuf, // Base settings directory- app database
|
||||||
pub config_dir: PathBuf, // Base config directory- instances, minecraft downloads, etc. Changeable as a setting.
|
pub config_dir: PathBuf, // Base config directory- instances, minecraft downloads, etc. Changeable as a setting.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +157,7 @@ impl DirectoryInfo {
|
|||||||
/// Get the cache directory for Theseus
|
/// Get the cache directory for Theseus
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn caches_dir(&self) -> PathBuf {
|
pub fn caches_dir(&self) -> PathBuf {
|
||||||
self.settings_dir.join(CACHES_FOLDER_NAME)
|
self.config_dir.join(CACHES_FOLDER_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get path from environment variable
|
/// Get path from environment variable
|
||||||
@ -162,6 +166,7 @@ impl DirectoryInfo {
|
|||||||
std::env::var_os(name).map(PathBuf::from)
|
std::env::var_os(name).map(PathBuf::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(settings, exec, io_semaphore))]
|
||||||
pub async fn move_launcher_directory<'a, E>(
|
pub async fn move_launcher_directory<'a, E>(
|
||||||
settings: &mut Settings,
|
settings: &mut Settings,
|
||||||
exec: E,
|
exec: E,
|
||||||
@ -170,14 +175,15 @@ impl DirectoryInfo {
|
|||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Sqlite> + Copy,
|
E: sqlx::Executor<'a, Database = sqlx::Sqlite> + Copy,
|
||||||
{
|
{
|
||||||
if let Some(ref prev_custom_dir) = settings.prev_custom_dir {
|
|
||||||
let prev_dir = PathBuf::from(prev_custom_dir);
|
|
||||||
let app_dir = DirectoryInfo::get_initial_settings_dir().ok_or(
|
let app_dir = DirectoryInfo::get_initial_settings_dir().ok_or(
|
||||||
crate::ErrorKind::FSError(
|
crate::ErrorKind::FSError(
|
||||||
"Could not find valid config dir".to_string(),
|
"Could not find valid config dir".to_string(),
|
||||||
),
|
),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
if let Some(ref prev_custom_dir) = settings.prev_custom_dir {
|
||||||
|
let prev_dir = PathBuf::from(prev_custom_dir);
|
||||||
|
|
||||||
let move_dir = settings
|
let move_dir = settings
|
||||||
.custom_dir
|
.custom_dir
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@ -203,10 +209,82 @@ impl DirectoryInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn move_directory(
|
fn is_same_disk(
|
||||||
|
old_dir: &Path,
|
||||||
|
new_dir: &Path,
|
||||||
|
) -> crate::Result<bool> {
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
Ok(old_dir.metadata()?.dev() == new_dir.metadata()?.dev())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
let old_dir = crate::util::io::canonicalize(old_dir)?;
|
||||||
|
let new_dir = crate::util::io::canonicalize(new_dir)?;
|
||||||
|
|
||||||
|
let old_component = old_dir.components().next();
|
||||||
|
let new_component = new_dir.components().next();
|
||||||
|
|
||||||
|
match (old_component, new_component) {
|
||||||
|
(
|
||||||
|
Some(std::path::Component::Prefix(old)),
|
||||||
|
Some(std::path::Component::Prefix(new)),
|
||||||
|
) => Ok(old.as_os_str() == new.as_os_str()),
|
||||||
|
_ => Ok(false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_disk_usage(path: &Path) -> crate::Result<Option<u64>> {
|
||||||
|
let path = crate::util::io::canonicalize(path)?;
|
||||||
|
|
||||||
|
let disks = sysinfo::Disks::new_with_refreshed_list();
|
||||||
|
|
||||||
|
for disk in disks.iter() {
|
||||||
|
if path.starts_with(disk.mount_point()) {
|
||||||
|
return Ok(Some(disk.available_space()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_dir = move_dir.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
if prev_dir != move_dir {
|
||||||
|
let loader_bar_id = init_loading(
|
||||||
|
LoadingBarType::DirectoryMove {
|
||||||
|
old: prev_dir.clone(),
|
||||||
|
new: move_dir.clone(),
|
||||||
|
},
|
||||||
|
100.0,
|
||||||
|
"Moving launcher directory",
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !is_dir_writeable(&move_dir).await? {
|
||||||
|
return Err(crate::ErrorKind::DirectoryMoveError(format!("Cannot move directory to {}: directory is not writeable", move_dir.display())).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
const MOVE_DIRS: &[&str] = &[
|
||||||
|
CACHES_FOLDER_NAME,
|
||||||
|
PROFILES_FOLDER_NAME,
|
||||||
|
METADATA_FOLDER_NAME,
|
||||||
|
];
|
||||||
|
|
||||||
|
struct MovePath {
|
||||||
|
old: PathBuf,
|
||||||
|
new: PathBuf,
|
||||||
|
size: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn add_paths(
|
||||||
source: &Path,
|
source: &Path,
|
||||||
destination: &Path,
|
destination: &Path,
|
||||||
io_semaphore: &IoSemaphore,
|
paths: &mut Vec<MovePath>,
|
||||||
|
total_size: &mut u64,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
if !source.exists() {
|
if !source.exists() {
|
||||||
crate::util::io::create_dir_all(source).await?;
|
crate::util::io::create_dir_all(source).await?;
|
||||||
@ -217,56 +295,181 @@ impl DirectoryInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for entry_path in
|
for entry_path in
|
||||||
crate::pack::import::get_all_subfiles(source).await?
|
crate::pack::import::get_all_subfiles(source, false)
|
||||||
|
.await?
|
||||||
{
|
{
|
||||||
let relative_path = entry_path.strip_prefix(source)?;
|
let relative_path = entry_path.strip_prefix(source)?;
|
||||||
let new_path = destination.join(relative_path);
|
let new_path = destination.join(relative_path);
|
||||||
|
let path_size =
|
||||||
|
entry_path.metadata().map(|x| x.len()).unwrap_or(0);
|
||||||
|
|
||||||
crate::util::fetch::copy(
|
*total_size += path_size;
|
||||||
&entry_path,
|
|
||||||
&new_path,
|
paths.push(MovePath {
|
||||||
io_semaphore,
|
old: entry_path,
|
||||||
)
|
new: new_path,
|
||||||
.await?;
|
size: path_size,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_dir = move_dir.to_string_lossy().to_string();
|
let mut paths: Vec<MovePath> = vec![];
|
||||||
|
let mut total_size = 0;
|
||||||
|
|
||||||
if prev_dir != move_dir {
|
for dir in MOVE_DIRS {
|
||||||
if !is_dir_writeable(&move_dir).await? {
|
add_paths(
|
||||||
settings.custom_dir = Some(prev_custom_dir.clone());
|
&prev_dir.join(dir),
|
||||||
|
&move_dir.join(dir),
|
||||||
return Ok(());
|
&mut paths,
|
||||||
|
&mut total_size,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
emit_loading(
|
||||||
|
&loader_bar_id,
|
||||||
|
10.0 / (MOVE_DIRS.len() as f64),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
move_directory(
|
let paths_len = paths.len();
|
||||||
&prev_dir.join(CACHES_FOLDER_NAME),
|
|
||||||
&app_dir.join(CACHES_FOLDER_NAME),
|
if is_same_disk(&prev_dir, &move_dir).unwrap_or(false) {
|
||||||
|
let success_idxs = Arc::new(DashSet::new());
|
||||||
|
|
||||||
|
let loader_bar_id = Arc::new(&loader_bar_id);
|
||||||
|
let res =
|
||||||
|
futures::future::try_join_all(paths.iter().enumerate().map(|(idx, x)| {
|
||||||
|
let loader_bar_id = loader_bar_id.clone();
|
||||||
|
let success_idxs = success_idxs.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
|
let _permit = io_semaphore.0.acquire().await?;
|
||||||
|
|
||||||
|
if let Some(parent) = x.new.parent() {
|
||||||
|
crate::util::io::create_dir_all(parent).await.map_err(|e| {
|
||||||
|
crate::Error::from(crate::ErrorKind::DirectoryMoveError(
|
||||||
|
format!(
|
||||||
|
"Failed to create directory {}: {}",
|
||||||
|
parent.display(),
|
||||||
|
e
|
||||||
|
)
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
|
crate::util::io::rename(
|
||||||
|
&x.old,
|
||||||
|
&x.new,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
crate::Error::from(crate::ErrorKind::DirectoryMoveError(
|
||||||
|
format!(
|
||||||
|
"Failed to move directory from {} to {}: {}",
|
||||||
|
x.old.display(),
|
||||||
|
x.new.display(),
|
||||||
|
e
|
||||||
|
),
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let _ = emit_loading(
|
||||||
|
&loader_bar_id,
|
||||||
|
90.0 / paths_len as f64,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
success_idxs.insert(idx);
|
||||||
|
|
||||||
|
Ok::<(), crate::Error>(())
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
if let Err(e) = res {
|
||||||
|
for idx in success_idxs.iter() {
|
||||||
|
let path = &paths[*idx.key()];
|
||||||
|
|
||||||
|
let res =
|
||||||
|
tokio::fs::rename(&path.new, &path.old).await;
|
||||||
|
|
||||||
|
if let Err(e) = res {
|
||||||
|
tracing::warn!(
|
||||||
|
"Failed to rollback directory {}: {}",
|
||||||
|
path.new.display(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some(disk_usage) = get_disk_usage(&move_dir)? {
|
||||||
|
if total_size > disk_usage {
|
||||||
|
return Err(crate::ErrorKind::DirectoryMoveError(format!("Not enough space to move directory to {}: only {} bytes available", app_dir.display(), disk_usage)).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let loader_bar_id = Arc::new(&loader_bar_id);
|
||||||
|
futures::future::try_join_all(paths.iter().map(|x| {
|
||||||
|
let loader_bar_id = loader_bar_id.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
|
crate::util::fetch::copy(
|
||||||
|
&x.old,
|
||||||
|
&x.new,
|
||||||
io_semaphore,
|
io_semaphore,
|
||||||
)
|
)
|
||||||
|
.await.map_err(|e| { crate::Error::from(
|
||||||
|
crate::ErrorKind::DirectoryMoveError(format!("Failed to move directory from {} to {}: {}", x.old.display(), x.new.display(), e)))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let _ = emit_loading(
|
||||||
|
&loader_bar_id,
|
||||||
|
((x.size as f64) / (total_size as f64)) * 60.0,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
Ok::<(), crate::Error>(())
|
||||||
|
}
|
||||||
|
}))
|
||||||
.await?;
|
.await?;
|
||||||
move_directory(
|
|
||||||
&prev_dir.join(LAUNCHER_LOGS_FOLDER_NAME),
|
futures::future::join_all(paths.iter().map(|x| {
|
||||||
&app_dir.join(LAUNCHER_LOGS_FOLDER_NAME),
|
let loader_bar_id = loader_bar_id.clone();
|
||||||
io_semaphore,
|
|
||||||
|
async move {
|
||||||
|
let res = async {
|
||||||
|
let _permit = io_semaphore.0.acquire().await?;
|
||||||
|
crate::util::io::remove_file(&x.old).await?;
|
||||||
|
|
||||||
|
emit_loading(
|
||||||
|
&loader_bar_id,
|
||||||
|
30.0 / paths_len as f64,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
move_directory(
|
Ok::<(), crate::Error>(())
|
||||||
&prev_dir.join(PROFILES_FOLDER_NAME),
|
};
|
||||||
&move_dir.join(PROFILES_FOLDER_NAME),
|
|
||||||
io_semaphore,
|
if let Err(e) = res.await {
|
||||||
)
|
tracing::warn!(
|
||||||
.await?;
|
"Failed to remove old file {}: {}",
|
||||||
move_directory(
|
x.old.display(),
|
||||||
&prev_dir.join(METADATA_FOLDER_NAME),
|
e
|
||||||
&move_dir.join(METADATA_FOLDER_NAME),
|
);
|
||||||
io_semaphore,
|
}
|
||||||
)
|
}
|
||||||
.await?;
|
}))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
let java_versions = JavaVersion::get_all(exec).await?;
|
let java_versions = JavaVersion::get_all(exec).await?;
|
||||||
for (_, mut java_version) in java_versions {
|
for (_, mut java_version) in java_versions {
|
||||||
@ -274,15 +477,41 @@ impl DirectoryInfo {
|
|||||||
prev_custom_dir,
|
prev_custom_dir,
|
||||||
new_dir.trim_end_matches('/').trim_end_matches('\\'),
|
new_dir.trim_end_matches('/').trim_end_matches('\\'),
|
||||||
);
|
);
|
||||||
java_version.upsert(exec).await?;
|
java_version.upsert(exec).await?
|
||||||
|
}
|
||||||
|
|
||||||
|
let profiles = Profile::get_all(exec).await?;
|
||||||
|
|
||||||
|
for mut profile in profiles {
|
||||||
|
profile.icon_path = profile.icon_path.map(|x| {
|
||||||
|
x.replace(
|
||||||
|
prev_custom_dir,
|
||||||
|
new_dir
|
||||||
|
.trim_end_matches('/')
|
||||||
|
.trim_end_matches('\\'),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
profile.java_path = profile.java_path.map(|x| {
|
||||||
|
x.replace(
|
||||||
|
prev_custom_dir,
|
||||||
|
new_dir
|
||||||
|
.trim_end_matches('/')
|
||||||
|
.trim_end_matches('\\'),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
profile.upsert(exec).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.custom_dir = Some(new_dir.clone());
|
settings.custom_dir = Some(new_dir);
|
||||||
settings.prev_custom_dir = Some(new_dir);
|
}
|
||||||
|
|
||||||
|
settings.prev_custom_dir.clone_from(&settings.custom_dir);
|
||||||
|
if settings.custom_dir.is_none() {
|
||||||
|
settings.custom_dir = Some(app_dir.to_string_lossy().to_string());
|
||||||
|
}
|
||||||
|
|
||||||
settings.update(exec).await?;
|
settings.update(exec).await?;
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use discord_rich_presence::{
|
|||||||
};
|
};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::state::{Process, Profile};
|
use crate::state::Profile;
|
||||||
use crate::State;
|
use crate::State;
|
||||||
|
|
||||||
pub struct DiscordGuard {
|
pub struct DiscordGuard {
|
||||||
@ -17,8 +17,8 @@ pub struct DiscordGuard {
|
|||||||
impl DiscordGuard {
|
impl DiscordGuard {
|
||||||
/// Initialize discord IPC client, and attempt to connect to it
|
/// Initialize discord IPC client, and attempt to connect to it
|
||||||
/// If it fails, it will still return a DiscordGuard, but the client will be unconnected
|
/// If it fails, it will still return a DiscordGuard, but the client will be unconnected
|
||||||
pub async fn init() -> crate::Result<DiscordGuard> {
|
pub fn init() -> crate::Result<DiscordGuard> {
|
||||||
let mut dipc =
|
let dipc =
|
||||||
DiscordIpcClient::new("1123683254248148992").map_err(|e| {
|
DiscordIpcClient::new("1123683254248148992").map_err(|e| {
|
||||||
crate::ErrorKind::OtherError(format!(
|
crate::ErrorKind::OtherError(format!(
|
||||||
"Could not create Discord client {}",
|
"Could not create Discord client {}",
|
||||||
@ -26,15 +26,10 @@ impl DiscordGuard {
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let res = dipc.connect(); // Do not need to connect to Discord to use app
|
Ok(DiscordGuard {
|
||||||
let connected = if res.is_ok() {
|
client: Arc::new(RwLock::new(dipc)),
|
||||||
Arc::new(AtomicBool::new(true))
|
connected: Arc::new(AtomicBool::new(false)),
|
||||||
} else {
|
})
|
||||||
Arc::new(AtomicBool::new(false))
|
|
||||||
};
|
|
||||||
|
|
||||||
let client = Arc::new(RwLock::new(dipc));
|
|
||||||
Ok(DiscordGuard { client, connected })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the client failed connecting during init(), this will check for connection and attempt to reconnect
|
/// If the client failed connecting during init(), this will check for connection and attempt to reconnect
|
||||||
@ -172,7 +167,7 @@ impl DiscordGuard {
|
|||||||
return self.clear_activity(true).await;
|
return self.clear_activity(true).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let running_profiles = Process::get_all(&state.pool).await?;
|
let running_profiles = state.process_manager.get_all();
|
||||||
if let Some(existing_child) = running_profiles.first() {
|
if let Some(existing_child) = running_profiles.first() {
|
||||||
let prof =
|
let prof =
|
||||||
Profile::get(&existing_child.profile_path, &state.pool).await?;
|
Profile::get(&existing_child.profile_path, &state.pool).await?;
|
||||||
|
|||||||
@ -88,7 +88,7 @@ pub(crate) async fn watch_profiles_init(
|
|||||||
watcher: &FileWatcher,
|
watcher: &FileWatcher,
|
||||||
dirs: &DirectoryInfo,
|
dirs: &DirectoryInfo,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
if let Ok(profiles_dir) = std::fs::read_dir(&dirs.profiles_dir()) {
|
if let Ok(profiles_dir) = std::fs::read_dir(dirs.profiles_dir()) {
|
||||||
for profile_dir in profiles_dir {
|
for profile_dir in profiles_dir {
|
||||||
if let Ok(file_name) = profile_dir.map(|x| x.file_name()) {
|
if let Ok(file_name) = profile_dir.map(|x| x.file_name()) {
|
||||||
if let Some(file_name) = file_name.to_str() {
|
if let Some(file_name) = file_name.to_str() {
|
||||||
@ -112,6 +112,7 @@ pub(crate) async fn watch_profile(
|
|||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let profile_path = dirs.profiles_dir().join(profile_path);
|
let profile_path = dirs.profiles_dir().join(profile_path);
|
||||||
|
|
||||||
|
if profile_path.exists() && profile_path.is_dir() {
|
||||||
for folder in ProjectType::iterator()
|
for folder in ProjectType::iterator()
|
||||||
.map(|x| x.get_folder())
|
.map(|x| x.get_folder())
|
||||||
.chain(["crash-reports"])
|
.chain(["crash-reports"])
|
||||||
@ -125,6 +126,7 @@ pub(crate) async fn watch_profile(
|
|||||||
let mut watcher = watcher.write().await;
|
let mut watcher = watcher.write().await;
|
||||||
watcher.watcher().watch(&path, RecursiveMode::Recursive)?;
|
watcher.watcher().watch(&path, RecursiveMode::Recursive)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
use crate::data::DirectoryInfo;
|
use crate::data::{Dependency, User, Version};
|
||||||
use crate::jre::check_jre;
|
use crate::jre::check_jre;
|
||||||
use crate::prelude::ModLoader;
|
use crate::prelude::ModLoader;
|
||||||
use crate::state;
|
use crate::state;
|
||||||
use crate::state::{
|
use crate::state::{
|
||||||
Credentials, DefaultPage, DeviceToken, DeviceTokenKey, DeviceTokenPair,
|
CacheValue, CachedEntry, CachedFile, CachedFileHash, CachedFileUpdate,
|
||||||
Hooks, LinkedData, MemorySettings, ModrinthCredentials, Profile,
|
Credentials, DefaultPage, DependencyType, DeviceToken, DeviceTokenKey,
|
||||||
ProfileInstallStage, Theme, WindowSize,
|
DeviceTokenPair, FileType, Hooks, LinkedData, MemorySettings,
|
||||||
|
ModrinthCredentials, Profile, ProfileInstallStage, TeamMember, Theme,
|
||||||
|
VersionFile, WindowSize,
|
||||||
};
|
};
|
||||||
use crate::util::fetch::{read_json, IoSemaphore};
|
use crate::util::fetch::{read_json, IoSemaphore};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@ -34,18 +36,6 @@ where
|
|||||||
};
|
};
|
||||||
let old_launcher_root_str = old_launcher_root.to_string_lossy().to_string();
|
let old_launcher_root_str = old_launcher_root.to_string_lossy().to_string();
|
||||||
|
|
||||||
let new_launcher_root = DirectoryInfo::get_initial_settings_dir().ok_or(
|
|
||||||
crate::ErrorKind::FSError(
|
|
||||||
"Could not find valid config dir".to_string(),
|
|
||||||
),
|
|
||||||
)?;
|
|
||||||
let new_launcher_root_str = new_launcher_root
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string()
|
|
||||||
.trim_end_matches('/')
|
|
||||||
.trim_end_matches('\\')
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let io_semaphore = IoSemaphore(Semaphore::new(10));
|
let io_semaphore = IoSemaphore(Semaphore::new(10));
|
||||||
let settings_path = old_launcher_root.join("settings.json");
|
let settings_path = old_launcher_root.join("settings.json");
|
||||||
|
|
||||||
@ -95,13 +85,9 @@ where
|
|||||||
settings.prev_custom_dir = Some(old_launcher_root_str.clone());
|
settings.prev_custom_dir = Some(old_launcher_root_str.clone());
|
||||||
|
|
||||||
for (_, legacy_version) in legacy_settings.java_globals.0 {
|
for (_, legacy_version) in legacy_settings.java_globals.0 {
|
||||||
if let Ok(Some(mut java_version)) =
|
if let Ok(Some(java_version)) =
|
||||||
check_jre(PathBuf::from(legacy_version.path)).await
|
check_jre(PathBuf::from(legacy_version.path)).await
|
||||||
{
|
{
|
||||||
java_version.path = java_version
|
|
||||||
.path
|
|
||||||
.replace(&old_launcher_root_str, &new_launcher_root_str);
|
|
||||||
|
|
||||||
java_version.upsert(exec).await?;
|
java_version.upsert(exec).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,20 +161,144 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut cached_entries = vec![];
|
||||||
|
|
||||||
if let Ok(profiles_dir) = std::fs::read_dir(
|
if let Ok(profiles_dir) = std::fs::read_dir(
|
||||||
&legacy_settings
|
legacy_settings
|
||||||
.loaded_config_dir
|
.loaded_config_dir
|
||||||
.unwrap_or(old_launcher_root)
|
.clone()
|
||||||
|
.unwrap_or_else(|| old_launcher_root.clone())
|
||||||
.join("profiles"),
|
.join("profiles"),
|
||||||
) {
|
) {
|
||||||
for entry in profiles_dir.flatten() {
|
for entry in profiles_dir.flatten() {
|
||||||
if entry.path().is_dir() {
|
if !entry.path().is_dir() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let profile_path = entry.path().join("profile.json");
|
let profile_path = entry.path().join("profile.json");
|
||||||
|
|
||||||
if let Ok(profile) =
|
let profile = if let Ok(profile) =
|
||||||
read_json::<LegacyProfile>(&profile_path, &io_semaphore)
|
read_json::<LegacyProfile>(&profile_path, &io_semaphore)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
profile
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (path, project) in profile.projects {
|
||||||
|
let full_path = legacy_settings
|
||||||
|
.loaded_config_dir
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| old_launcher_root.clone())
|
||||||
|
.join("profiles")
|
||||||
|
.join(&profile.path)
|
||||||
|
.join(&path);
|
||||||
|
|
||||||
|
if !full_path.exists() || !full_path.is_file() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let sha512 = project.sha512;
|
||||||
|
|
||||||
|
if let LegacyProjectMetadata::Modrinth {
|
||||||
|
version,
|
||||||
|
members,
|
||||||
|
update_version,
|
||||||
|
..
|
||||||
|
} = project.metadata
|
||||||
|
{
|
||||||
|
if let Some(file) = version
|
||||||
|
.files
|
||||||
|
.iter()
|
||||||
|
.find(|x| x.hashes.get("sha512") == Some(&sha512))
|
||||||
|
{
|
||||||
|
if let Some(sha1) = file.hashes.get("sha1") {
|
||||||
|
if let Ok(metadata) = full_path.metadata() {
|
||||||
|
let file_name = format!(
|
||||||
|
"{}/{}",
|
||||||
|
profile.path,
|
||||||
|
path.replace("\\", "/")
|
||||||
|
.replace(".disabled", "")
|
||||||
|
);
|
||||||
|
|
||||||
|
cached_entries.push(CacheValue::FileHash(
|
||||||
|
CachedFileHash {
|
||||||
|
path: file_name,
|
||||||
|
size: metadata.len(),
|
||||||
|
hash: sha1.clone(),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
cached_entries.push(CacheValue::File(
|
||||||
|
CachedFile {
|
||||||
|
hash: sha1.clone(),
|
||||||
|
project_id: version.project_id.clone(),
|
||||||
|
version_id: version.id.clone(),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
if let Some(update_version) = update_version {
|
||||||
|
let mod_loader: ModLoader =
|
||||||
|
profile.metadata.loader.into();
|
||||||
|
cached_entries.push(
|
||||||
|
CacheValue::FileUpdate(
|
||||||
|
CachedFileUpdate {
|
||||||
|
hash: sha1.clone(),
|
||||||
|
game_version: profile
|
||||||
|
.metadata
|
||||||
|
.game_version
|
||||||
|
.clone(),
|
||||||
|
loader: mod_loader
|
||||||
|
.as_str()
|
||||||
|
.to_string(),
|
||||||
|
update_version_id:
|
||||||
|
update_version.id.clone(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
cached_entries.push(CacheValue::Version(
|
||||||
|
(*update_version).into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let members = members
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| {
|
||||||
|
let user = User {
|
||||||
|
id: x.user.id,
|
||||||
|
username: x.user.username,
|
||||||
|
avatar_url: x.user.avatar_url,
|
||||||
|
bio: x.user.bio,
|
||||||
|
created: x.user.created,
|
||||||
|
role: x.user.role,
|
||||||
|
};
|
||||||
|
|
||||||
|
cached_entries.push(CacheValue::User(
|
||||||
|
user.clone(),
|
||||||
|
));
|
||||||
|
|
||||||
|
TeamMember {
|
||||||
|
team_id: x.team_id,
|
||||||
|
user: user.clone(),
|
||||||
|
is_owner: x.role == "Owner",
|
||||||
|
role: x.role,
|
||||||
|
ordering: x.ordering,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
cached_entries.push(CacheValue::Team(members));
|
||||||
|
|
||||||
|
cached_entries.push(CacheValue::Version(
|
||||||
|
(*version).into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Profile {
|
Profile {
|
||||||
path: profile.path,
|
path: profile.path,
|
||||||
install_stage: match profile.install_stage {
|
install_stage: match profile.install_stage {
|
||||||
@ -206,29 +316,15 @@ where
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
name: profile.metadata.name,
|
name: profile.metadata.name,
|
||||||
icon_path: profile.metadata.icon.map(|x| {
|
icon_path: profile.metadata.icon,
|
||||||
x.replace(
|
|
||||||
&old_launcher_root_str,
|
|
||||||
&new_launcher_root_str,
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
game_version: profile.metadata.game_version,
|
game_version: profile.metadata.game_version,
|
||||||
loader: match profile.metadata.loader {
|
loader: profile.metadata.loader.into(),
|
||||||
LegacyModLoader::Vanilla => ModLoader::Vanilla,
|
|
||||||
LegacyModLoader::Forge => ModLoader::Forge,
|
|
||||||
LegacyModLoader::Fabric => ModLoader::Fabric,
|
|
||||||
LegacyModLoader::Quilt => ModLoader::Quilt,
|
|
||||||
LegacyModLoader::NeoForge => {
|
|
||||||
ModLoader::NeoForge
|
|
||||||
}
|
|
||||||
},
|
|
||||||
loader_version: profile
|
loader_version: profile
|
||||||
.metadata
|
.metadata
|
||||||
.loader_version
|
.loader_version
|
||||||
.map(|x| x.id),
|
.map(|x| x.id),
|
||||||
groups: profile.metadata.groups,
|
groups: profile.metadata.groups,
|
||||||
linked_data: profile.metadata.linked_data.and_then(
|
linked_data: profile.metadata.linked_data.and_then(|x| {
|
||||||
|x| {
|
|
||||||
if let Some(project_id) = x.project_id {
|
if let Some(project_id) = x.project_id {
|
||||||
if let Some(version_id) = x.version_id {
|
if let Some(version_id) = x.version_id {
|
||||||
if let Some(locked) = x.locked {
|
if let Some(locked) = x.locked {
|
||||||
@ -242,24 +338,16 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
},
|
}),
|
||||||
),
|
|
||||||
created: profile.metadata.date_created,
|
created: profile.metadata.date_created,
|
||||||
modified: profile.metadata.date_modified,
|
modified: profile.metadata.date_modified,
|
||||||
last_played: profile.metadata.last_played,
|
last_played: profile.metadata.last_played,
|
||||||
submitted_time_played: profile
|
submitted_time_played: profile
|
||||||
.metadata
|
.metadata
|
||||||
.submitted_time_played,
|
.submitted_time_played,
|
||||||
recent_time_played: profile
|
recent_time_played: profile.metadata.recent_time_played,
|
||||||
.metadata
|
|
||||||
.recent_time_played,
|
|
||||||
java_path: profile.java.as_ref().and_then(|x| {
|
java_path: profile.java.as_ref().and_then(|x| {
|
||||||
x.override_version.clone().map(|x| {
|
x.override_version.clone().map(|x| x.path)
|
||||||
x.path.replace(
|
|
||||||
&old_launcher_root_str,
|
|
||||||
&new_launcher_root_str,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}),
|
}),
|
||||||
extra_launch_args: profile
|
extra_launch_args: profile
|
||||||
.java
|
.java
|
||||||
@ -284,17 +372,27 @@ where
|
|||||||
.hooks
|
.hooks
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|x| x.wrapper.clone()),
|
.and_then(|x| x.wrapper.clone()),
|
||||||
post_exit: profile
|
post_exit: profile.hooks.and_then(|x| x.post_exit),
|
||||||
.hooks
|
|
||||||
.and_then(|x| x.post_exit),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
.upsert(exec)
|
.upsert(exec)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
CachedEntry::upsert_many(
|
||||||
|
&cached_entries
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| {
|
||||||
|
let mut entry = x.get_entry();
|
||||||
|
entry.expires =
|
||||||
|
Utc::now().timestamp() - entry.type_.expiry();
|
||||||
|
entry
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
exec,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
settings.migrated = true;
|
settings.migrated = true;
|
||||||
settings.update(exec).await?;
|
settings.update(exec).await?;
|
||||||
@ -384,6 +482,12 @@ struct LegacyJavaVersion {
|
|||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
struct LegacyModrinthUser {
|
struct LegacyModrinthUser {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
pub username: String,
|
||||||
|
// pub name: Option<String>,
|
||||||
|
pub avatar_url: Option<String>,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub created: DateTime<Utc>,
|
||||||
|
pub role: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
@ -439,6 +543,195 @@ struct LegacyProfile {
|
|||||||
pub resolution: Option<LegacyWindowSize>,
|
pub resolution: Option<LegacyWindowSize>,
|
||||||
pub fullscreen: Option<bool>,
|
pub fullscreen: Option<bool>,
|
||||||
pub hooks: Option<LegacyHooks>,
|
pub hooks: Option<LegacyHooks>,
|
||||||
|
pub projects: HashMap<String, LegacyProject>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
|
struct LegacyProject {
|
||||||
|
pub sha512: String,
|
||||||
|
// pub disabled: bool,
|
||||||
|
pub metadata: LegacyProjectMetadata,
|
||||||
|
// pub file_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
|
#[serde(tag = "type", rename_all = "snake_case")]
|
||||||
|
enum LegacyProjectMetadata {
|
||||||
|
Modrinth {
|
||||||
|
// project: Box<LegacyModrinthProject>,
|
||||||
|
version: Box<LegacyModrinthVersion>,
|
||||||
|
members: Vec<LegacyModrinthTeamMember>,
|
||||||
|
update_version: Option<Box<LegacyModrinthVersion>>,
|
||||||
|
},
|
||||||
|
Inferred,
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[derive(Deserialize, Clone, Debug)]
|
||||||
|
// struct LegacyModrinthProject {
|
||||||
|
// pub id: String,
|
||||||
|
// pub slug: Option<String>,
|
||||||
|
// pub project_type: String,
|
||||||
|
// pub team: String,
|
||||||
|
// pub title: String,
|
||||||
|
// pub description: String,
|
||||||
|
// pub body: String,
|
||||||
|
//
|
||||||
|
// pub published: DateTime<Utc>,
|
||||||
|
// pub updated: DateTime<Utc>,
|
||||||
|
//
|
||||||
|
// pub client_side: LegacySideType,
|
||||||
|
// pub server_side: LegacySideType,
|
||||||
|
//
|
||||||
|
// pub downloads: u32,
|
||||||
|
// pub followers: u32,
|
||||||
|
//
|
||||||
|
// pub categories: Vec<String>,
|
||||||
|
// pub additional_categories: Vec<String>,
|
||||||
|
// pub game_versions: Vec<String>,
|
||||||
|
// pub loaders: Vec<String>,
|
||||||
|
//
|
||||||
|
// pub versions: Vec<String>,
|
||||||
|
//
|
||||||
|
// pub icon_url: Option<String>,
|
||||||
|
// }
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
|
struct LegacyModrinthVersion {
|
||||||
|
pub id: String,
|
||||||
|
pub project_id: String,
|
||||||
|
pub author_id: String,
|
||||||
|
|
||||||
|
pub featured: bool,
|
||||||
|
|
||||||
|
pub name: String,
|
||||||
|
pub version_number: String,
|
||||||
|
pub changelog: String,
|
||||||
|
pub changelog_url: Option<String>,
|
||||||
|
|
||||||
|
pub date_published: DateTime<Utc>,
|
||||||
|
pub downloads: u32,
|
||||||
|
pub version_type: String,
|
||||||
|
|
||||||
|
pub files: Vec<LegacyModrinthVersionFile>,
|
||||||
|
pub dependencies: Vec<LegacyDependency>,
|
||||||
|
pub game_versions: Vec<String>,
|
||||||
|
pub loaders: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<LegacyModrinthVersion> for Version {
|
||||||
|
fn from(value: LegacyModrinthVersion) -> Self {
|
||||||
|
Version {
|
||||||
|
id: value.id,
|
||||||
|
project_id: value.project_id,
|
||||||
|
author_id: value.author_id,
|
||||||
|
featured: value.featured,
|
||||||
|
name: value.name,
|
||||||
|
version_number: value.version_number,
|
||||||
|
changelog: value.changelog,
|
||||||
|
changelog_url: value.changelog_url,
|
||||||
|
date_published: value.date_published,
|
||||||
|
downloads: value.downloads,
|
||||||
|
version_type: value.version_type,
|
||||||
|
files: value
|
||||||
|
.files
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| VersionFile {
|
||||||
|
hashes: x.hashes,
|
||||||
|
url: x.url,
|
||||||
|
filename: x.filename,
|
||||||
|
primary: x.primary,
|
||||||
|
size: x.size,
|
||||||
|
file_type: x.file_type.map(|x| match x {
|
||||||
|
LegacyFileType::RequiredResourcePack => {
|
||||||
|
FileType::RequiredResourcePack
|
||||||
|
}
|
||||||
|
LegacyFileType::OptionalResourcePack => {
|
||||||
|
FileType::OptionalResourcePack
|
||||||
|
}
|
||||||
|
LegacyFileType::Unknown => FileType::Unknown,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
dependencies: value
|
||||||
|
.dependencies
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| Dependency {
|
||||||
|
version_id: x.version_id,
|
||||||
|
project_id: x.project_id,
|
||||||
|
file_name: x.file_name,
|
||||||
|
dependency_type: match x.dependency_type {
|
||||||
|
LegacyDependencyType::Required => {
|
||||||
|
DependencyType::Required
|
||||||
|
}
|
||||||
|
LegacyDependencyType::Optional => {
|
||||||
|
DependencyType::Optional
|
||||||
|
}
|
||||||
|
LegacyDependencyType::Incompatible => {
|
||||||
|
DependencyType::Incompatible
|
||||||
|
}
|
||||||
|
LegacyDependencyType::Embedded => {
|
||||||
|
DependencyType::Embedded
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
game_versions: value.game_versions,
|
||||||
|
loaders: value.loaders,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
|
struct LegacyModrinthVersionFile {
|
||||||
|
pub hashes: HashMap<String, String>,
|
||||||
|
pub url: String,
|
||||||
|
pub filename: String,
|
||||||
|
pub primary: bool,
|
||||||
|
pub size: u32,
|
||||||
|
pub file_type: Option<LegacyFileType>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
|
struct LegacyDependency {
|
||||||
|
pub version_id: Option<String>,
|
||||||
|
pub project_id: Option<String>,
|
||||||
|
pub file_name: Option<String>,
|
||||||
|
pub dependency_type: LegacyDependencyType,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
|
struct LegacyModrinthTeamMember {
|
||||||
|
pub team_id: String,
|
||||||
|
pub user: LegacyModrinthUser,
|
||||||
|
pub role: String,
|
||||||
|
pub ordering: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Copy, Clone, Debug)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
enum LegacyDependencyType {
|
||||||
|
Required,
|
||||||
|
Optional,
|
||||||
|
Incompatible,
|
||||||
|
Embedded,
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
|
||||||
|
// #[serde(rename_all = "kebab-case")]
|
||||||
|
// enum LegacySideType {
|
||||||
|
// Required,
|
||||||
|
// Optional,
|
||||||
|
// Unsupported,
|
||||||
|
// Unknown,
|
||||||
|
// }
|
||||||
|
|
||||||
|
#[derive(Deserialize, Copy, Clone, Debug)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
enum LegacyFileType {
|
||||||
|
RequiredResourcePack,
|
||||||
|
OptionalResourcePack,
|
||||||
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
@ -477,6 +770,18 @@ enum LegacyModLoader {
|
|||||||
NeoForge,
|
NeoForge,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<LegacyModLoader> for ModLoader {
|
||||||
|
fn from(value: LegacyModLoader) -> Self {
|
||||||
|
match value {
|
||||||
|
LegacyModLoader::Vanilla => ModLoader::Vanilla,
|
||||||
|
LegacyModLoader::Forge => ModLoader::Forge,
|
||||||
|
LegacyModLoader::Fabric => ModLoader::Fabric,
|
||||||
|
LegacyModLoader::Quilt => ModLoader::Quilt,
|
||||||
|
LegacyModLoader::NeoForge => ModLoader::NeoForge,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
struct LegacyLinkedData {
|
struct LegacyLinkedData {
|
||||||
pub project_id: Option<String>,
|
pub project_id: Option<String>,
|
||||||
|
|||||||
@ -1,8 +1,4 @@
|
|||||||
//! Theseus state management system
|
//! Theseus state management system
|
||||||
use crate::event::emit::{emit_loading, init_loading_unsafe};
|
|
||||||
|
|
||||||
use crate::event::LoadingBarType;
|
|
||||||
|
|
||||||
use crate::util::fetch::{FetchSemaphore, IoSemaphore};
|
use crate::util::fetch::{FetchSemaphore, IoSemaphore};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{OnceCell, Semaphore};
|
use tokio::sync::{OnceCell, Semaphore};
|
||||||
@ -35,7 +31,7 @@ pub use self::minecraft_auth::*;
|
|||||||
mod cache;
|
mod cache;
|
||||||
pub use self::cache::*;
|
pub use self::cache::*;
|
||||||
|
|
||||||
mod db;
|
pub mod db;
|
||||||
pub mod fs_watcher;
|
pub mod fs_watcher;
|
||||||
mod mr_auth;
|
mod mr_auth;
|
||||||
|
|
||||||
@ -61,6 +57,9 @@ pub struct State {
|
|||||||
/// Discord RPC
|
/// Discord RPC
|
||||||
pub discord_rpc: DiscordGuard,
|
pub discord_rpc: DiscordGuard,
|
||||||
|
|
||||||
|
/// Process manager
|
||||||
|
pub process_manager: ProcessManager,
|
||||||
|
|
||||||
pub(crate) pool: SqlitePool,
|
pub(crate) pool: SqlitePool,
|
||||||
|
|
||||||
pub(crate) file_watcher: FileWatcher,
|
pub(crate) file_watcher: FileWatcher,
|
||||||
@ -72,7 +71,13 @@ impl State {
|
|||||||
.get_or_try_init(Self::initialize_state)
|
.get_or_try_init(Self::initialize_state)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Process::garbage_collect(&state.pool).await?;
|
tokio::task::spawn(async move {
|
||||||
|
let res = state.discord_rpc.clear_to_default(true).await;
|
||||||
|
|
||||||
|
if let Err(e) = res {
|
||||||
|
tracing::error!("Error running discord RPC: {e}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -94,13 +99,6 @@ impl State {
|
|||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
async fn initialize_state() -> crate::Result<Arc<Self>> {
|
async fn initialize_state() -> crate::Result<Arc<Self>> {
|
||||||
let loading_bar = init_loading_unsafe(
|
|
||||||
LoadingBarType::StateInit,
|
|
||||||
100.0,
|
|
||||||
"Initializing launcher",
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let pool = db::connect().await?;
|
let pool = db::connect().await?;
|
||||||
|
|
||||||
legacy_converter::migrate_legacy_data(&pool).await?;
|
legacy_converter::migrate_legacy_data(&pool).await?;
|
||||||
@ -120,29 +118,20 @@ impl State {
|
|||||||
&io_semaphore,
|
&io_semaphore,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let directories = DirectoryInfo::init(settings.custom_dir).await?;
|
let directories = DirectoryInfo::init(settings.custom_dir).await?;
|
||||||
|
|
||||||
emit_loading(&loading_bar, 10.0, None).await?;
|
let discord_rpc = DiscordGuard::init()?;
|
||||||
|
|
||||||
let discord_rpc = DiscordGuard::init().await?;
|
|
||||||
if settings.discord_rpc {
|
|
||||||
// Add default Idling to discord rich presence
|
|
||||||
// Force add to avoid recursion
|
|
||||||
let _ = discord_rpc.force_set_activity("Idling...", true).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
let file_watcher = fs_watcher::init_watcher().await?;
|
let file_watcher = fs_watcher::init_watcher().await?;
|
||||||
fs_watcher::watch_profiles_init(&file_watcher, &directories).await?;
|
fs_watcher::watch_profiles_init(&file_watcher, &directories).await?;
|
||||||
|
|
||||||
emit_loading(&loading_bar, 10.0, None).await?;
|
|
||||||
|
|
||||||
Ok(Arc::new(Self {
|
Ok(Arc::new(Self {
|
||||||
directories,
|
directories,
|
||||||
fetch_semaphore,
|
fetch_semaphore,
|
||||||
io_semaphore,
|
io_semaphore,
|
||||||
api_semaphore,
|
api_semaphore,
|
||||||
discord_rpc,
|
discord_rpc,
|
||||||
|
process_manager: ProcessManager::new(),
|
||||||
pool,
|
pool,
|
||||||
file_watcher,
|
file_watcher,
|
||||||
}))
|
}))
|
||||||
|
|||||||
@ -1,136 +1,134 @@
|
|||||||
use chrono::{DateTime, Utc};
|
|
||||||
use serde::Deserialize;
|
|
||||||
use serde::Serialize;
|
|
||||||
use tokio::process::Command;
|
|
||||||
|
|
||||||
use crate::event::emit::emit_process;
|
use crate::event::emit::emit_process;
|
||||||
use crate::event::ProcessPayloadType;
|
use crate::event::ProcessPayloadType;
|
||||||
|
use crate::profile;
|
||||||
use crate::util::io::IOError;
|
use crate::util::io::IOError;
|
||||||
use crate::{profile, ErrorKind};
|
use chrono::{DateTime, Utc};
|
||||||
|
use dashmap::DashMap;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use serde::Serialize;
|
||||||
|
use std::process::ExitStatus;
|
||||||
|
use tokio::process::{Child, Command};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
pub struct ProcessManager {
|
||||||
pub struct Process {
|
processes: DashMap<Uuid, Process>,
|
||||||
pub pid: i64,
|
|
||||||
pub start_time: i64,
|
|
||||||
pub name: String,
|
|
||||||
pub executable: String,
|
|
||||||
pub profile_path: String,
|
|
||||||
pub post_exit_command: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! select_process_with_predicate {
|
impl Default for ProcessManager {
|
||||||
($predicate:tt, $param:ident) => {
|
fn default() -> Self {
|
||||||
sqlx::query_as!(
|
Self::new()
|
||||||
Process,
|
}
|
||||||
r#"
|
|
||||||
SELECT
|
|
||||||
pid, start_time, name, executable, profile_path, post_exit_command
|
|
||||||
FROM processes
|
|
||||||
"#
|
|
||||||
+ $predicate,
|
|
||||||
$param
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Process {
|
impl ProcessManager {
|
||||||
/// Runs on launcher startup. Queries all the cached processes and removes processes that no
|
pub fn new() -> Self {
|
||||||
/// longer exist. If a PID is found, they are "rescued" and passed to our process manager
|
Self {
|
||||||
pub async fn garbage_collect(
|
processes: DashMap::new(),
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite> + Copy,
|
|
||||||
) -> crate::Result<()> {
|
|
||||||
let processes = Self::get_all(exec).await?;
|
|
||||||
|
|
||||||
let mut system = sysinfo::System::new();
|
|
||||||
system.refresh_processes();
|
|
||||||
for cached_process in processes {
|
|
||||||
let process = system
|
|
||||||
.process(sysinfo::Pid::from_u32(cached_process.pid as u32));
|
|
||||||
|
|
||||||
if let Some(process) = process {
|
|
||||||
if cached_process.start_time as u64 == process.start_time()
|
|
||||||
&& cached_process.name == process.name()
|
|
||||||
&& cached_process.executable
|
|
||||||
== process
|
|
||||||
.exe()
|
|
||||||
.map(|x| x.to_string_lossy())
|
|
||||||
.unwrap_or_default()
|
|
||||||
{
|
|
||||||
tokio::spawn(cached_process.sequential_process_manager());
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::remove(cached_process.pid as u32, exec).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn insert_new_process(
|
pub async fn insert_new_process(
|
||||||
|
&self,
|
||||||
profile_path: &str,
|
profile_path: &str,
|
||||||
mut mc_command: Command,
|
mut mc_command: Command,
|
||||||
post_exit_command: Option<String>, // Command to run after minecraft.
|
post_exit_command: Option<String>,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
) -> crate::Result<ProcessMetadata> {
|
||||||
) -> crate::Result<Self> {
|
|
||||||
let mc_proc = mc_command.spawn().map_err(IOError::from)?;
|
let mc_proc = mc_command.spawn().map_err(IOError::from)?;
|
||||||
|
|
||||||
let pid = mc_proc.id().ok_or_else(|| {
|
let process = Process {
|
||||||
crate::ErrorKind::LauncherError(
|
metadata: ProcessMetadata {
|
||||||
"Process immediately failed, could not get PID".to_string(),
|
uuid: Uuid::new_v4(),
|
||||||
)
|
start_time: Utc::now(),
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut system = sysinfo::System::new();
|
|
||||||
system.refresh_processes();
|
|
||||||
let process =
|
|
||||||
system.process(sysinfo::Pid::from_u32(pid)).ok_or_else(|| {
|
|
||||||
crate::ErrorKind::LauncherError(format!(
|
|
||||||
"Could not find process {}",
|
|
||||||
pid
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
let start_time = process.start_time();
|
|
||||||
let name = process.name().to_string();
|
|
||||||
|
|
||||||
let Some(path) = process.exe() else {
|
|
||||||
return Err(ErrorKind::LauncherError(format!(
|
|
||||||
"Cached process {} has no accessible path",
|
|
||||||
pid
|
|
||||||
))
|
|
||||||
.into());
|
|
||||||
};
|
|
||||||
|
|
||||||
let executable = path.to_string_lossy().to_string();
|
|
||||||
|
|
||||||
let process = Self {
|
|
||||||
pid: pid as i64,
|
|
||||||
start_time: start_time as i64,
|
|
||||||
name,
|
|
||||||
executable,
|
|
||||||
profile_path: profile_path.to_string(),
|
profile_path: profile_path.to_string(),
|
||||||
post_exit_command,
|
},
|
||||||
|
child: mc_proc,
|
||||||
};
|
};
|
||||||
process.upsert(exec).await?;
|
|
||||||
|
|
||||||
tokio::spawn(process.clone().sequential_process_manager());
|
let metadata = process.metadata.clone();
|
||||||
|
|
||||||
|
tokio::spawn(Process::sequential_process_manager(
|
||||||
|
profile_path.to_string(),
|
||||||
|
post_exit_command,
|
||||||
|
metadata.uuid,
|
||||||
|
));
|
||||||
|
|
||||||
|
self.processes.insert(process.metadata.uuid, process);
|
||||||
|
|
||||||
emit_process(
|
emit_process(
|
||||||
profile_path,
|
profile_path,
|
||||||
pid,
|
metadata.uuid,
|
||||||
ProcessPayloadType::Launched,
|
ProcessPayloadType::Launched,
|
||||||
"Launched Minecraft",
|
"Launched Minecraft",
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(process)
|
Ok(metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get(&self, id: Uuid) -> Option<ProcessMetadata> {
|
||||||
|
self.processes.get(&id).map(|x| x.metadata.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_all(&self) -> Vec<ProcessMetadata> {
|
||||||
|
self.processes
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.value().metadata.clone())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn try_wait(
|
||||||
|
&self,
|
||||||
|
id: Uuid,
|
||||||
|
) -> crate::Result<Option<Option<ExitStatus>>> {
|
||||||
|
if let Some(mut process) = self.processes.get_mut(&id) {
|
||||||
|
Ok(Some(process.child.try_wait()?))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn wait_for(&self, id: Uuid) -> crate::Result<()> {
|
||||||
|
if let Some(mut process) = self.processes.get_mut(&id) {
|
||||||
|
process.child.wait().await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn kill(&self, id: Uuid) -> crate::Result<()> {
|
||||||
|
if let Some(mut process) = self.processes.get_mut(&id) {
|
||||||
|
process.child.kill().await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove(&self, id: Uuid) {
|
||||||
|
self.processes.remove(&id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
|
pub struct ProcessMetadata {
|
||||||
|
pub uuid: Uuid,
|
||||||
|
pub profile_path: String,
|
||||||
|
pub start_time: DateTime<Utc>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Process {
|
||||||
|
metadata: ProcessMetadata,
|
||||||
|
child: Child,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Process {
|
||||||
// Spawns a new child process and inserts it into the hashmap
|
// Spawns a new child process and inserts it into the hashmap
|
||||||
// Also, as the process ends, it spawns the follow-up process if it exists
|
// Also, as the process ends, it spawns the follow-up process if it exists
|
||||||
// By convention, ExitStatus is last command's exit status, and we exit on the first non-zero exit status
|
// By convention, ExitStatus is last command's exit status, and we exit on the first non-zero exit status
|
||||||
async fn sequential_process_manager(self) -> crate::Result<i32> {
|
async fn sequential_process_manager(
|
||||||
|
profile_path: String,
|
||||||
|
post_exit_command: Option<String>,
|
||||||
|
uuid: Uuid,
|
||||||
|
) -> crate::Result<()> {
|
||||||
async fn update_playtime(
|
async fn update_playtime(
|
||||||
last_updated_playtime: &mut DateTime<Utc>,
|
last_updated_playtime: &mut DateTime<Utc>,
|
||||||
profile_path: &str,
|
profile_path: &str,
|
||||||
@ -160,207 +158,79 @@ impl Process {
|
|||||||
let mc_exit_status;
|
let mc_exit_status;
|
||||||
let mut last_updated_playtime = Utc::now();
|
let mut last_updated_playtime = Utc::now();
|
||||||
|
|
||||||
|
let state = crate::State::get().await?;
|
||||||
loop {
|
loop {
|
||||||
if let Some(t) = self.try_wait().await? {
|
if let Some(process) = state.process_manager.try_wait(uuid)? {
|
||||||
|
if let Some(t) = process {
|
||||||
mc_exit_status = t;
|
mc_exit_status = t;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
mc_exit_status = ExitStatus::default();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// sleep for 10ms
|
// sleep for 10ms
|
||||||
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
|
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
|
||||||
|
|
||||||
// Auto-update playtime every minute
|
// Auto-update playtime every minute
|
||||||
update_playtime(
|
update_playtime(&mut last_updated_playtime, &profile_path, false)
|
||||||
&mut last_updated_playtime,
|
|
||||||
&self.profile_path,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.process_manager.remove(uuid);
|
||||||
|
emit_process(
|
||||||
|
&profile_path,
|
||||||
|
uuid,
|
||||||
|
ProcessPayloadType::Finished,
|
||||||
|
"Exited process",
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Now fully complete- update playtime one last time
|
// Now fully complete- update playtime one last time
|
||||||
update_playtime(&mut last_updated_playtime, &self.profile_path, true)
|
update_playtime(&mut last_updated_playtime, &profile_path, true).await;
|
||||||
.await;
|
|
||||||
|
|
||||||
// Publish play time update
|
// Publish play time update
|
||||||
// Allow failure, it will be stored locally and sent next time
|
// Allow failure, it will be stored locally and sent next time
|
||||||
// Sent in another thread as first call may take a couple seconds and hold up process ending
|
// Sent in another thread as first call may take a couple seconds and hold up process ending
|
||||||
let profile_path = self.profile_path.clone();
|
let profile = profile_path.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Err(e) =
|
if let Err(e) = profile::try_update_playtime(&profile).await {
|
||||||
profile::try_update_playtime(&profile_path.clone()).await
|
|
||||||
{
|
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"Failed to update playtime for profile {}: {}",
|
"Failed to update playtime for profile {}: {}",
|
||||||
&profile_path,
|
profile,
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = crate::State::get().await?;
|
|
||||||
let _ = state.discord_rpc.clear_to_default(true).await;
|
let _ = state.discord_rpc.clear_to_default(true).await;
|
||||||
|
|
||||||
Self::remove(self.pid as u32, &state.pool).await?;
|
|
||||||
|
|
||||||
// If in tauri, window should show itself again after process exists if it was hidden
|
// If in tauri, window should show itself again after process exists if it was hidden
|
||||||
#[cfg(feature = "tauri")]
|
#[cfg(feature = "tauri")]
|
||||||
{
|
{
|
||||||
let window = crate::EventState::get_main_window().await?;
|
let window = crate::EventState::get_main_window().await?;
|
||||||
if let Some(window) = window {
|
if let Some(window) = window {
|
||||||
window.unminimize()?;
|
window.unminimize()?;
|
||||||
|
window.set_focus()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if mc_exit_status == 0 {
|
if mc_exit_status.success() {
|
||||||
// We do not wait on the post exist command to finish running! We let it spawn + run on its own.
|
// We do not wait on the post exist command to finish running! We let it spawn + run on its own.
|
||||||
// This behaviour may be changed in the future
|
// This behaviour may be changed in the future
|
||||||
if let Some(hook) = self.post_exit_command {
|
if let Some(hook) = post_exit_command {
|
||||||
let mut cmd = hook.split(' ');
|
let mut cmd = hook.split(' ');
|
||||||
if let Some(command) = cmd.next() {
|
if let Some(command) = cmd.next() {
|
||||||
let mut command = Command::new(command);
|
let mut command = Command::new(command);
|
||||||
command.args(&cmd.collect::<Vec<&str>>()).current_dir(
|
command.args(cmd.collect::<Vec<&str>>()).current_dir(
|
||||||
crate::api::profile::get_full_path(&self.profile_path)
|
profile::get_full_path(&profile_path).await?,
|
||||||
.await?,
|
|
||||||
);
|
);
|
||||||
command.spawn().map_err(IOError::from)?;
|
command.spawn().map_err(IOError::from)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_process(
|
|
||||||
&self.profile_path,
|
|
||||||
self.pid as u32,
|
|
||||||
ProcessPayloadType::Finished,
|
|
||||||
"Exited process",
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(mc_exit_status)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn try_wait(&self) -> crate::Result<Option<i32>> {
|
|
||||||
let mut system = sysinfo::System::new();
|
|
||||||
if !system.refresh_process(sysinfo::Pid::from_u32(self.pid as u32)) {
|
|
||||||
return Ok(Some(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
let process = system.process(sysinfo::Pid::from_u32(self.pid as u32));
|
|
||||||
|
|
||||||
if let Some(process) = process {
|
|
||||||
if process.status() == sysinfo::ProcessStatus::Run {
|
|
||||||
Ok(None)
|
|
||||||
} else {
|
|
||||||
Ok(Some(0))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok(Some(0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn wait_for(&self) -> crate::Result<()> {
|
|
||||||
loop {
|
|
||||||
if self.try_wait().await?.is_some() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// sleep for 10ms
|
|
||||||
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn kill(&self) -> crate::Result<()> {
|
|
||||||
let mut system = sysinfo::System::new();
|
|
||||||
if system.refresh_process(sysinfo::Pid::from_u32(self.pid as u32)) {
|
|
||||||
let process =
|
|
||||||
system.process(sysinfo::Pid::from_u32(self.pid as u32));
|
|
||||||
if let Some(process) = process {
|
|
||||||
process.kill();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get(
|
|
||||||
pid: i32,
|
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
||||||
) -> crate::Result<Option<Self>> {
|
|
||||||
let res = select_process_with_predicate!("WHERE pid = $1", pid)
|
|
||||||
.fetch_optional(exec)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_from_profile(
|
|
||||||
profile_path: &str,
|
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
||||||
) -> crate::Result<Vec<Self>> {
|
|
||||||
let results = select_process_with_predicate!(
|
|
||||||
"WHERE profile_path = $1",
|
|
||||||
profile_path
|
|
||||||
)
|
|
||||||
.fetch_all(exec)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(results)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_all(
|
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
||||||
) -> crate::Result<Vec<Self>> {
|
|
||||||
let true_val = 1;
|
|
||||||
let results = select_process_with_predicate!("WHERE 1=$1", true_val)
|
|
||||||
.fetch_all(exec)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(results)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn upsert(
|
|
||||||
&self,
|
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
||||||
) -> crate::Result<()> {
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
INSERT INTO processes (pid, start_time, name, executable, profile_path, post_exit_command)
|
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
|
||||||
ON CONFLICT (pid) DO UPDATE SET
|
|
||||||
start_time = $2,
|
|
||||||
name = $3,
|
|
||||||
executable = $4,
|
|
||||||
profile_path = $5,
|
|
||||||
post_exit_command = $6
|
|
||||||
",
|
|
||||||
self.pid,
|
|
||||||
self.start_time,
|
|
||||||
self.name,
|
|
||||||
self.executable,
|
|
||||||
self.profile_path,
|
|
||||||
self.post_exit_command
|
|
||||||
)
|
|
||||||
.execute(exec)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn remove(
|
|
||||||
pid: u32,
|
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite>,
|
|
||||||
) -> crate::Result<()> {
|
|
||||||
let pid = pid as i32;
|
|
||||||
|
|
||||||
sqlx::query!(
|
|
||||||
"
|
|
||||||
DELETE FROM processes WHERE pid = $1
|
|
||||||
",
|
|
||||||
pid,
|
|
||||||
)
|
|
||||||
.execute(exec)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user