From ab25bf16b2b08bf7ad74a679e55ea220d59f3fd7 Mon Sep 17 00:00:00 2001 From: Marie <8841466+Mar0xy@users.noreply.github.com> Date: Mon, 19 Apr 2021 20:43:25 +0200 Subject: [PATCH] Add Discord RPC & fix artist in mediainfo (#40) --- package.json | 1 + src/constants/settings.js | 1 + src/main.js | 10 +++++- src/pages/settings/preload.js | 3 ++ src/pages/settings/settings.html | 10 ++++++ src/preload.js | 6 +++- src/scripts/discord.js | 52 ++++++++++++++++++++++++++++++++ src/scripts/mediaInfo.js | 2 ++ src/scripts/settings.js | 1 + 9 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/scripts/discord.js diff --git a/package.json b/package.json index f3a18b8..d0bf445 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "homepage": "https://github.com/Mastermindzh/tidal-hifi", "license": "MIT", "dependencies": { + "discord-rpc": "^3.2.0", "electron-store": "^5.1.1", "express": "^4.17.1", "hotkeys-js": "^3.7.6", diff --git a/src/constants/settings.js b/src/constants/settings.js index 593e9f8..f8ec0f0 100644 --- a/src/constants/settings.js +++ b/src/constants/settings.js @@ -20,6 +20,7 @@ const settings = { mpris: "mpris", enableCustomHotkeys: "enableCustomHotkeys", trayIcon: "trayIcon", + enableDiscord: "enableDiscord", windowBounds: { root: "windowBounds", width: "windowBounds.width", diff --git a/src/main.js b/src/main.js index 686844c..28ca3c7 100644 --- a/src/main.js +++ b/src/main.js @@ -9,14 +9,15 @@ const { } = require("./scripts/settings"); const { addTray, refreshTray } = require("./scripts/tray"); const { addMenu } = require("./scripts/menu"); - const path = require("path"); const tidalUrl = "https://listen.tidal.com"; const expressModule = require("./scripts/express"); const mediaKeys = require("./constants/mediaKeys"); const mediaInfoModule = require("./scripts/mediaInfo"); +const discordModule = require("./scripts/discord"); const globalEvents = require("./constants/globalEvents"); + let mainWindow; let icon = path.join(__dirname, "../assets/icon.png"); @@ -85,6 +86,7 @@ app.on("ready", () => { addGlobalShortcuts(); store.get(settings.trayIcon) && addTray({ icon }) && refreshTray(); store.get(settings.api) && expressModule.run(mainWindow); + store.get(settings.enableDiscord) && discordModule.initRPC(); }); app.on("activate", function () { @@ -113,6 +115,12 @@ ipcMain.on(globalEvents.updateStatus, (event, arg) => { }); ipcMain.on(globalEvents.storeChanged, (event, arg) => { mainWindow.setMenuBarVisibility(store.get(settings.menuBar)); + + if(store.get(settings.enableDiscord) && !discordModule.rpc) { + discordModule.initRPC(); + } else if(!store.get(settings.enableDiscord) && discordModule.rpc) { + discordModule.unRPC(); + } }); ipcMain.on(globalEvents.error, (event, arg) => { diff --git a/src/pages/settings/preload.js b/src/pages/settings/preload.js index 588e609..1a00065 100644 --- a/src/pages/settings/preload.js +++ b/src/pages/settings/preload.js @@ -20,6 +20,7 @@ function refreshSettings() { trayIcon.checked = store.get(settings.trayIcon); mpris.checked = store.get(settings.mpris); enableCustomHotkeys.checked = store.get(settings.enableCustomHotkeys); + enableDiscord.checked = store.get(settings.enableDiscord); } /** @@ -81,6 +82,7 @@ window.addEventListener("DOMContentLoaded", () => { trayIcon = get("trayIcon"); mpris = get("mprisCheckbox"); enableCustomHotkeys = get("enableCustomHotkeys"); + enableDiscord = get("enableDiscord"); refreshSettings(); @@ -92,4 +94,5 @@ window.addEventListener("DOMContentLoaded", () => { addInputListener(trayIcon, settings.trayIcon); addInputListener(mpris, settings.mpris); addInputListener(enableCustomHotkeys, settings.enableCustomHotkeys); + addInputListener(enableDiscord, settings.enableDiscord); }); diff --git a/src/pages/settings/settings.html b/src/pages/settings/settings.html index 6ff5252..124675a 100644 --- a/src/pages/settings/settings.html +++ b/src/pages/settings/settings.html @@ -141,6 +141,16 @@ +
+ Show what you're listening to on Discord +
+ +