diff --git a/package.json b/package.json index c3ade28..248ee94 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tidalRPC", - "version": "1.1.0", + "version": "1.2.0", "description": "Unofficial Discord Rich Presence for Tidal Desktop app.", "repository": { "type": "git", @@ -26,6 +26,7 @@ "node-window-manager": "2.2.3" }, "devDependencies": { + "@types/auto-launch": "^5.0.1", "@types/axios": "^0.14.0", "@types/debug": "^4.1.5", "@types/discord-rpc": "^3.0.5", diff --git a/src/app.ts b/src/app.ts index 9b56674..c215772 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,9 +1,9 @@ import debug from "debug"; import { app, dialog } from "electron"; +import { autoUpdater } from "electron-updater"; import { textSync } from "figlet"; import { askForScreenCaptureAccess, getAuthStatus } from "node-mac-permissions"; import { platform } from "os"; -import { autoUpdater } from "electron-updater"; import TidalManager from "@managers/tidal.manager"; @@ -23,7 +23,7 @@ export default class App { private _checkUpdates() { autoUpdater.checkForUpdatesAndNotify(); - autoUpdater.on("update-downloaded", info => { + autoUpdater.on("update-downloaded", () => { autoUpdater.quitAndInstall(); }); } diff --git a/src/classes/song.class.ts b/src/classes/song.class.ts index be712b9..a4fba94 100644 --- a/src/classes/song.class.ts +++ b/src/classes/song.class.ts @@ -1,6 +1,7 @@ export default class Song { title: string | undefined; artist: string | undefined; + album: { name: string; year: number } | undefined; startTime: number; duration: number; pausedTime: number; diff --git a/src/index.ts b/src/index.ts index 1bf4ade..2746387 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { platform } from "os"; import { destroyClient } from "@managers/discord.manager"; import TrayManager from "@managers/tray.manager"; +import { store } from "@util/config"; import App from "./app"; @@ -16,6 +17,15 @@ app.whenReady().then(async () => { trayManager = new TrayManager(); if (platform() === "darwin") app.dock.hide(); + if ( + app.isPackaged && + store.get("autoStart") && + !app.getLoginItemSettings().openAtLogin + ) + app.setLoginItemSettings({ + openAtLogin: true, + openAsHidden: true + }); const Application = new App(); Application.start(); diff --git a/src/managers/discord.manager.ts b/src/managers/discord.manager.ts index 352af79..6b712a1 100644 --- a/src/managers/discord.manager.ts +++ b/src/managers/discord.manager.ts @@ -86,7 +86,13 @@ export const setActivity = (data: Song) => { data.startTime + data.duration + data.pausedTime; presenceData.state = data.artist; - presenceData.details = data.title; + presenceData.details = + data.title + + `${ + data.album && store.get("showAlbum") + ? ` • ${data.album.name} (${data.album.year})` + : "" + }`; presenceData.smallImageKey = data.paused ? "pause" : "play"; presenceData.smallImageText = data.paused ? "Paused" : "Playing"; diff --git a/src/managers/tidal.manager.ts b/src/managers/tidal.manager.ts index 7affb9f..2da78ec 100644 --- a/src/managers/tidal.manager.ts +++ b/src/managers/tidal.manager.ts @@ -74,6 +74,10 @@ export default class TidalManager { this.currentSong.artist = await this.getAuthors(getInfo[0].artists); this.currentSong.title = getInfo[0].title; + this.currentSong.album = { + name: getAlbumInfo.title, + year: new Date(getAlbumInfo.releaseDate).getUTCFullYear() + }; this.currentSong.duration = getInfo[0].duration; this.currentSong.quality = getInfo[0].audioQuality; this.currentSong.startTime = 0; @@ -84,13 +88,13 @@ export default class TidalManager { if (getInfo[0].url) this.currentSong.buttons?.push({ - label: "Listen along!", + label: "Listen Along!", url: getInfo[0].url }); - if (getAlbumInfo) + if (getAlbumInfo.url) this.currentSong.buttons?.push({ - label: "View Album", + label: "Visit Album", url: getAlbumInfo.url }); @@ -107,6 +111,7 @@ export default class TidalManager { private _clearCurrentSong() { this.currentSong.title = undefined; this.currentSong.artist = undefined; + this.currentSong.album = undefined; this.currentSong.startTime = 0; this.currentSong.duration = 0; this.currentSong.pausedTime = 0; diff --git a/src/managers/tray.manager.ts b/src/managers/tray.manager.ts index ffdb90e..4f37a46 100644 --- a/src/managers/tray.manager.ts +++ b/src/managers/tray.manager.ts @@ -43,25 +43,43 @@ export default class TrayManager { label: "Show Rich Presence", type: "checkbox", checked: store.get("showPresence"), - click: () => { - store.set("showPresence", !store.get("showPresence")); - } + click: () => store.set("showPresence", !store.get("showPresence")) }, { label: "Show AppName in Rich Presence", type: "checkbox", checked: store.get("showAppName"), - click: () => { - store.set("showAppName", !store.get("showAppName")); - } + click: () => store.set("showAppName", !store.get("showAppName")) }, { - label: "Show Buttons in Rich Presence", + label: "Start at System Startup", type: "checkbox", - checked: store.get("showButtons"), + checked: store.get("autoStart"), + enabled: app.isPackaged ? true : false, click: () => { - store.set("showButtons", !store.get("showButtons")); + store.set("autoStart", !store.get("autoStart")); + store.get("autoStart") && app.isPackaged + ? app.setLoginItemSettings({ openAtLogin: true }) + : app.setLoginItemSettings({ openAtLogin: false }); } + }, + { + label: "Song", + submenu: [ + { + label: "Show Album with Year in Rich Presence", + type: "checkbox", + checked: store.get("showAlbum"), + click: () => store.set("showAlbum", !store.get("showAlbum")) + }, + { + label: "Show Buttons in Rich Presence", + type: "checkbox", + checked: store.get("showButtons"), + click: () => + store.set("showButtons", !store.get("showButtons")) + } + ] } ] }, @@ -96,25 +114,45 @@ export default class TrayManager { label: "Show Rich Presence", type: "checkbox", checked: store.get("showPresence"), - click: () => { - store.set("showPresence", !store.get("showPresence")); - } + click: () => store.set("showPresence", !store.get("showPresence")) }, { label: "Show AppName in Rich Presence", type: "checkbox", checked: store.get("showAppName"), - click: () => { - store.set("showAppName", !store.get("showAppName")); - } + click: () => store.set("showAppName", !store.get("showAppName")) }, { - label: "Show Buttons in Rich Presence", + label: "Start at System Startup", type: "checkbox", - checked: store.get("showButtons"), + checked: store.get("autoStart"), + enabled: app.isPackaged ? true : false, click: () => { - store.set("showButtons", !store.get("showButtons")); + store.set("autoStart", !store.get("autoStart")); + store.get("autoStart") && app.isPackaged + ? app.setLoginItemSettings({ + openAtLogin: true, + openAsHidden: true + }) + : app.setLoginItemSettings({ openAtLogin: false }); } + }, + { + label: "Song", + submenu: [ + { + label: "Show Album with Year in Rich Presence", + type: "checkbox", + checked: store.get("showAlbum"), + click: () => store.set("showAlbum", !store.get("showAlbum")) + }, + { + label: "Show Buttons in Rich Presence", + type: "checkbox", + checked: store.get("showButtons"), + click: () => store.set("showButtons", !store.get("showButtons")) + } + ] } ] }, diff --git a/src/util/config.ts b/src/util/config.ts index b2cfc1a..cede3da 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -4,12 +4,16 @@ interface configType { showPresence: boolean; showAppName: boolean; showButtons: boolean; + showAlbum: boolean; + autoStart: boolean; } export const store = new Store({ defaults: { showPresence: true, showAppName: true, - showButtons: true + showButtons: true, + showAlbum: true, + autoStart: true } }); diff --git a/yarn.lock b/yarn.lock index 93cb5d2..4ea903f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -143,6 +143,13 @@ __metadata: languageName: node linkType: hard +"@types/auto-launch@npm:^5.0.1": + version: 5.0.1 + resolution: "@types/auto-launch@npm:5.0.1" + checksum: 6b833513bf1cb3464477ef7efcf2ca3541527fe3ca704d3122f2099f1a0607a061ee038fc12ca2c8c536f9ae5e1476776492b3781624480c86bf8140c7ccdbd9 + languageName: node + linkType: hard + "@types/axios@npm:^0.14.0": version: 0.14.0 resolution: "@types/axios@npm:0.14.0" @@ -4686,6 +4693,7 @@ resolve@^1.20.0: version: 0.0.0-use.local resolution: "tidalRPC@workspace:." dependencies: + "@types/auto-launch": ^5.0.1 "@types/axios": ^0.14.0 "@types/debug": ^4.1.5 "@types/discord-rpc": ^3.0.5