Skip to content

Commit

Permalink
✨ New features!
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Apr 29, 2021
1 parent 5b691bd commit 4295e4d
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 26 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -23,7 +23,7 @@ export default class App {

private _checkUpdates() {
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on("update-downloaded", info => {
autoUpdater.on("update-downloaded", () => {
autoUpdater.quitAndInstall();
});
}
Expand Down
1 change: 1 addition & 0 deletions src/classes/song.class.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion src/managers/discord.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
11 changes: 8 additions & 3 deletions src/managers/tidal.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
});

Expand All @@ -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;
Expand Down
74 changes: 56 additions & 18 deletions src/managers/tray.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
]
}
]
},
Expand Down Expand Up @@ -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"))
}
]
}
]
},
Expand Down
6 changes: 5 additions & 1 deletion src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ interface configType {
showPresence: boolean;
showAppName: boolean;
showButtons: boolean;
showAlbum: boolean;
autoStart: boolean;
}

export const store = new Store<configType>({
defaults: {
showPresence: true,
showAppName: true,
showButtons: true
showButtons: true,
showAlbum: true,
autoStart: true
}
});
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4295e4d

Please sign in to comment.