Skip to content

Commit

Permalink
Finish most of cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Jul 20, 2024
1 parent dd2f74f commit 11f1793
Show file tree
Hide file tree
Showing 34 changed files with 704 additions and 739 deletions.
20 changes: 11 additions & 9 deletions apps/app-frontend/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { computed, ref, watch, onMounted } from 'vue'
import { computed, ref, onMounted } from 'vue'
import { RouterView, RouterLink, useRouter, useRoute } from 'vue-router'
import {
HomeIcon,
Expand All @@ -21,11 +21,11 @@ import SplashScreen from '@/components/ui/SplashScreen.vue'
import ErrorModal from '@/components/ui/ErrorModal.vue'
import ModrinthLoadingIndicator from '@/components/modrinth-loading-indicator'
import { handleError, useNotifications } from '@/store/notifications.js'
import { offline_listener, 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 { type } from '@tauri-apps/api/os'
import { appWindow } from '@tauri-apps/api/window'
import { isDev, getOS, isOffline, showLauncherLogsFolder } from '@/helpers/utils.js'
import { isDev, getOS, showLauncherLogsFolder } from '@/helpers/utils.js'
import {
mixpanel_track,
mixpanel_init,
Expand All @@ -49,7 +49,14 @@ const themeStore = useTheming()
const urlModal = ref(null)
const isLoading = ref(true)
const offline = ref(false)
const offline = ref(!navigator.onLine)
window.addEventListener('offline', () => {
offline.value = true
})
window.addEventListener('online', () => {
offline.value = false
})
const showOnboarding = ref(false)
const nativeDecorations = ref(false)
Expand Down Expand Up @@ -96,11 +103,6 @@ defineExpose({
document.getElementsByTagName('html')[0].classList.add('windows')
}
offline.value = await isOffline()
await offline_listener((b) => {
offline.value = b
})
await warning_listener((e) =>
notificationsWrapper.value.addNotification({
title: 'Warning',
Expand Down
12 changes: 9 additions & 3 deletions apps/app-frontend/src/components/ui/ProjectCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ const toTransparent = computed(() => {
const install = async (e) => {
e?.stopPropagation()
installing.value = true
await installVersion(props.project.project_id, null, props.instance.path, 'ProjectCard', () => {
installing.value = false
})
await installVersion(
props.project.project_id,
null,
props.instance ? props.instance.path : null,
'ProjectCard',
() => {
installing.value = false
},
)
}
</script>
Expand Down
18 changes: 8 additions & 10 deletions apps/app-frontend/src/components/ui/RunningAppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</Button>
<div v-if="offline" class="status">
<span class="circle stopped" />
<div class="running-text clickable" @click="refreshInternet()">
<div class="running-text">
<span> Offline </span>
</div>
</div>
Expand Down Expand Up @@ -111,10 +111,9 @@ import {
kill_by_uuid as killProfile,
get_uuids_by_profile_path as getProfileProcesses,
} from '@/helpers/process'
import { loading_listener, process_listener, offline_listener } from '@/helpers/events'
import { loading_listener, process_listener } from '@/helpers/events'
import { useRouter } from 'vue-router'
import { progress_bars_list } from '@/helpers/state.js'
import { refreshOffline, isOffline } from '@/helpers/utils.js'
import ProgressBar from '@/components/ui/ProgressBar.vue'
import { handleError } from '@/store/notifications.js'
import { mixpanel_track } from '@/helpers/mixpanel'
Expand All @@ -132,12 +131,12 @@ const showProfiles = ref(false)
const currentProcesses = ref(await getRunningProfiles().catch(handleError))
const selectedProfile = ref(currentProcesses.value[0])
const offline = ref(await isOffline().catch(handleError))
const refreshInternet = async () => {
offline.value = await refreshOffline().catch(handleError)
}
const unlistenRefresh = await offline_listener(async (b) => {
offline.value = b
const offline = ref(!navigator.onLine)
window.addEventListener('offline', () => {
offline.value = true
})
window.addEventListener('online', () => {
offline.value = false
})
const unlistenProcess = await process_listener(async () => {
Expand Down Expand Up @@ -265,7 +264,6 @@ onBeforeUnmount(() => {
window.removeEventListener('click', handleClickOutsideProfile)
unlistenProcess()
unlistenLoading()
unlistenRefresh()
})
</script>
Expand Down
14 changes: 1 addition & 13 deletions apps/app-frontend/src/helpers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// event.payload is the payload object
console.log(event)
})
Putting that in a script will print any emitted signal from rust
*/
import { listen } from '@tauri-apps/api/event'
Expand Down Expand Up @@ -93,15 +93,3 @@ export async function command_listener(callback) {
export async function warning_listener(callback) {
return await listen('warning', (event) => callback(event.payload))
}

/// Payload for the 'offline' event
/*
OfflinePayload {
offline: bool, true or false
}
*/
export async function offline_listener(callback) {
return await listen('offline', (event) => {
return callback(event.payload)
})
}
8 changes: 8 additions & 0 deletions apps/app-frontend/src/helpers/jre.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ JavaVersion {
*/

export async function get_java_versions() {
return await invoke('plugin:jre|get_java_versions')
}

export async function set_java_version(version) {
return await invoke('plugin:jre|set_java_version', { version })
}

// Finds all the installation of Java 7, if it exists
// Returns [JavaVersion]
export async function find_filtered_jres(version) {
Expand Down
19 changes: 0 additions & 19 deletions apps/app-frontend/src/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,3 @@ export const releaseColor = (releaseType) => {
return ''
}
}

export const openLink = (url) => {
window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Shell',
message: {
cmd: 'open',
path: url,
},
})
}

export const refreshOffline = async () => {
return await invoke('plugin:utils|refresh_offline', {})
}

// returns true/false
export const isOffline = async () => {
return await invoke('plugin:utils|is_offline', {})
}
21 changes: 7 additions & 14 deletions apps/app-frontend/src/pages/Browse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,17 @@ import { useRoute, useRouter } from 'vue-router'
import SearchCard from '@/components/ui/SearchCard.vue'
import SplashScreen from '@/components/ui/SplashScreen.vue'
import { useFetch } from '@/helpers/fetch.js'
import {
check_installed,
get,
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 { isOffline } from '@/helpers/utils'
import { offline_listener } from '@/helpers/events'
const router = useRouter()
const route = useRoute()
const offline = ref(await isOffline())
const unlistenOffline = await offline_listener((b) => {
offline.value = b
const offline = ref(!navigator.onLine)
window.addEventListener('offline', () => {
offline.value = true
})
window.addEventListener('online', () => {
offline.value = false
})
const breadcrumbs = useBreadcrumbs()
Expand Down Expand Up @@ -527,8 +522,6 @@ const showLoaders = computed(
instanceContext.value === null) ||
ignoreInstanceLoaders.value,
)
onUnmounted(() => unlistenOffline())
</script>

<template>
Expand Down
19 changes: 8 additions & 11 deletions apps/app-frontend/src/pages/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { ref, onUnmounted, shallowRef, computed } from 'vue'
import { useRoute } from 'vue-router'
import RowDisplay from '@/components/RowDisplay.vue'
import { list } from '@/helpers/profile.js'
import { offline_listener, profile_listener } from '@/helpers/events'
import { profile_listener } from '@/helpers/events'
import { useBreadcrumbs } from '@/store/breadcrumbs'
import { useFetch } from '@/helpers/fetch.js'
import { handleError } from '@/store/notifications.js'
import dayjs from 'dayjs'
import { isOffline } from '@/helpers/utils'
const featuredModpacks = ref({})
const featuredMods = ref({})
Expand All @@ -21,7 +20,13 @@ breadcrumbs.setRootContext({ name: 'Home', link: route.path })
const recentInstances = shallowRef([])
const offline = ref(await isOffline())
const offline = ref(!navigator.onLine)
window.addEventListener('offline', () => {
offline.value = true
})
window.addEventListener('online', () => {
offline.value = false
})
const getInstances = async () => {
const profiles = await list(true).catch(handleError)
Expand Down Expand Up @@ -74,13 +79,6 @@ const unlistenProfile = await profile_listener(async (e) => {
}
})
const unlistenOffline = await offline_listener(async (b) => {
offline.value = b
if (!b) {
await Promise.all([getFeaturedModpacks(), getFeaturedMods()])
}
})
// computed sums of recentInstances, featuredModpacks, featuredMods, treating them as arrays if they are not
const total = computed(() => {
return (
Expand All @@ -92,7 +90,6 @@ const total = computed(() => {
onUnmounted(() => {
unlistenProfile()
unlistenOffline()
})
</script>
Expand Down
13 changes: 7 additions & 6 deletions apps/app-frontend/src/pages/Library.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import GridDisplay from '@/components/GridDisplay.vue'
import { list } from '@/helpers/profile.js'
import { useRoute } from 'vue-router'
import { useBreadcrumbs } from '@/store/breadcrumbs'
import { offline_listener, profile_listener } from '@/helpers/events.js'
import { profile_listener } from '@/helpers/events.js'
import { handleError } from '@/store/notifications.js'
import { Button } from '@modrinth/ui'
import { PlusIcon } from '@modrinth/assets'
import InstanceCreationModal from '@/components/ui/InstanceCreationModal.vue'
import { NewInstanceImage } from '@/assets/icons'
import { isOffline } from '@/helpers/utils'
const route = useRoute()
const breadcrumbs = useBreadcrumbs()
Expand All @@ -20,9 +19,12 @@ breadcrumbs.setRootContext({ name: 'Library', link: route.path })
const profiles = await list(true).catch(handleError)
const instances = shallowRef(Object.values(profiles))
const offline = ref(await isOffline())
const unlistenOffline = await offline_listener((b) => {
offline.value = b
const offline = ref(!navigator.onLine)
window.addEventListener('offline', () => {
offline.value = true
})
window.addEventListener('online', () => {
offline.value = false
})
const unlistenProfile = await profile_listener(async () => {
Expand All @@ -31,7 +33,6 @@ const unlistenProfile = await profile_listener(async () => {
})
onUnmounted(() => {
unlistenProfile()
unlistenOffline()
})
</script>

Expand Down
9 changes: 7 additions & 2 deletions apps/app-frontend/src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ const accessSettings = async () => {
const fetchSettings = await accessSettings().catch(handleError)
const settings = ref(fetchSettings)
console.log(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))
const maxMemory = ref(100000)
watch(
settings,
async (oldSettings, newSettings) => {
console.log('hellooo')
if (oldSettings.loaded_config_dir !== newSettings.loaded_config_dir) {
return
}
Expand Down Expand Up @@ -83,14 +85,17 @@ watch(
{ deep: true },
)
console.log('hellooo')
const credentials = ref(await getCreds().catch(handleError))
const loginScreenModal = ref()
console.log('hellooo')
async function logOut() {
await logout().catch(handleError)
credentials.value = await getCreds().catch(handleError)
}
console.log('hellooo')
async function signInAfter() {
loginScreenModal.value.hide()
credentials.value = await getCreds().catch(handleError)
Expand Down
19 changes: 10 additions & 9 deletions apps/app-frontend/src/pages/instance/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ import {
get_uuids_by_profile_path,
kill_by_uuid,
} from '@/helpers/process'
import { offline_listener, process_listener, profile_listener } from '@/helpers/events'
import { 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 { isOffline, showProfileInFolder } from '@/helpers/utils.js'
import { showProfileInFolder } from '@/helpers/utils.js'
import ContextMenu from '@/components/ui/ContextMenu.vue'
import { mixpanel_track } from '@/helpers/mixpanel'
import { convertFileSrc } from '@tauri-apps/api/tauri'
Expand All @@ -162,7 +162,13 @@ breadcrumbs.setContext({
query: route.query,
})
const offline = ref(await isOffline())
const offline = ref(!navigator.onLine)
window.addEventListener('offline', () => {
offline.value = true
})
window.addEventListener('online', () => {
offline.value = false
})
const loadingBar = useLoading()
Expand Down Expand Up @@ -197,7 +203,7 @@ const checkProcess = async () => {
// Get information on associated modrinth versions, if any
const modrinthVersions = ref([])
if (!(await isOffline()) && instance.value.linked_data && instance.value.linked_data.project_id) {
if (!offline.value && instance.value.linked_data && instance.value.linked_data.project_id) {
modrinthVersions.value = await useFetch(
`https://api.modrinth.com/v2/project/${instance.value.linked_data.project_id}/version`,
'project',
Expand Down Expand Up @@ -295,14 +301,9 @@ 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>

Expand Down
Loading

0 comments on commit 11f1793

Please sign in to comment.