Skip to content

Commit df4e2b4

Browse files
authored
fix(electron): discord rpc not initialising on start (#717)
1 parent de82067 commit df4e2b4

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

app/electron/src/helpers/discordRPC.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "@pomatez/shareables";
88

99
const clientId = "1416789071350730762";
10-
let rpc: RPC.Client | undefined;
10+
let rpcClient: RPC.Client | undefined;
1111
let currentActivity: RpcActivityData;
1212

1313
type RpcActivityType = "Idle" | "Focus" | "Break";
@@ -68,7 +68,9 @@ const presetActivities: Record<RpcActivityType, DiscordActivity> = {
6868
};
6969

7070
export function setActivity(data: RpcActivityData): void {
71-
if (!(rpc instanceof RPC.Client)) {
71+
console.log("Setting RPC Activity:", data, RPC);
72+
if (!(rpcClient instanceof RPC.Client)) {
73+
console.log("RPC Client not initialized.");
7274
return;
7375
}
7476

@@ -85,27 +87,28 @@ export function setActivity(data: RpcActivityData): void {
8587
data.end instanceof Date ? data.end.getTime() : undefined, //this is supposed to make it count down, but its not working
8688
};
8789

88-
rpc.setActivity(activity).catch(console.error);
90+
rpcClient.setActivity(activity).catch(console.error);
8991
}
9092

9193
export function initializeRPC(): void {
92-
if (rpc instanceof RPC.Client) {
94+
console.log("Initializing Discord RPC...", RPC.Client);
95+
if (rpcClient instanceof RPC.Client) {
9396
return;
9497
}
9598

96-
rpc = new RPC.Client({ transport: "ipc" });
99+
rpcClient = new RPC.Client({ transport: "ipc" });
97100

98-
rpc.login({ clientId }).catch(console.error);
101+
rpcClient.login({ clientId }).catch(console.error);
99102

100-
rpc.on("ready", () => {
103+
rpcClient.on("ready", () => {
101104
setActivity(currentActivity || { type: "Idle" });
102105
});
103106
}
104107

105108
export function uninitializeRPC(): void {
106-
if (rpc instanceof RPC.Client) {
107-
rpc.destroy().catch(console.error);
108-
rpc = undefined;
109+
if (rpcClient instanceof RPC.Client) {
110+
rpcClient.destroy().catch(console.error);
111+
rpcClient = undefined;
109112
}
110113
}
111114

app/electron/src/main.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,16 @@ if (!onlySingleInstance) {
304304
}
305305

306306
createMainWindow();
307-
debounce(async () => {
308-
try {
309-
if (win) {
310-
const data = await getFromStorage(win, "state");
311-
if (data.settings.enableRPC) {
312-
initializeRPC();
313-
}
307+
try {
308+
if (win) {
309+
const data = await getFromStorage(win, "state");
310+
if (data.settings.enableRPC) {
311+
initializeRPC();
314312
}
315-
} catch (error) {
316-
console.log(error);
317313
}
318-
});
314+
} catch (error) {
315+
console.log(error);
316+
}
319317

320318
if (onProduction) {
321319
if (win) {

0 commit comments

Comments
 (0)