mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-11-22 13:32:42 +01:00
add time left to discord rpc & duration, current to mediainfo
This commit is contained in:
parent
31d90a342c
commit
df887b8628
@ -1,21 +1,33 @@
|
||||
const discordrpc = require("discord-rpc");
|
||||
const { ipcMain } = require("electron");
|
||||
const electron = require("electron");
|
||||
const { app, ipcMain } = require("electron");
|
||||
const globalEvents = require("../constants/globalEvents");
|
||||
const clientId = "833617820704440341";
|
||||
const mediaInfoModule = require("./mediaInfo");
|
||||
const discordModule = [];
|
||||
|
||||
function timeToSeconds(timeArray) {
|
||||
let minutes = (timeArray[0] * 1);
|
||||
let seconds = (minutes * 60) + (timeArray[1] * 1);
|
||||
return seconds;
|
||||
}
|
||||
|
||||
let rpc;
|
||||
const observer = (event, arg) => {
|
||||
if (mediaInfoModule.mediaInfo.status == "paused" && rpc) {
|
||||
rpc.setActivity(idleStatus);
|
||||
} else if (rpc) {
|
||||
let csec = timeToSeconds(mediaInfoModule.mediaInfo.current.split(":"));
|
||||
let dsec = timeToSeconds(mediaInfoModule.mediaInfo.duration.split(":"));
|
||||
const date = new Date();
|
||||
let now = date.getTime() / 1000 | 0;
|
||||
let remaining = date.setSeconds(date.getSeconds() + (dsec - csec));
|
||||
rpc.setActivity({
|
||||
...idleStatus,
|
||||
...{
|
||||
details: `Listening to ${mediaInfoModule.mediaInfo.title}`,
|
||||
state: mediaInfoModule.mediaInfo.artist,
|
||||
startTimestamp: parseInt(now),
|
||||
endTimestamp: parseInt(remaining),
|
||||
buttons: [{ label: "Play on Tidal", url: mediaInfoModule.mediaInfo.url }],
|
||||
},
|
||||
});
|
||||
@ -25,7 +37,7 @@ const observer = (event, arg) => {
|
||||
const idleStatus = {
|
||||
details: `Browsing Tidal`,
|
||||
largeImageKey: "tidal-hifi-icon",
|
||||
largeImageText: `Tidal HiFi ${electron.app.getVersion()}`,
|
||||
largeImageText: `Tidal HiFi ${app.getVersion()}`,
|
||||
instance: false,
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,8 @@ const mediaInfo = {
|
||||
icon: "",
|
||||
status: statuses.paused,
|
||||
url: "",
|
||||
current: "",
|
||||
duration: ""
|
||||
};
|
||||
const mediaInfoModule = {
|
||||
mediaInfo,
|
||||
@ -20,6 +22,8 @@ mediaInfoModule.update = function (arg) {
|
||||
mediaInfo.icon = propOrDefault(arg.icon);
|
||||
mediaInfo.url = propOrDefault(arg.url);
|
||||
mediaInfo.status = propOrDefault(arg.status);
|
||||
mediaInfo.current = propOrDefault(arg.current);
|
||||
mediaInfo.duration = propOrDefault(arg.duration);
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user