mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-11-22 13:32:42 +01:00
Implemented the logic in the discord.ts file as mentioned in earlier commits
This commit is contained in:
parent
7c6d2df16a
commit
36a2367397
@ -1,4 +1,4 @@
|
|||||||
import { Client } from "discord-rpc";
|
import { Client, Presence } from "discord-rpc";
|
||||||
import { app, ipcMain } from "electron";
|
import { app, ipcMain } from "electron";
|
||||||
import { globalEvents } from "../constants/globalEvents";
|
import { globalEvents } from "../constants/globalEvents";
|
||||||
import { settings } from "../constants/settings";
|
import { settings } from "../constants/settings";
|
||||||
@ -18,58 +18,54 @@ function timeToSeconds(timeArray: string[]) {
|
|||||||
export let rpc: Client;
|
export let rpc: Client;
|
||||||
|
|
||||||
const observer = () => {
|
const observer = () => {
|
||||||
if (mediaInfo.status === MediaStatus.paused && rpc) {
|
if (rpc) {
|
||||||
rpc.setActivity(idleStatus);
|
rpc.setActivity(getActivity());
|
||||||
} else if (rpc) {
|
}
|
||||||
|
};
|
||||||
|
const getActivity = (): Presence | undefined => {
|
||||||
|
const presence: Presence | undefined = {
|
||||||
|
largeImageKey: "tidal-hifi-icon",
|
||||||
|
largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
||||||
|
instance: false,
|
||||||
|
};
|
||||||
|
if (mediaInfo.status === MediaStatus.paused) {
|
||||||
|
presence.details = settingsStore.get<string, string>(settings.discord.idleText) ?? "Browsing Tidal";
|
||||||
|
} else {
|
||||||
|
const showSong = settingsStore.get<string, boolean>(settings.discord.showSong) ?? false;
|
||||||
|
if (showSong) {
|
||||||
|
const includeTimestamps =
|
||||||
|
settingsStore.get<string, boolean>(settings.discord.includeTimestamps) ?? true;
|
||||||
|
|
||||||
|
if (includeTimestamps) {
|
||||||
const currentSeconds = timeToSeconds(mediaInfo.current.split(":"));
|
const currentSeconds = timeToSeconds(mediaInfo.current.split(":"));
|
||||||
const durationSeconds = timeToSeconds(mediaInfo.duration.split(":"));
|
const durationSeconds = timeToSeconds(mediaInfo.duration.split(":"));
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const now = (date.getTime() / 1000) | 0;
|
const now = (date.getTime() / 1000) | 0;
|
||||||
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
|
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
|
||||||
const detailsPrefix =
|
presence.startTimestamp = now;
|
||||||
settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
|
presence.endTimestamp = remaining;
|
||||||
const buttonText =
|
}
|
||||||
settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";
|
|
||||||
const includeTimestamps =
|
const detailsPrefix = settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
|
||||||
settingsStore.get<string, boolean>(settings.discord.includeTimestamps) ?? true;
|
const buttonText = settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";
|
||||||
|
|
||||||
let activity = {
|
|
||||||
...idleStatus,
|
|
||||||
...{
|
|
||||||
startTimestamp: includeTimestamps ? now : undefined,
|
|
||||||
endTimestamp: includeTimestamps ? remaining : undefined,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (mediaInfo.url) {
|
if (mediaInfo.url) {
|
||||||
activity = {
|
presence.details = `${detailsPrefix}${mediaInfo.title}`;
|
||||||
...activity,
|
presence.state = mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)";
|
||||||
...{
|
presence.largeImageKey = mediaInfo.image;
|
||||||
details: `${detailsPrefix}${mediaInfo.title}`,
|
if (mediaInfo.album) {
|
||||||
state: mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)",
|
presence.largeImageText = mediaInfo.album;
|
||||||
largeImageKey: mediaInfo.image,
|
}
|
||||||
largeImageText: mediaInfo.album ? mediaInfo.album : `${idleStatus.largeImageText}`,
|
presence.buttons = [{ label: buttonText, url: mediaInfo.url }];
|
||||||
buttons: [{ label: buttonText, url: mediaInfo.url }],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
activity = {
|
presence.details = `Watching ${mediaInfo.title}`;
|
||||||
...activity,
|
presence.state = mediaInfo.artists;
|
||||||
...{
|
|
||||||
details: `Watching ${mediaInfo.title}`,
|
|
||||||
state: mediaInfo.artists,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
rpc.setActivity(activity);
|
presence.details = settingsStore.get<string, string>(settings.discord.listeningText) ?? "Listening Tidal";
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
return presence;
|
||||||
const idleStatus = {
|
|
||||||
details: `Browsing Tidal`,
|
|
||||||
largeImageKey: "tidal-hifi-icon",
|
|
||||||
largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
|
||||||
instance: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,7 +76,7 @@ export const initRPC = () => {
|
|||||||
rpc.login({ clientId }).then(
|
rpc.login({ clientId }).then(
|
||||||
() => {
|
() => {
|
||||||
rpc.on("ready", () => {
|
rpc.on("ready", () => {
|
||||||
rpc.setActivity(idleStatus);
|
rpc.setActivity(getActivity());
|
||||||
});
|
});
|
||||||
ipcMain.on(globalEvents.updateInfo, observer);
|
ipcMain.on(globalEvents.updateInfo, observer);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user