Doesn't seem to update RPC, react-electron-boilerplate
daggy1234 opened this issue · comments
Why does discord-rpc not update when I change a var
For example
const Hello = () => {
const clientId = "675937742638809089";
const [title, setTite] = useState("Discord-Rpc-Controller");
const [ready, setReady] = useState(false);
DiscordRPC.register(clientId);
const rpc = new DiscordRPC.Client({ transport: "ipc" });
rpc.on("ready", () => {
setReady(true);
});
const instance = rpc.login({ clientId }).catch(console.error);
const setActivity = (text: string, startTimestamp: Date) => {
rpc.setActivity({
details: text,
state: "Testing State",
startTimestamp,
instance: false,
});
};
const Start = async () => {
const startTimestamp = new Date();
setActivity(title, startTimestamp);
console.log("k");
};
const Stop = async () => {
console.log("Stop");
rpc
.clearActivity()
.then((a) => console.log(a))
.catch(console.error);
};
return (
<div>
<div className="Hello">
<img width="200px" alt="icon" src={icon} />
</div>
<h1>Discord-Rpc_Controller</h1>
{ready && (
<>
<input
type="text"
value={title}
onChange={(event) => {
setTite(event.target.value);
}}
/>
<div className="Hello">
<button type="button" onClick={() => Start().then(console.log)}>
Start
</button>
<button type="button" onClick={() => Stop().then(console.log)}>
Stop
</button>
<button
type="button"
onClick={() => {
Stop().then(() => Start().then(console.log("Start and Stop")));
}}
>
Reset
</button>
</div>
</>
)}
</div>
);
};
Nothing Happens as shown below:
Another Similar Demo
const Hello = () => {
const clientId = "675937742638809089";
const [title, setTite] = useState("Discord-Rpc-Controller");
const [ready, setReady] = useState(false);
DiscordRPC.register(clientId);
const rpc = new DiscordRPC.Client({ transport: "ipc" });
const startTimestamp = new Date();
const setActivityA = () => {
console.log("what");
rpc.setActivity({
details: `Text: ${title}`,
state: "Testing State",
startTimestamp,
instance: false,
});
};
rpc.on("ready", () => {
setReady(true);
setActivityA();
setInterval(() => {
setActivityA();
}, 15e3);
});
const instance = rpc.login({ clientId }).catch(console.error);
return (
<div>
<div className="Hello">
<img width="200px" alt="icon" src={icon} />
</div>
<h1>Discord-Rpc_Controller</h1>
<input
type="text"
value={title}
onChange={(event) => {
setTite(event.target.value);
}}
/>
<div className="Hello">
</div>
</div>
);
};
Does not update as well,
For some reason the what
is consol.logged 11 times each 15 second inetrval but the RPC doesn't change.
Video of problem 2:
Can you provide a minimal reproduction? Ideally one without any UI.
Yup sure will do tmrw!
While making a min example, I realized the example worked.
I then replaced the react state with a basic number that updates with a counter and it worked fine.
It seems to be an issue with react state, every state update causes the RPC client to reinitialize leading to a lot of logs. Curious . WIll report soon