add time left to discord rpc & duration, current to mediainfo

This commit is contained in:
Marie 2021-04-20 21:56:45 +02:00 committed by GitHub
parent 31d90a342c
commit df887b8628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -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,
};

View File

@ -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);
};
/**