chore: add dynamic button for beatmap display
This commit is contained in:
1 parent
bde922ab9f
commit
d2ae9e939f
3 files changed
+26
No files matched your search
@@ -867,6 +867,21 @@ pub async fn presence_update_user(user: PresenceUser) {
|
|||||||
presence::update_user(user.username.as_deref(), user.id.as_deref());
|
presence::update_user(user.username.as_deref(), user.id.as_deref());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct PresenceButton {
|
||||||
|
text: Option<String>,
|
||||||
|
url: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn presence_update_button(button: PresenceButton) {
|
||||||
|
match (button.text.as_deref(), button.url.as_deref()) {
|
||||||
|
(Some(text), Some(url)) => presence::set_button(text, url),
|
||||||
|
_ => presence::clear_button(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn presence_is_connected() -> bool {
|
pub async fn presence_is_connected() -> bool {
|
||||||
presence::has_presence().await
|
presence::has_presence().await
|
||||||
|
|||||||
@@ -16,4 +16,6 @@ export const updateStatus = async (status: {
|
|||||||
});
|
});
|
||||||
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', { user: { username: user.username, id: user.id } });
|
await invoke('presence_update_user', { user: { username: user.username, id: user.id } });
|
||||||
|
export const updateButton = async (button: { text?: string; url?: string }) =>
|
||||||
|
await invoke('presence_update_button', { button: button });
|
||||||
export const isConnected = async () => await invoke<boolean>('presence_is_connected');
|
export const isConnected = async () => await invoke<boolean>('presence_is_connected');
|
||||||
@@ -524,6 +524,10 @@
|
|||||||
if (userStatus?.player_status.online) {
|
if (userStatus?.player_status.online) {
|
||||||
let largeImageKey = 'ezppfarm';
|
let largeImageKey = 'ezppfarm';
|
||||||
let details = 'Idle...';
|
let details = 'Idle...';
|
||||||
|
let customButton: { text?: string; url?: string } = {
|
||||||
|
text: undefined,
|
||||||
|
url: undefined,
|
||||||
|
};
|
||||||
let state =
|
let state =
|
||||||
userStatus.player_status.status.info_text.length > 0
|
userStatus.player_status.status.info_text.length > 0
|
||||||
? userStatus.player_status.status.info_text
|
? userStatus.player_status.status.info_text
|
||||||
@@ -579,6 +583,10 @@
|
|||||||
const beatmapCoverImage = `https://assets.ppy.sh/beatmaps/${userStatus.player_status.status.beatmap.set_id}/covers/[email protected]`;
|
const beatmapCoverImage = `https://assets.ppy.sh/beatmaps/${userStatus.player_status.status.beatmap.set_id}/covers/[email protected]`;
|
||||||
const isValidImage = await urlIsValidImage(beatmapCoverImage);
|
const isValidImage = await urlIsValidImage(beatmapCoverImage);
|
||||||
if (isValidImage) largeImageKey = beatmapCoverImage;
|
if (isValidImage) largeImageKey = beatmapCoverImage;
|
||||||
|
customButton = {
|
||||||
|
text: 'View Beatmap',
|
||||||
|
url: `https://ez-pp.farm/beatmapsets/${userStatus.player_status.status.beatmap.set_id}/${userStatus.player_status.status.beatmap.id}`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
details = `[${gamemodeName}] ${details}`;
|
details = `[${gamemodeName}] ${details}`;
|
||||||
@@ -591,6 +599,7 @@
|
|||||||
username += ` (#${currentModeStats.rank})`;
|
username += ` (#${currentModeStats.rank})`;
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
|
presence.updateButton(customButton),
|
||||||
presence.updateUser({
|
presence.updateUser({
|
||||||
username,
|
username,
|
||||||
id: $currentUser.id.toFixed(),
|
id: $currentUser.id.toFixed(),
|
||||||
|
|||||||
Reference in new issue
Block a user