Attempt at repairing crash and failing to stop RPC

This commit is contained in:
Djkato 2022-04-10 00:17:27 +02:00
parent 49c20fd1f4
commit fd5fd330b5
6 changed files with 32 additions and 5 deletions

12
!ERROR.txt Normal file
View file

@ -0,0 +1,12 @@
(node:25384) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [RP]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
C:\Users\djkato\Documents\Discord Rich Presence for Cinema 4D\src\Rich Presence for C4D.js:46
str = str[1].split("]")
^
TypeError: Cannot read properties of undefined (reading 'split')
at updateOpenProjectName (C:\Users\djkato\Documents\Discord Rich Presence for Cinema 4D\src\Rich Presence for C4D.js:46:22)
at main (C:\Users\djkato\Documents\Discord Rich Presence for Cinema 4D\src\Rich Presence for C4D.js:98:9)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

1
.gitignore vendored
View file

@ -5,3 +5,4 @@ temp.txt
C4DRichPresence.bat C4DRichPresence.bat
build/DRCSettings.json build/DRCSettings.json
src/DRCSettings.json src/DRCSettings.json
!ERROR.txt

1
DRCSettings.json Normal file
View file

@ -0,0 +1 @@
{"portfolio_website":"djkato.net","scan_refresh_rate":1000}

View file

@ -1,6 +1,6 @@
{ {
"name": "discord-rich-presence-for-cinema-4d", "name": "discord-rich-presence-for-cinema-4d",
"version": "1.0.1", "version": "1.0.2",
"description": "A simple node project to show your friends on discord what you're working on in Cinema 4D! Bit hacky but it works x)", "description": "A simple node project to show your friends on discord what you're working on in Cinema 4D! Bit hacky but it works x)",
"bin": "./src/Rich Presence for C4D.js", "bin": "./src/Rich Presence for C4D.js",
"main": "./src/Rich Presence for C4D.js", "main": "./src/Rich Presence for C4D.js",

View file

@ -35,6 +35,7 @@ function getCinemaProcessInfo() {
} }
function updateOpenProjectName(str) { function updateOpenProjectName(str) {
//if project file found sets current project to name, else currentProject = false
if (str.includes("No tasks")) { if (str.includes("No tasks")) {
currentProject = false currentProject = false
return return
@ -42,6 +43,8 @@ function updateOpenProjectName(str) {
str = str.split("Window Title:") str = str.split("Window Title:")
if (str[1].includes("Cinema 4D")) { if (str[1].includes("Cinema 4D")) {
str = str[1].split("[") str = str[1].split("[")
//If for some reason the name isnt right?
if (!str[1]) return
str = str[1].split("]") str = str[1].split("]")
if (str[0].includes("*")) { if (str[0].includes("*")) {
str = str[0].substring(0, str[0].length - 2) str = str[0].substring(0, str[0].length - 2)
@ -60,13 +63,23 @@ function setDRCProject() {
//reconnects the client if isnt connected //reconnects the client if isnt connected
if (!clientIsConnected) { if (!clientIsConnected) {
currentClient = client("936296341250904065") currentClient = client("936296341250904065")
currentClient.on("error", (err) => {
//console.log("err")
})
clientIsConnected = true clientIsConnected = true
//console.log("starting client") //console.log("starting client")
currentProject = "0" currentProject = "0"
} }
currentClient.on("error", (err) => {
//if errored and shouldnt have, reconnect
if (clientIsConnected && currentProject) {
currentClient = client("936296341250904065")
console.log("errored and reconnecting")
} else {
clientIsConnected = false, currentProject = false
console.log("errored and keeping off")
}
})
if (currentProject != pastProject) { if (currentProject != pastProject) {
currentClient.updatePresence({ currentClient.updatePresence({
state: `Porfolio: ${DRCSettings.portfolio_website}`, state: `Porfolio: ${DRCSettings.portfolio_website}`,
@ -85,7 +98,7 @@ function setDRCProject() {
async function main() { async function main() {
while (true) { while (true) {
updateOpenProjectName(await getCinemaProcessInfo()) updateOpenProjectName(await getCinemaProcessInfo())
//stops DRC when broken //stops DRC when no project detected
if (currentProject == false) { if (currentProject == false) {
if (clientIsConnected) { if (clientIsConnected) {
await currentClient.disconnect() await currentClient.disconnect()