Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(theseus): add snapPoints for memory sliders #1275

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/app-frontend/src/composables/useMemorySlider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ref, computed } from 'vue'
import { get_max_memory } from '@/helpers/jre.js'
import { handleError } from '@/store/notifications.js'

export default async function () {
const maxMemory = ref(Math.floor((await get_max_memory().catch(handleError)) / 1024))

const snapPoints = computed(() => {
let points = []
let memory = 2048

while (memory <= maxMemory.value) {
points.push(memory)
memory *= 2
}

return points
})

return { maxMemory, snapPoints }
}
6 changes: 4 additions & 2 deletions apps/app-frontend/src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { LogOutIcon, LogInIcon, BoxIcon, FolderSearchIcon, UpdatedIcon } from '@
import { Card, Slider, DropdownSelect, Toggle, Modal, Button } from '@modrinth/ui'
import { handleError, useTheming } from '@/store/state'
import { is_dir_writeable, change_config_dir, get, set } from '@/helpers/settings'
import { get_max_memory } from '@/helpers/jre'
import { get as getCreds, logout } from '@/helpers/mr_auth.js'
import JavaSelector from '@/components/ui/JavaSelector.vue'
import ModrinthLoginScreen from '@/components/ui/tutorial/ModrinthLoginScreen.vue'
import { mixpanel_opt_out_tracking, mixpanel_opt_in_tracking } from '@/helpers/mixpanel'
import { open } from '@tauri-apps/api/dialog'
import { getOS } from '@/helpers/utils.js'
import { getVersion } from '@tauri-apps/api/app'
import useMemorySlider from '@/composables/useMemorySlider.js'

const pageOptions = ['Home', 'Library']

Expand All @@ -32,7 +32,7 @@ const fetchSettings = await accessSettings().catch(handleError)

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, snapPoints } = await useMemorySlider()

watch(
settings,
Expand Down Expand Up @@ -414,6 +414,8 @@ async function refreshDir() {
:max="maxMemory"
:step="64"
unit="mb"
:snap-points="snapPoints"
:snap-range="512"
/>
</div>
</Card>
Expand Down
6 changes: 4 additions & 2 deletions apps/app-frontend/src/pages/instance/Options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@
:max="maxMemory"
:step="64"
unit="mb"
:snap-points="snapPoints"
snap-range="512"
/>
</div>
</Card>
Expand Down Expand Up @@ -548,7 +550,6 @@ import {
update_repair_modrinth,
} from '@/helpers/profile.js'
import { computed, readonly, ref, shallowRef, watch } from 'vue'
import { get_max_memory } from '@/helpers/jre.js'
import { get } from '@/helpers/settings.js'
import JavaSelector from '@/components/ui/JavaSelector.vue'
import { convertFileSrc } from '@tauri-apps/api/tauri'
Expand All @@ -565,6 +566,7 @@ import { mixpanel_track } from '@/helpers/mixpanel'
import { useTheming } from '@/store/theme.js'
import { useBreadcrumbs } from '@/store/breadcrumbs'
import ModpackVersionModal from '@/components/ui/ModpackVersionModal.vue'
import useMemorySlider from '@/composables/useMemorySlider.js'

const breadcrumbs = useBreadcrumbs()

Expand Down Expand Up @@ -650,7 +652,7 @@ const envVars = ref(

const overrideMemorySettings = ref(!!props.instance.memory)
const memory = ref(props.instance.memory ?? globalSettings.memory)
const maxMemory = Math.floor((await get_max_memory().catch(handleError)) / 1024)
const { maxMemory, snapPoints } = await useMemorySlider()

const overrideWindowSettings = ref(!!props.instance.resolution || !!props.instance.fullscreen)
const resolution = ref(props.instance.resolution ?? globalSettings.game_resolution)
Expand Down