Skip to content

Commit

Permalink
Fixed impl
Browse files Browse the repository at this point in the history
  • Loading branch information
3top1a committed Oct 17, 2024
1 parent 1a0c15e commit b1830f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions src/scripts/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const clientId = "833617820704440341";

export let rpc: DRPC.Client;

const ACTIVITY_LISTENING = 2;

const observer = () => {
if (rpc) {
updateActivity();
Expand All @@ -20,7 +22,7 @@ const observer = () => {

const defaultPresence = {
largeImageKey: "tidal-hifi-icon",
largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
largeImageText: `Tidal`,
instance: false,
};

Expand All @@ -36,7 +38,7 @@ const updateActivity = () => {
const getActivity = (): DRPC.Presence => {
const presence: DRPC.Presence = { ...defaultPresence };

presence.type = DRPC.ActivityTypes.LISTENING
presence.type = ACTIVITY_LISTENING;

if (mediaInfo.status === MediaStatus.paused) {
presence.details =
Expand All @@ -52,13 +54,14 @@ const getActivity = (): DRPC.Presence => {
settingsStore.get<string, string>(settings.discord.usingText) ?? "Playing media on TIDAL";
}
}

return presence;

function getFromStore() {
const includeTimestamps =
settingsStore.get<string, boolean>(settings.discord.includeTimestamps) ?? true;
const detailsPrefix =
settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "";
const buttonText =
settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";

Expand Down Expand Up @@ -100,12 +103,13 @@ const getActivity = (): DRPC.Presence => {
const currentSeconds = convertDurationToSeconds(mediaInfo.current);
const durationSeconds = convertDurationToSeconds(mediaInfo.duration);
const date = new Date();
const now = (date.getTime() / 1000) | 0;
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
presence.startTimestamp = now;
presence.endTimestamp = remaining;
const now = Math.floor(date.getTime() / 1000);
const startTimestamp = now - currentSeconds;
const endTimestamp = startTimestamp + durationSeconds;
presence.startTimestamp = startTimestamp;
presence.endTimestamp = endTimestamp;
}
}
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const settingsStore = new Store({
idleText: "Browsing Tidal",
usingText: "Playing media on TIDAL",
includeTimestamps: true,
detailsPrefix: "Listening to ",
detailsPrefix: "",
buttonText: "Play on Tidal",
},
ListenBrainz: {
Expand Down

0 comments on commit b1830f5

Please sign in to comment.