fix(presence): keep rich presence synced with launcher state
Refresh idle activity from live mode, stats, user, and config changes, replace activity snapshots so cleared buttons and images are removed, and keep retrying Discord IPC until presence is disabled.
This commit is contained in:
1 parent
e1c04c4f5b
commit
34e93ee29b
7 files changed
+137
-125
No files matched your search
@@ -12,13 +12,11 @@
|
||||
DISCORD_PRESENCE_PRESETS,
|
||||
interpolatePresenceString,
|
||||
loadDiscordPresenceConfig,
|
||||
pushIdlePresenceFromConfig,
|
||||
saveDiscordPresenceConfig,
|
||||
type DiscordPresenceConfig,
|
||||
type PresenceVariableContext,
|
||||
} from '$lib/discordPresenceConfig';
|
||||
import { discordPresence, launcherVersion } from '$lib/global';
|
||||
import * as presence from '$lib/presence';
|
||||
import { currentUser } from '$lib/userAuthentication';
|
||||
import {
|
||||
Check,
|
||||
@@ -206,10 +204,14 @@
|
||||
user?: Parameters<typeof currentUser.set>[0];
|
||||
info?: Parameters<typeof currentUserInfo.set>[0];
|
||||
launcherVersion?: string;
|
||||
discordPresence?: boolean;
|
||||
}>('sync-theme-editor-global-data', (event) => {
|
||||
if (event.payload?.user) currentUser.set(event.payload.user);
|
||||
if (event.payload?.info) currentUserInfo.set(event.payload.info);
|
||||
if (event.payload?.launcherVersion) launcherVersion.set(event.payload.launcherVersion);
|
||||
if (typeof event.payload?.discordPresence === 'boolean') {
|
||||
discordPresence.set(event.payload.discordPresence);
|
||||
}
|
||||
});
|
||||
await emit('request-theme-editor-global-data');
|
||||
} catch (err) {
|
||||
@@ -469,18 +471,9 @@
|
||||
try {
|
||||
await saveDiscordPresenceConfig(workingConfig);
|
||||
initialConfigJson = JSON.stringify(workingConfig);
|
||||
if ($discordPresence && (await presence.isConnected())) {
|
||||
await pushIdlePresenceFromConfig(
|
||||
{
|
||||
user: $currentUser,
|
||||
version: $launcherVersion || undefined,
|
||||
rank: simRank,
|
||||
pp: simPp,
|
||||
accuracy: simAccuracy,
|
||||
},
|
||||
workingConfig
|
||||
);
|
||||
}
|
||||
// The main window owns the live player stats and its presence config
|
||||
// store, so let it refresh and push the updated activity immediately.
|
||||
await emit('discord-presence-config-saved');
|
||||
sileo.success({ title: 'Discord Rich Presence Saved', description: 'Activity updated' });
|
||||
await handleClose();
|
||||
} catch (err) {
|
||||
|
||||
@@ -247,6 +247,8 @@ export type IdlePresenceParams = {
|
||||
rank?: number | string;
|
||||
pp?: number | string;
|
||||
accuracy?: number | string;
|
||||
mode?: string;
|
||||
action?: string;
|
||||
};
|
||||
|
||||
export type PlayingPresenceParams = {
|
||||
@@ -282,6 +284,8 @@ export const pushIdlePresenceFromConfig = async (
|
||||
rank: params?.rank,
|
||||
pp: params?.pp,
|
||||
accuracy: params?.accuracy,
|
||||
mode: params?.mode,
|
||||
action: params?.action ?? 'In Launcher',
|
||||
version: params?.version,
|
||||
profileUrl: params?.user?.id ? `https://ez-pp.farm/u/${params.user.id}` : 'https://ez-pp.farm',
|
||||
};
|
||||
|
||||
+9
-9
@@ -6,15 +6,15 @@ export type PresenceButtonPayload = {
|
||||
};
|
||||
|
||||
export type PresenceActivityPayload = {
|
||||
state?: string;
|
||||
details?: string;
|
||||
largeImageKey?: string;
|
||||
largeImageText?: string;
|
||||
smallImageKey?: string | null;
|
||||
smallImageText?: string | null;
|
||||
button1?: PresenceButtonPayload | null;
|
||||
button2?: PresenceButtonPayload | null;
|
||||
showTimestamp?: boolean;
|
||||
state: string;
|
||||
details: string;
|
||||
largeImageKey: string;
|
||||
largeImageText: string;
|
||||
smallImageKey: string | null;
|
||||
smallImageText: string | null;
|
||||
button1: PresenceButtonPayload | null;
|
||||
button2: PresenceButtonPayload | null;
|
||||
showTimestamp: boolean;
|
||||
};
|
||||
|
||||
export const connect = async () => await invoke('presence_connect');
|
||||
|
||||
Reference in new issue
Block a user