diff --git a/environments/core/extensions/PresenceHandler.js b/environments/core/extensions/PresenceHandler.js index d47b6b6..b6b5362 100644 --- a/environments/core/extensions/PresenceHandler.js +++ b/environments/core/extensions/PresenceHandler.js @@ -6,16 +6,17 @@ const RPC = require("../rpc/RPC"); */ module.exports = (mainWindow) => { ipcMain.on("setActivity", async (ev, name) => { - console.log("Activity Call"); if (!RPC.ready) await RPC.login(); - RPC.setActivity(name); + if (RPC.ready) RPC.setActivity(name); }); ipcMain.on("destroyRPC", (ev) => { - RPC.logout(); + if (RPC.ready) RPC.logout(); }); - ipcMain.on("reconnectRPC", (ev) => { - RPC.login(); + ipcMain.on("reconnectRPC", async (ev) => { + if (RPC.ready) return; + const success = await RPC.login(); + if (success) RPC.setActivity(); }); }; diff --git a/environments/core/rpc/RPC.js b/environments/core/rpc/RPC.js index bdf5eb8..3becaab 100644 --- a/environments/core/rpc/RPC.js +++ b/environments/core/rpc/RPC.js @@ -17,7 +17,7 @@ class RichPresence { login() { console.log("Enabled?", this.enabled()); - if (this.enabled()) return Promise.resolve(false); + if (!this.enabled()) return Promise.resolve(false); return new Promise((resolve) => { this.client.on("ready", () => { @@ -29,7 +29,10 @@ class RichPresence { .login({ clientId: this.id }) - .catch(() => resolve(false)); + .catch((e) => { + console.error(e); + resolve(false); + }); }); } @@ -37,21 +40,21 @@ class RichPresence { this.client .setActivity({ details: title || "Scratch For Discord", - timestamps: { - start: this.startedAt - }, - assets: { - large_image: "large", - large_text: `Scratch For Discord - v${packageMeta.version}` - }, + startTimestamp: this.startedAt, buttons: [ { label: "Download", url: "https://androz2091.github.io/scratch-for-discord/download/index.html" } - ] + ], + largeImageKey: "large", + largeImageText: `Scratch For Discord - v${packageMeta.version}`, + smallImageKey: "small", + smallImageText: "Scratch For Discord" }) - .catch(() => {}); + .catch((e) => { + console.error(e); + }); } logout() { @@ -59,7 +62,9 @@ class RichPresence { () => { this.ready = false; }, - () => {} + (e) => { + console.error(e); + } ); } } diff --git a/environments/main.js b/environments/main.js index 6455b10..0dd0d99 100644 --- a/environments/main.js +++ b/environments/main.js @@ -3,6 +3,7 @@ const isDev = require("electron-is-dev"); const path = require("path"); const Updater = require("./updates/window"); const updater = new Updater(); +const rpc = require("./core/rpc/RPC"); require("./core/storage/database"); const S4D_PROTOCOL = "s4d"; let tray = null, @@ -90,8 +91,7 @@ async function createWindow() { if (mainWindow.maximizable) mainWindow.maximize(); // load extensions new (require("./core/ExtensionsLoader"))(mainWindow); - const rpc = require("./core/rpc/RPC"); - rpc.login().then(() => rpc.setActivity()); + rpc.login().then((success) => (success ? rpc.setActivity() : console.log("Could not start RPC"))); }); mainWindow.webContents.setWindowOpenHandler((handler) => { diff --git a/package.json b/package.json index 5e8d4e2..87e0ade 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scratch-for-discord", - "version": "2.0.0-dev.10", + "version": "2.0.0-dev.11", "private": true, "main": "environments/main.js", "description": "Build your own discord bot with scratch blocks.", @@ -33,6 +33,7 @@ "@fortawesome/free-solid-svg-icons": "^5.15.4", "@fortawesome/react-fontawesome": "^0.1.15", "@tailwindcss/forms": "^0.3.3", + "@types/discord-rpc": "^4.0.0", "@types/http-server": "^0.12.1", "@types/react": "^17.0.17", "@types/react-router-dom": "^5.1.8", diff --git a/src/components/ExtensionStore/ExtensionStore.jsx b/src/components/ExtensionStore/ExtensionStore.jsx index c102e78..1c9e62f 100644 --- a/src/components/ExtensionStore/ExtensionStore.jsx +++ b/src/components/ExtensionStore/ExtensionStore.jsx @@ -1,4 +1,10 @@ +import { useEffect } from "react"; + export default function ExtensionStore() { + useEffect(() => { + window.ScratchNative?.sendMessage("setActivity", "on S4D Store"); + }, []); + return (