mirror of
https://github.com/SrIzan10/lofi.git
synced 2026-06-06 00:56:53 +00:00
chore: use mobile atmospheres
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
function getVolumeValue(name: string) {
|
||||
return appState.activeAtmospheres[name] || 0;
|
||||
}
|
||||
console.log(appState.atmospheres)
|
||||
</script>
|
||||
|
||||
<DropdownMenu.Root>
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
import { state as appState } from '@/state.svelte';
|
||||
import { getGeneralData, getStationSongs } from '@/utils';
|
||||
import { onMount } from 'svelte';
|
||||
import { useIsMobile } from '@/isMobile.svelte';
|
||||
|
||||
// svelte-ignore non_reactive_update
|
||||
let audioElement: HTMLAudioElement;
|
||||
let isTransitioning = $state(false);
|
||||
let isMobile = useIsMobile();
|
||||
|
||||
function togglePlayback(play: boolean) {
|
||||
if (!audioElement) return;
|
||||
@@ -204,7 +206,7 @@
|
||||
|
||||
{#each Object.entries(appState.activeAtmospheres) as [name, volume]}
|
||||
<audio
|
||||
src={`https://chill1.b-cdn.net/audio/v4/desktop/${name}.mp3`}
|
||||
src={isMobile ? appState.atmospheres.find(atm => atm.name === name)?.urlMobile : appState.atmospheres.find(atm => atm.name === name)?.url}
|
||||
class="hidden"
|
||||
id={name}
|
||||
volume={volume}
|
||||
|
||||
20
src/lib/isMobile.svelte.ts
Normal file
20
src/lib/isMobile.svelte.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { readable } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
export function useIsMobile(mobileWidth = 768) {
|
||||
return readable(false, (set) => {
|
||||
if (!browser) return;
|
||||
|
||||
const checkIsMobile = () => {
|
||||
const isMobile = window.innerWidth < mobileWidth;
|
||||
set(isMobile);
|
||||
};
|
||||
|
||||
checkIsMobile();
|
||||
|
||||
window.addEventListener('resize', checkIsMobile);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', checkIsMobile);
|
||||
};
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user