Skip to content

Commit

Permalink
attempt to reconnect on rpc disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
oonqt committed Oct 1, 2019
1 parent c09496e commit 162c67b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require("fs");
const path = require("path");
const { app, BrowserWindow, ipcMain, Tray, Menu, shell, dialog } = require("electron");
const startup = require("./utils/startupHandler");
const Startup = require("./utils/startupHandler");
const request = require("request");
const DiscordRPC = require("discord-rpc");
const Logger = require("./utils/logger");
Expand All @@ -13,7 +13,7 @@ let rpc;

const logger = new Logger((process.defaultApp ? "console" : "file"), app.getPath("userData"));

const startupHandler = new startup(app);
const startupHandler = new Startup(app);

const clientId = "609837785049726977";

Expand Down Expand Up @@ -112,8 +112,15 @@ function rpcConnect() {
setTimeout(rpcConnect, 15000);
});
}

rpc.transport.once("close", () => {
clearInterval(statusUpdate);
rpcConnect();
logger.log("Disconnected from discord. Attemping to reconnect");
});
}


function toggleStartup() {
if(startupHandler.isEnabled) {
startupHandler.disable();
Expand Down Expand Up @@ -198,8 +205,6 @@ async function setStatus() {

let session = body.filter(session => session.UserName === data.username && session.DeviceName !== "Discord RPC" && session.NowPlayingItem)[0];

console.log(session);

if(session) {
switch(session.NowPlayingItem.Type) {
case "Episode":
Expand Down

0 comments on commit 162c67b

Please sign in to comment.