feat: add current mode rank to small image

This commit is contained in:
HorizonCode 2025-07-08 17:45:08 +02:00
parent d6623891bb
commit 376ee1e648
4 changed files with 50 additions and 36 deletions

View File

@ -170,7 +170,7 @@ pub static PRESENCE_DATA: Lazy<StdMutex<PresenceData>> = Lazy::new(|| {
state: "Idle in Launcher...".to_string(),
details: " ".to_string(),
large_image_key: "ezppfarm".to_string(),
large_image_text: "EZPPFarm v1.0.0".to_string(),
large_image_text: "EZPPFarm".to_string(),
small_image_key: None,
small_image_text: None,
})

View File

@ -59,12 +59,12 @@ export const ezppfarm = {
}
return request.data;
},
getUserInfo: async (userId: number) => {
getUserInfo: async (userId: number, scope: 'all' | 'info' | 'stats' = 'all') => {
const request = await betterFetch<EZPPUserInfoResponse>(`${API_ENDPOINT}v1/get_player_info`, {
timeout,
query: {
id: userId,
scope: 'all',
scope,
},
headers: {
'Content-Type': 'application/json',

View File

@ -3,15 +3,17 @@ import { invoke } from '@tauri-apps/api/core';
export const connect = async () => await invoke('presence_connect');
export const disconnect = async () => await invoke('presence_disconnect');
export const updateStatus = async (status: {
state?: string | null;
details?: string | null;
state: string;
details: string;
largeImageKey?: string;
}) =>
await invoke('presence_update_status', {
state: status.state,
details: status.details,
largeImageKey: status.largeImageKey,
status: {
state: status.state,
details: status.details,
largeImageKey: status.largeImageKey,
},
});
export const updateUser = async (user: { username: string; id?: string | null }) =>
await invoke('presence_update_user', { username: user.username, id: user.id });
await invoke('presence_update_user', { user: { username: user.username, id: user.id } });
export const isConnected = async () => await invoke<boolean>('presence_is_connected');

View File

@ -332,6 +332,7 @@
return;
}
if ($currentUser) {
const userStats = await ezppfarm.getUserInfo($currentUser.id, 'stats');
const userStatus = await ezppfarm.getUserStatus($currentUser.id);
if (userStatus?.player_status.online) {
let largeImageKey = 'ezppfarm';
@ -394,42 +395,53 @@
}
details = `[${gamemodeName}] ${details}`;
try {
const currentModeStats =
userStats?.player.stats[userStatus.player_status.status.mode];
let username = $currentUser.name;
await Promise.all([
presence.updateUser({
username: $currentUser.name,
id: $currentUser.id.toFixed(),
}),
presence.updateStatus({
details,
state,
largeImageKey,
}),
]);
if (currentModeStats && currentModeStats.rank > 0)
username + ` (#${currentModeStats.rank})`;
await Promise.all([
presence.updateUser({
username,
id: $currentUser.id.toFixed(),
}),
presence.updateStatus({
details,
state,
largeImageKey,
}),
]);
} catch {}
}
}
}, 1000 * 5);
}, 1000 * 2);
}
await runOsu(osuPath, true);
if (presenceUpdater) {
window.clearInterval(presenceUpdater);
await Promise.all([
presence.updateUser({
username: ' ',
id: null,
}),
presence.updateStatus({
details: null,
state: 'Idle in Launcher...',
largeImageKey: 'ezppfarm',
}),
]);
}
launchInfo = 'Cleaning up...';
await getCurrentWindow().show();
if (presenceUpdater) {
window.clearInterval(presenceUpdater);
console.log('clearing discord presence...');
try {
await Promise.all([
presence.updateUser({
username: ' ',
id: null,
}),
presence.updateStatus({
details: ' ',
state: 'Idle in Launcher...',
largeImageKey: 'ezppfarm',
}),
]);
} catch {}
console.log('discord presence cleared...');
}
await new Promise((res) => setTimeout(res, 1000));
await replaceUIFiles(osuPath, true);