fix(rpc): clear Discord presence properly when launcher closes

This commit is contained in:
Joao Pedro 2026-08-10 22:14:25 -03:00
parent d536a6590b
commit 436ae2ce48
2 changed files with 21 additions and 3 deletions

View file

@ -7,6 +7,7 @@ import { useSkinSync } from "../hooks/useSkinSync";
import { useDiscordRPC } from "../hooks/useDiscordRPC";
import { useGamepad } from "../hooks/useGamepad";
import { useUpdateCheck } from "../hooks/useUpdateCheck";
import RpcService from "../services/RpcService";
interface UIContextType {
activeView: string;
@ -161,8 +162,12 @@ export function LauncherProvider({ children }: { children: React.ReactNode }) {
const setupVisibilityDetection = async () => {
try {
const { listen } = await import("@tauri-apps/api/event");
const unlistenClose = await listen("tauri://close-requested", () => {
const unlistenClose = await listen("tauri://close-requested", async () => {
setIsWindowVisible(false);
if (config.rpcEnabled) {
// the launcher never
await RpcService.StopRPC();
}
});
const unlistenShow = await listen("tauri://window-shown", () => {
@ -190,7 +195,7 @@ export function LauncherProvider({ children }: { children: React.ReactNode }) {
};
setupVisibilityDetection();
}, []);
}, [config.rpcEnabled]);
const uiValue = useMemo(() => ({
activeView, setActiveView, showIntro, setShowIntro,

View file

@ -1,4 +1,4 @@
import { setActivity, start } from "tauri-plugin-drpc";
import { setActivity, start, clearActivity, stop } from "tauri-plugin-drpc";
import {
Activity,
ActivityType,
@ -72,6 +72,19 @@ class RPC {
console.error("Failed to set RPC activity:", e);
}
}
public async StopRPC() {
try {
await clearActivity();
await stop();
} catch (e) {
// no need to handle errors here as the launcher will close anyways!
} finally {
this.initialized = false;
this.initializationPromise = null;
sessionStorage.removeItem("lce_rpc_started");
}
}
}
export default new RPC();