EZPPLauncher/src/lib/global.ts
HorizonCode 651592c333 feat: Refactor API interactions and enhance user settings management
- Updated ezpp API to include user info retrieval and improved error handling.
- Introduced new writable stores for current user info and loading states.
- Added gamemode enums and utility functions for better gamemode handling.
- Refactored global state management to use consistent naming conventions.
- Enhanced loading and login components to provide better user feedback.
- Updated user settings to include preferred mode and type.
- Improved layout and page components for better state management and user experience.
2025-07-03 11:46:50 +02:00

49 lines
1.4 KiB
TypeScript

import { writable } from 'svelte/store';
import { ezppfarm } from './api/ezpp';
import type { Component } from 'svelte';
import Loading from '../pages/Loading.svelte';
export const currentView = writable<Component>(Loading);
export const currentLoadingInfo = writable<string>('Initializing...');
export const firstStartup = writable<boolean>(false);
export const serverPing = writable<number | undefined>(undefined);
export const serverConnectionFails = writable(0);
export const onlineFriends = writable<number | undefined>(undefined);
export const beatmapSets = writable<number | undefined>(undefined);
export const setupValues = () => {
updatePing();
updateFriends();
updateBeatmapSets();
const pingUpdater = setInterval(updatePing, 5000 * 2);
const friendUpdater = setInterval(updateFriends, 5000 * 2);
return () => {
clearInterval(pingUpdater);
clearInterval(friendUpdater);
};
};
const updatePing = async () => {
const currentServerPing = await ezppfarm.ping();
if (!currentServerPing) {
serverConnectionFails.update((num) => num + 1);
} else {
serverConnectionFails.set(0);
serverPing.set(currentServerPing);
}
};
const updateFriends = async () => {
await new Promise((res) => setTimeout(res, Math.random() * 300));
const currentOnlineFriends = Math.round(Math.random() * 10);
onlineFriends.set(currentOnlineFriends);
};
const updateBeatmapSets = async () => {};