You've already forked AstralRinth
forked from didirus/AstralRinth
Offline mode (#403)
* offline mode * fixes, mixpanels, etc * changes * prettier * rev * actions
This commit is contained in:
@@ -86,7 +86,12 @@
|
||||
<RouterView v-slot="{ Component }">
|
||||
<template v-if="Component">
|
||||
<Suspense @pending="loadingBar.startLoading()" @resolve="loadingBar.stopLoading()">
|
||||
<component :is="Component" :instance="instance" :options="options"></component>
|
||||
<component
|
||||
:is="Component"
|
||||
:instance="instance"
|
||||
:options="options"
|
||||
:offline="offline"
|
||||
></component>
|
||||
</Suspense>
|
||||
</template>
|
||||
</RouterView>
|
||||
@@ -144,13 +149,13 @@ import {
|
||||
get_uuids_by_profile_path,
|
||||
kill_by_uuid,
|
||||
} from '@/helpers/process'
|
||||
import { process_listener, profile_listener } from '@/helpers/events'
|
||||
import { offline_listener, process_listener, profile_listener } from '@/helpers/events'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ref, onUnmounted } from 'vue'
|
||||
import { handleError, useBreadcrumbs, useLoading } from '@/store/state'
|
||||
import { showProfileInFolder } from '@/helpers/utils.js'
|
||||
import { isOffline, showProfileInFolder } from '@/helpers/utils.js'
|
||||
import ContextMenu from '@/components/ui/ContextMenu.vue'
|
||||
import mixpanel from 'mixpanel-browser'
|
||||
import { mixpanel_track } from '@/helpers/mixpanel'
|
||||
import { PackageIcon } from '@/assets/icons/index.js'
|
||||
import ExportModal from '@/components/ui/ExportModal.vue'
|
||||
import { convertFileSrc } from '@tauri-apps/api/tauri'
|
||||
@@ -170,6 +175,8 @@ breadcrumbs.setContext({
|
||||
query: route.query,
|
||||
})
|
||||
|
||||
const offline = ref(await isOffline())
|
||||
|
||||
const loadingBar = useLoading()
|
||||
|
||||
const uuid = ref(null)
|
||||
@@ -183,7 +190,7 @@ const startInstance = async (context) => {
|
||||
loading.value = false
|
||||
playing.value = true
|
||||
|
||||
mixpanel.track('InstanceStart', {
|
||||
mixpanel_track('InstanceStart', {
|
||||
loader: instance.value.metadata.loader,
|
||||
game_version: instance.value.metadata.game_version,
|
||||
source: context,
|
||||
@@ -211,7 +218,7 @@ const stopInstance = async (context) => {
|
||||
uuids.forEach(async (u) => await kill_by_uuid(u).catch(handleError))
|
||||
} else await kill_by_uuid(uuid.value).catch(handleError)
|
||||
|
||||
mixpanel.track('InstanceStop', {
|
||||
mixpanel_track('InstanceStop', {
|
||||
loader: instance.value.metadata.loader,
|
||||
game_version: instance.value.metadata.game_version,
|
||||
source: context,
|
||||
@@ -292,9 +299,14 @@ const unlistenProcesses = await process_listener((e) => {
|
||||
if (e.event === 'finished' && uuid.value === e.uuid) playing.value = false
|
||||
})
|
||||
|
||||
const unlistenOffline = await offline_listener((b) => {
|
||||
offline.value = b
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
unlistenProcesses()
|
||||
unlistenProfiles()
|
||||
unlistenOffline()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<CheckIcon v-else />
|
||||
{{ copied ? 'Copied' : 'Copy' }}
|
||||
</Button>
|
||||
<Button color="primary" @click="share">
|
||||
<Button color="primary" :disabled="offline" @click="share">
|
||||
<ShareIcon />
|
||||
Share
|
||||
</Button>
|
||||
@@ -78,6 +78,10 @@ const props = defineProps({
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
offline: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
const logs = ref([])
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
</Button>
|
||||
<Button
|
||||
class="transparent update"
|
||||
:disabled="offline"
|
||||
@click="updateAll()"
|
||||
@mouseover="selectedOption = 'Update'"
|
||||
>
|
||||
@@ -139,7 +140,7 @@
|
||||
</Button>
|
||||
</section>
|
||||
<section v-if="selectedOption === 'Update'" class="options">
|
||||
<Button class="transparent" @click="updateAll()">
|
||||
<Button class="transparent" :disabled="offline" @click="updateAll()">
|
||||
<UpdatedIcon />
|
||||
Update all
|
||||
</Button>
|
||||
@@ -181,6 +182,7 @@
|
||||
<router-link
|
||||
v-if="mod.slug"
|
||||
:to="{ path: `/project/${mod.slug}/`, query: { i: props.instance.path } }"
|
||||
:disabled="offline"
|
||||
class="mod-content"
|
||||
>
|
||||
<Avatar :src="mod.icon" />
|
||||
@@ -208,7 +210,7 @@
|
||||
<Button
|
||||
v-else
|
||||
v-tooltip="'Update project'"
|
||||
:disabled="!mod.outdated"
|
||||
:disabled="!mod.outdated || offline"
|
||||
icon-only
|
||||
@click="updateProject(mod)"
|
||||
>
|
||||
@@ -345,7 +347,7 @@ import {
|
||||
update_project,
|
||||
} from '@/helpers/profile.js'
|
||||
import { handleError } from '@/store/notifications.js'
|
||||
import mixpanel from 'mixpanel-browser'
|
||||
import { mixpanel_track } from '@/helpers/mixpanel'
|
||||
import { open } from '@tauri-apps/api/dialog'
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
import { convertFileSrc } from '@tauri-apps/api/tauri'
|
||||
@@ -368,6 +370,12 @@ const props = defineProps({
|
||||
return {}
|
||||
},
|
||||
},
|
||||
offline: {
|
||||
type: Boolean,
|
||||
default() {
|
||||
return false
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const projects = ref([])
|
||||
@@ -376,8 +384,9 @@ const showingOptions = ref(false)
|
||||
|
||||
const initProjects = (initInstance) => {
|
||||
projects.value = []
|
||||
if (!initInstance || !initInstance.projects) return
|
||||
for (const [path, project] of Object.entries(initInstance.projects)) {
|
||||
if (project.metadata.type === 'modrinth') {
|
||||
if (project.metadata.type === 'modrinth' && !props.offline) {
|
||||
let owner = project.metadata.members.find((x) => x.role === 'Owner')
|
||||
projects.value.push({
|
||||
path,
|
||||
@@ -442,6 +451,13 @@ watch(
|
||||
}
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.offline,
|
||||
() => {
|
||||
if (props.instance) initProjects(props.instance)
|
||||
}
|
||||
)
|
||||
|
||||
const searchFilter = ref('')
|
||||
const selectAll = ref(false)
|
||||
const selectedProjectType = ref('All')
|
||||
@@ -576,7 +592,7 @@ const updateAll = async () => {
|
||||
projects.value[project].updating = false
|
||||
}
|
||||
|
||||
mixpanel.track('InstanceUpdateAll', {
|
||||
mixpanel_track('InstanceUpdateAll', {
|
||||
loader: props.instance.metadata.loader,
|
||||
game_version: props.instance.metadata.game_version,
|
||||
count: setProjects.length,
|
||||
@@ -601,7 +617,7 @@ const updateProject = async (mod) => {
|
||||
mod.version = mod.updateVersion.version_number
|
||||
mod.updateVersion = null
|
||||
|
||||
mixpanel.track('InstanceProjectUpdate', {
|
||||
mixpanel_track('InstanceProjectUpdate', {
|
||||
loader: props.instance.metadata.loader,
|
||||
game_version: props.instance.metadata.game_version,
|
||||
id: mod.id,
|
||||
@@ -628,7 +644,7 @@ const toggleDisableMod = async (mod) => {
|
||||
.then((newPath) => {
|
||||
mod.path = newPath
|
||||
mod.disabled = !mod.disabled
|
||||
mixpanel.track('InstanceProjectDisable', {
|
||||
mixpanel_track('InstanceProjectDisable', {
|
||||
loader: props.instance.metadata.loader,
|
||||
game_version: props.instance.metadata.game_version,
|
||||
id: mod.id,
|
||||
@@ -649,7 +665,7 @@ const removeMod = async (mod) => {
|
||||
await remove_project(props.instance.path, mod.path).catch(handleError)
|
||||
projects.value = projects.value.filter((x) => mod.path !== x.path)
|
||||
|
||||
mixpanel.track('InstanceProjectRemove', {
|
||||
mixpanel_track('InstanceProjectRemove', {
|
||||
loader: props.instance.metadata.loader,
|
||||
game_version: props.instance.metadata.game_version,
|
||||
id: mod.id,
|
||||
@@ -778,7 +794,7 @@ listen('tauri://file-drop', async (event) => {
|
||||
}
|
||||
initProjects(await get(props.instance.path).catch(handleError))
|
||||
}
|
||||
mixpanel.track('InstanceCreate', {
|
||||
mixpanel_track('InstanceCreate', {
|
||||
source: 'FileDrop',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -90,7 +90,12 @@
|
||||
Allows you to change the mod loader, loader version, or game version of the instance.
|
||||
</span>
|
||||
</label>
|
||||
<button id="edit-versions" class="btn" @click="$refs.changeVersionsModal.show()">
|
||||
<button
|
||||
id="edit-versions"
|
||||
class="btn"
|
||||
@click="$refs.changeVersionsModal.show()"
|
||||
:disabled="offline"
|
||||
>
|
||||
<EditIcon />
|
||||
Edit versions
|
||||
</button>
|
||||
@@ -291,7 +296,7 @@
|
||||
<button
|
||||
id="repair-profile"
|
||||
class="btn btn-highlight"
|
||||
:disabled="repairing"
|
||||
:disabled="repairing || offline"
|
||||
@click="repairProfile"
|
||||
>
|
||||
<HammerIcon /> Repair
|
||||
@@ -308,7 +313,7 @@
|
||||
<button
|
||||
id="repair-profile"
|
||||
class="btn btn-highlight"
|
||||
:disabled="repairing"
|
||||
:disabled="repairing || offline"
|
||||
@click="repairModpack"
|
||||
>
|
||||
<DownloadIcon /> Reinstall
|
||||
@@ -373,7 +378,7 @@ import { open } from '@tauri-apps/api/dialog'
|
||||
import { get_fabric_versions, get_forge_versions, get_quilt_versions } from '@/helpers/metadata.js'
|
||||
import { get_game_versions, get_loaders } from '@/helpers/tags.js'
|
||||
import { handleError } from '@/store/notifications.js'
|
||||
import mixpanel from 'mixpanel-browser'
|
||||
import { mixpanel_track } from '@/helpers/mixpanel'
|
||||
import { useTheming } from '@/store/theme.js'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -383,6 +388,10 @@ const props = defineProps({
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
offline: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
const themeStore = useTheming()
|
||||
@@ -403,7 +412,7 @@ const availableGroups = ref([
|
||||
async function resetIcon() {
|
||||
icon.value = null
|
||||
await edit_icon(props.instance.path, null).catch(handleError)
|
||||
mixpanel.track('InstanceRemoveIcon')
|
||||
mixpanel_track('InstanceRemoveIcon')
|
||||
}
|
||||
|
||||
async function setIcon() {
|
||||
@@ -422,7 +431,7 @@ async function setIcon() {
|
||||
icon.value = value
|
||||
await edit_icon(props.instance.path, icon.value).catch(handleError)
|
||||
|
||||
mixpanel.track('InstanceSetIcon')
|
||||
mixpanel_track('InstanceSetIcon')
|
||||
}
|
||||
|
||||
const globalSettings = await get().catch(handleError)
|
||||
@@ -536,7 +545,7 @@ async function repairProfile() {
|
||||
await install(props.instance.path).catch(handleError)
|
||||
repairing.value = false
|
||||
|
||||
mixpanel.track('InstanceRepair', {
|
||||
mixpanel_track('InstanceRepair', {
|
||||
loader: props.instance.metadata.loader,
|
||||
game_version: props.instance.metadata.game_version,
|
||||
})
|
||||
@@ -547,7 +556,7 @@ async function repairModpack() {
|
||||
await update_repair_modrinth(props.instance.path).catch(handleError)
|
||||
repairing.value = false
|
||||
|
||||
mixpanel.track('InstanceRepair', {
|
||||
mixpanel_track('InstanceRepair', {
|
||||
loader: props.instance.metadata.loader,
|
||||
game_version: props.instance.metadata.game_version,
|
||||
})
|
||||
@@ -559,7 +568,7 @@ async function removeProfile() {
|
||||
await remove(props.instance.path).catch(handleError)
|
||||
removing.value = false
|
||||
|
||||
mixpanel.track('InstanceRemove', {
|
||||
mixpanel_track('InstanceRemove', {
|
||||
loader: props.instance.metadata.loader,
|
||||
game_version: props.instance.metadata.game_version,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user