chore: only update server ping when not in launching state

This commit is contained in:
HorizonCode 2025-07-04 09:24:34 +02:00
parent 493d425ee7
commit 8c5e7ca6f2
2 changed files with 39 additions and 22 deletions

View File

@ -9,6 +9,8 @@ export const currentLoadingInfo = writable<string>('Initializing...');
export const firstStartup = writable<boolean>(false); export const firstStartup = writable<boolean>(false);
export const launching = writable<boolean>(false);
export const serverPing = writable<number | undefined>(undefined); export const serverPing = writable<number | undefined>(undefined);
export const serverConnectionFails = writable(0); export const serverConnectionFails = writable(0);
@ -20,20 +22,20 @@ export const skins = writable<number | undefined>(undefined);
export const osuStream = writable<string | undefined>(undefined); export const osuStream = writable<string | undefined>(undefined);
export const osuBuild = writable<string | undefined>(undefined); export const osuBuild = writable<string | undefined>(undefined);
let updateValues = true;
launching.subscribe((val) => (updateValues = !val));
export const setupValues = () => { export const setupValues = () => {
updatePing(); updatePing();
updateFriends();
updateBeatmapSets();
const pingUpdater = setInterval(updatePing, 5000 * 2); const pingUpdater = setInterval(updatePing, 5000 * 2);
const friendUpdater = setInterval(updateFriends, 5000 * 2);
return () => { return () => {
clearInterval(pingUpdater); clearInterval(pingUpdater);
clearInterval(friendUpdater);
}; };
}; };
const updatePing = async () => { const updatePing = async () => {
if (!updateValues) return;
const currentServerPing = await ezppfarm.ping(); const currentServerPing = await ezppfarm.ping();
if (!currentServerPing) { if (!currentServerPing) {
serverConnectionFails.update((num) => num + 1); serverConnectionFails.update((num) => num + 1);
@ -42,11 +44,3 @@ const updatePing = async () => {
serverPing.set(currentServerPing); 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 () => {};

View File

@ -7,6 +7,7 @@
import { import {
beatmapSets, beatmapSets,
currentView, currentView,
launching,
osuBuild, osuBuild,
osuStream, osuStream,
serverConnectionFails, serverConnectionFails,
@ -71,7 +72,6 @@
import { getCurrentWindow } from '@tauri-apps/api/window'; import { getCurrentWindow } from '@tauri-apps/api/window';
let selectedTab = $state('home'); let selectedTab = $state('home');
let launching = $state(false);
let launchInfo = $state(''); let launchInfo = $state('');
let selectedGamemode = $derived( let selectedGamemode = $derived(
@ -133,14 +133,14 @@
} }
const osuPath = $osuInstallationPath; const osuPath = $osuInstallationPath;
launchInfo = 'Validating osu! installation...'; launchInfo = 'Validating osu! installation...';
launching = true; launching.set(true);
const validFolder: boolean = await invoke('valid_osu_folder', { folder: osuPath }); const validFolder: boolean = await invoke('valid_osu_folder', { folder: osuPath });
if (!validFolder) { if (!validFolder) {
toast.error('Hmmm...', { toast.error('Hmmm...', {
description: 'Your selected osu! installation folder is not valid.', description: 'Your selected osu! installation folder is not valid.',
}); });
launching = false; launching.set(false);
return; return;
} }
@ -150,7 +150,7 @@
toast.error('Hmmm...', { toast.error('Hmmm...', {
description: 'Failed to check for updates.', description: 'Failed to check for updates.',
}); });
launching = false; launching.set(false);
return; return;
} }
@ -215,6 +215,29 @@
}, },
]); ]);
} }
} else {
await setUserConfigValues(osuPath, [
{
key: 'Username',
value: '',
},
{
key: 'Password',
value: '',
},
{
key: 'SaveUsername',
value: '1',
},
{
key: 'SavePassword',
value: '0',
},
{
key: 'CredentialEndpoint',
value: 'ez-pp.farm',
},
]);
} }
await new Promise((res) => setTimeout(res, 1500)); await new Promise((res) => setTimeout(res, 1500));
launchInfo = 'Launching osu!...'; launchInfo = 'Launching osu!...';
@ -243,22 +266,22 @@
}); });
if (skinCount) skins.set(skinCount); if (skinCount) skins.set(skinCount);
launching = false; launching.set(false);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
toast.error('Hmmm...', { toast.error('Hmmm...', {
description: 'Failed to launch.', description: 'Failed to launch.',
}); });
launching = false; launching.set(false);
} }
setTimeout(() => { setTimeout(() => {
launching = false; launching.set(false);
}, 5000); }, 5000);
}; };
</script> </script>
<AlertDialog.Root bind:open={launching}> <AlertDialog.Root bind:open={$launching}>
<AlertDialog.Content class="bg-theme-950 border-theme-800 p-0"> <AlertDialog.Content class="bg-theme-950 border-theme-800 p-0">
<div <div
class="flex flex-col items-center justify-center border-b border-theme-800 bg-black/40 rounded-t-lg p-3" class="flex flex-col items-center justify-center border-b border-theme-800 bg-black/40 rounded-t-lg p-3"
@ -643,7 +666,7 @@
</div> </div>
<Button <Button
size="lg" size="lg"
disabled={launching || $osuInstallationPath === ''} disabled={$launching || $osuInstallationPath === ''}
onclick={() => launch($serverConnectionFails > 1)} onclick={() => launch($serverConnectionFails > 1)}
> >
<Play /> <Play />
@ -662,7 +685,7 @@
<Gamepad2 class="text-muted-foreground" size="24" /> <Gamepad2 class="text-muted-foreground" size="24" />
<span class="font-semibold text-muted-foreground text-sm">Client Info</span> <span class="font-semibold text-muted-foreground text-sm">Client Info</span>
</div> </div>
<div class="grid grid-cols-[1fr_auto] gap-1 mt-2 border-t border-theme-800 pt-2 px-2 pb-2"> <div class="grid grid-cols-[1fr_auto] gap-1 mt-2 border-t border-theme-800 pt-2 px-2 pb-0">
<span class="text-sm text-muted-foreground font-semibold">osu! Release Stream</span> <span class="text-sm text-muted-foreground font-semibold">osu! Release Stream</span>
<span class="text-sm font-semibold text-end text-theme-50"> <span class="text-sm font-semibold text-end text-theme-50">
<Badge> <Badge>