mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-11-22 21:42:46 +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 discordrpc = require("discord-rpc");
|
||||||
const { ipcMain } = require("electron");
|
const { app, ipcMain } = require("electron");
|
||||||
const electron = require("electron");
|
|
||||||
const globalEvents = require("../constants/globalEvents");
|
const globalEvents = require("../constants/globalEvents");
|
||||||
const clientId = "833617820704440341";
|
const clientId = "833617820704440341";
|
||||||
const mediaInfoModule = require("./mediaInfo");
|
const mediaInfoModule = require("./mediaInfo");
|
||||||
const discordModule = [];
|
const discordModule = [];
|
||||||
|
|
||||||
|
function timeToSeconds(timeArray) {
|
||||||
|
let minutes = (timeArray[0] * 1);
|
||||||
|
let seconds = (minutes * 60) + (timeArray[1] * 1);
|
||||||
|
return seconds;
|
||||||
|
}
|
||||||
|
|
||||||
let rpc;
|
let rpc;
|
||||||
const observer = (event, arg) => {
|
const observer = (event, arg) => {
|
||||||
if (mediaInfoModule.mediaInfo.status == "paused" && rpc) {
|
if (mediaInfoModule.mediaInfo.status == "paused" && rpc) {
|
||||||
rpc.setActivity(idleStatus);
|
rpc.setActivity(idleStatus);
|
||||||
} else if (rpc) {
|
} 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({
|
rpc.setActivity({
|
||||||
...idleStatus,
|
...idleStatus,
|
||||||
...{
|
...{
|
||||||
details: `Listening to ${mediaInfoModule.mediaInfo.title}`,
|
details: `Listening to ${mediaInfoModule.mediaInfo.title}`,
|
||||||
state: mediaInfoModule.mediaInfo.artist,
|
state: mediaInfoModule.mediaInfo.artist,
|
||||||
|
startTimestamp: parseInt(now),
|
||||||
|
endTimestamp: parseInt(remaining),
|
||||||
buttons: [{ label: "Play on Tidal", url: mediaInfoModule.mediaInfo.url }],
|
buttons: [{ label: "Play on Tidal", url: mediaInfoModule.mediaInfo.url }],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -25,7 +37,7 @@ const observer = (event, arg) => {
|
|||||||
const idleStatus = {
|
const idleStatus = {
|
||||||
details: `Browsing Tidal`,
|
details: `Browsing Tidal`,
|
||||||
largeImageKey: "tidal-hifi-icon",
|
largeImageKey: "tidal-hifi-icon",
|
||||||
largeImageText: `Tidal HiFi ${electron.app.getVersion()}`,
|
largeImageText: `Tidal HiFi ${app.getVersion()}`,
|
||||||
instance: false,
|
instance: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ const mediaInfo = {
|
|||||||
icon: "",
|
icon: "",
|
||||||
status: statuses.paused,
|
status: statuses.paused,
|
||||||
url: "",
|
url: "",
|
||||||
|
current: "",
|
||||||
|
duration: ""
|
||||||
};
|
};
|
||||||
const mediaInfoModule = {
|
const mediaInfoModule = {
|
||||||
mediaInfo,
|
mediaInfo,
|
||||||
@ -20,6 +22,8 @@ mediaInfoModule.update = function (arg) {
|
|||||||
mediaInfo.icon = propOrDefault(arg.icon);
|
mediaInfo.icon = propOrDefault(arg.icon);
|
||||||
mediaInfo.url = propOrDefault(arg.url);
|
mediaInfo.url = propOrDefault(arg.url);
|
||||||
mediaInfo.status = propOrDefault(arg.status);
|
mediaInfo.status = propOrDefault(arg.status);
|
||||||
|
mediaInfo.current = propOrDefault(arg.current);
|
||||||
|
mediaInfo.duration = propOrDefault(arg.duration);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user