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(), state: "Idle in Launcher...".to_string(),
details: " ".to_string(), details: " ".to_string(),
large_image_key: "ezppfarm".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_key: None,
small_image_text: None, small_image_text: None,
}) })

View File

@ -59,12 +59,12 @@ export const ezppfarm = {
} }
return request.data; 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`, { const request = await betterFetch<EZPPUserInfoResponse>(`${API_ENDPOINT}v1/get_player_info`, {
timeout, timeout,
query: { query: {
id: userId, id: userId,
scope: 'all', scope,
}, },
headers: { headers: {
'Content-Type': 'application/json', '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 connect = async () => await invoke('presence_connect');
export const disconnect = async () => await invoke('presence_disconnect'); export const disconnect = async () => await invoke('presence_disconnect');
export const updateStatus = async (status: { export const updateStatus = async (status: {
state?: string | null; state: string;
details?: string | null; details: string;
largeImageKey?: string; largeImageKey?: string;
}) => }) =>
await invoke('presence_update_status', { await invoke('presence_update_status', {
state: status.state, status: {
details: status.details, state: status.state,
largeImageKey: status.largeImageKey, details: status.details,
largeImageKey: status.largeImageKey,
},
}); });
export const updateUser = async (user: { username: string; id?: string | null }) => 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'); export const isConnected = async () => await invoke<boolean>('presence_is_connected');

View File

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