diff --git a/apps/app-frontend/src/components/GridDisplay.vue b/apps/app-frontend/src/components/GridDisplay.vue index 58204dcbc..53921e745 100644 --- a/apps/app-frontend/src/components/GridDisplay.vue +++ b/apps/app-frontend/src/components/GridDisplay.vue @@ -120,9 +120,9 @@ const handleOptionsClick = async (args) => { } const search = ref('') -const group = ref('Category') -const filters = ref('All profiles') -const sortBy = ref('Name') +const group = defineModel('group') +const filters = defineModel('filters') +const sortBy = defineModel('sortBy') const filteredResults = computed(() => { let instances = props.instances.filter((instance) => { diff --git a/apps/app-frontend/src/composables/useSettings.js b/apps/app-frontend/src/composables/useSettings.js new file mode 100644 index 000000000..c10be10c4 --- /dev/null +++ b/apps/app-frontend/src/composables/useSettings.js @@ -0,0 +1,56 @@ +import { ref, watch } from 'vue' +import { get, set } from '@/helpers/settings.js' +import { optOutAnalytics, optInAnalytics } from '@/helpers/analytics' +import { handleError } from '@/store/state' + +export async function useSettings() { + const rawSettings = await get().catch(handleError) + + rawSettings.launchArgs = rawSettings.extra_launch_args.join(' ') + rawSettings.envVars = rawSettings.custom_env_vars.map((x) => x.join('=')).join(' ') + + const settings = ref(rawSettings) + + watch( + settings, + async (oldSettings, newSettings) => { + if (oldSettings.loaded_config_dir !== newSettings.loaded_config_dir) { + return + } + + const setSettings = JSON.parse(JSON.stringify(newSettings)) + + if (setSettings.telemetry) { + optOutAnalytics() + } else { + optInAnalytics() + } + + setSettings.extra_launch_args = setSettings.launchArgs.trim().split(/\s+/).filter(Boolean) + setSettings.custom_env_vars = setSettings.envVars + .trim() + .split(/\s+/) + .filter(Boolean) + .map((x) => x.split('=').filter(Boolean)) + + if (!setSettings.hooks.pre_launch) { + setSettings.hooks.pre_launch = null + } + if (!setSettings.hooks.wrapper) { + setSettings.hooks.wrapper = null + } + if (!setSettings.hooks.post_exit) { + setSettings.hooks.post_exit = null + } + + if (!setSettings.custom_dir) { + setSettings.custom_dir = null + } + + await set(setSettings) + }, + { deep: true }, + ) + + return settings +} diff --git a/apps/app-frontend/src/pages/Library.vue b/apps/app-frontend/src/pages/Library.vue index 147a711e6..62351e7a9 100644 --- a/apps/app-frontend/src/pages/Library.vue +++ b/apps/app-frontend/src/pages/Library.vue @@ -10,6 +10,7 @@ import { Button } from '@modrinth/ui' import { PlusIcon } from '@modrinth/assets' import InstanceCreationModal from '@/components/ui/InstanceCreationModal.vue' import { NewInstanceImage } from '@/assets/icons' +import { useSettings } from '@/composables/useSettings.js' import { hide_ads_window } from '@/helpers/ads.js' onMounted(() => { @@ -37,10 +38,19 @@ const unlistenProfile = await profile_listener(async () => { onUnmounted(() => { unlistenProfile() }) + +const settings = await useSettings()