mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-07-07 14:53:51 +02:00
Merge e37b2f99cc856f819ed87f5621f15b3a00e2b6d1 into 887a3d8a45d7f4241a3e0ca64efbb7200ca6f836
This commit is contained in:
commit
2d383ae828
@ -24,6 +24,9 @@ export const settings = {
|
|||||||
detailsPrefix: "discord.detailsPrefix",
|
detailsPrefix: "discord.detailsPrefix",
|
||||||
buttonText: "discord.buttonText",
|
buttonText: "discord.buttonText",
|
||||||
includeTimestamps: "discord.includeTimestamps",
|
includeTimestamps: "discord.includeTimestamps",
|
||||||
|
showSong: "discord.showSong",
|
||||||
|
idleText: "discord.idleText",
|
||||||
|
listeningText: "discord.listeningText",
|
||||||
},
|
},
|
||||||
ListenBrainz: {
|
ListenBrainz: {
|
||||||
root: "ListenBrainz",
|
root: "ListenBrainz",
|
||||||
|
@ -20,6 +20,11 @@ const switchesWithSettings = {
|
|||||||
classToHide: "discord_options",
|
classToHide: "discord_options",
|
||||||
settingsKey: settings.enableDiscord,
|
settingsKey: settings.enableDiscord,
|
||||||
},
|
},
|
||||||
|
discord_show_song: {
|
||||||
|
switch: "discord_show_song",
|
||||||
|
classToHide: "discord_show_song_options",
|
||||||
|
settingsKey: settings.discord.showSong,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let adBlock: HTMLInputElement,
|
let adBlock: HTMLInputElement,
|
||||||
@ -49,7 +54,10 @@ let adBlock: HTMLInputElement,
|
|||||||
enableWaylandSupport: HTMLInputElement,
|
enableWaylandSupport: HTMLInputElement,
|
||||||
discord_details_prefix: HTMLInputElement,
|
discord_details_prefix: HTMLInputElement,
|
||||||
discord_include_timestamps: HTMLInputElement,
|
discord_include_timestamps: HTMLInputElement,
|
||||||
discord_button_text: HTMLInputElement;
|
discord_button_text: HTMLInputElement,
|
||||||
|
discord_show_song: HTMLInputElement,
|
||||||
|
discord_idle_text: HTMLInputElement,
|
||||||
|
discord_listening_text: HTMLInputElement;
|
||||||
|
|
||||||
addCustomCss(app);
|
addCustomCss(app);
|
||||||
|
|
||||||
@ -138,6 +146,9 @@ function refreshSettings() {
|
|||||||
discord_details_prefix.value = settingsStore.get(settings.discord.detailsPrefix);
|
discord_details_prefix.value = settingsStore.get(settings.discord.detailsPrefix);
|
||||||
discord_include_timestamps.checked = settingsStore.get(settings.discord.includeTimestamps);
|
discord_include_timestamps.checked = settingsStore.get(settings.discord.includeTimestamps);
|
||||||
discord_button_text.value = settingsStore.get(settings.discord.buttonText);
|
discord_button_text.value = settingsStore.get(settings.discord.buttonText);
|
||||||
|
discord_show_song.checked = settingsStore.get(settings.discord.showSong);
|
||||||
|
discord_idle_text.value = settingsStore.get(settings.discord.idleText);
|
||||||
|
discord_listening_text.value = settingsStore.get(settings.discord.listeningText);
|
||||||
|
|
||||||
// set state of all switches with additional settings
|
// set state of all switches with additional settings
|
||||||
Object.values(switchesWithSettings).forEach((settingSwitch) => {
|
Object.values(switchesWithSettings).forEach((settingSwitch) => {
|
||||||
@ -251,6 +262,9 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
discord_include_timestamps = get("discord_include_timestamps");
|
discord_include_timestamps = get("discord_include_timestamps");
|
||||||
listenbrainz_delay = get("listenbrainz_delay");
|
listenbrainz_delay = get("listenbrainz_delay");
|
||||||
discord_button_text = get("discord_button_text");
|
discord_button_text = get("discord_button_text");
|
||||||
|
discord_show_song = get("discord_show_song");
|
||||||
|
discord_listening_text = get("discord_listening_text");
|
||||||
|
discord_idle_text = get("discord_idle_text")
|
||||||
|
|
||||||
refreshSettings();
|
refreshSettings();
|
||||||
addInputListener(adBlock, settings.adBlock);
|
addInputListener(adBlock, settings.adBlock);
|
||||||
@ -285,4 +299,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
addInputListener(discord_details_prefix, settings.discord.detailsPrefix);
|
addInputListener(discord_details_prefix, settings.discord.detailsPrefix);
|
||||||
addInputListener(discord_include_timestamps, settings.discord.includeTimestamps);
|
addInputListener(discord_include_timestamps, settings.discord.includeTimestamps);
|
||||||
addInputListener(discord_button_text, settings.discord.buttonText);
|
addInputListener(discord_button_text, settings.discord.buttonText);
|
||||||
|
addInputListener(discord_show_song, settings.discord.showSong, switchesWithSettings.discord_show_song);
|
||||||
|
addInputListener(discord_idle_text, settings.discord.idleText);
|
||||||
|
addInputListener(discord_listening_text, settings.discord.listeningText);
|
||||||
});
|
});
|
||||||
|
@ -216,32 +216,64 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div id="discord_options">
|
<div id="discord_options">
|
||||||
|
|
||||||
<div class="group__option" class="hidden">
|
<div class="group__option" class="hidden">
|
||||||
<div class="group__description">
|
<div class="group__description">
|
||||||
<h4>Include timestamps</h4>
|
<h4>Idle Text</h4>
|
||||||
<p>Show current/end playtime in the Discord client</p>
|
<p>The text displayed on Discord's rich presence while idling in the app.</p>
|
||||||
|
<input id="discord_idle_text" type="text" class="text-input" name="discord_idle_text" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="group__option" class="hidden">
|
||||||
|
<div class="group__description">
|
||||||
|
<h4>Listening Text</h4>
|
||||||
|
<p>The text displayed on Discord's rich presence while listening to a song.</p>
|
||||||
|
<input id="discord_listening_text" type="text" class="text-input" name="discord_listening_text" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="group__option" class="hidden">
|
||||||
|
<div class="group__description">
|
||||||
|
<h4>Show song</h4>
|
||||||
|
<p>Show the current song in the Discord client</p>
|
||||||
</div>
|
</div>
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
<input id="discord_include_timestamps" type="checkbox" />
|
<input id="discord_show_song" type="checkbox" />
|
||||||
<span class="switch__slider"></span>
|
<span class="switch__slider"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="group__option" class="hidden">
|
<div id="discord_show_song_options" class="hidden">
|
||||||
<div class="group__description">
|
|
||||||
<h4>Details prefix</h4>
|
<div class="group__option" class="hidden">
|
||||||
<p>Prefix for the "details" field of Discord's rich presence.</p>
|
<div class="group__description">
|
||||||
<input id="discord_details_prefix" type="text" class="text-input" name="discord_details_prefix" />
|
<h4>Include timestamps</h4>
|
||||||
|
<p>Show current/end playtime in the Discord client</p>
|
||||||
|
</div>
|
||||||
|
<label class="switch">
|
||||||
|
<input id="discord_include_timestamps" type="checkbox" />
|
||||||
|
<span class="switch__slider"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="group__option" class="hidden">
|
||||||
|
<div class="group__description">
|
||||||
|
<h4>Details prefix</h4>
|
||||||
|
<p>Prefix for the "details" field of Discord's rich presence.</p>
|
||||||
|
<input id="discord_details_prefix" type="text" class="text-input" name="discord_details_prefix" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="group__option">
|
||||||
|
<div class="group__description">
|
||||||
|
<h4>Button text</h4>
|
||||||
|
<p>Text to display on the button below the song information.</p>
|
||||||
|
<input id="discord_button_text" type="text" class="text-input" name="discord_button_text" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="group__option">
|
|
||||||
<div class="group__description">
|
|
||||||
<h4>Button text</h4>
|
|
||||||
<p>Text to display on the button below the song information.</p>
|
|
||||||
<input id="discord_button_text" type="text" class="text-input" name="discord_button_text" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="group">
|
<div class="group">
|
||||||
@ -422,4 +454,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -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 currentSeconds = timeToSeconds(mediaInfo.current.split(":"));
|
|
||||||
const durationSeconds = timeToSeconds(mediaInfo.duration.split(":"));
|
|
||||||
const date = new Date();
|
|
||||||
const now = (date.getTime() / 1000) | 0;
|
|
||||||
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
|
|
||||||
const detailsPrefix =
|
|
||||||
settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
|
|
||||||
const buttonText =
|
|
||||||
settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";
|
|
||||||
const includeTimestamps =
|
|
||||||
settingsStore.get<string, boolean>(settings.discord.includeTimestamps) ?? true;
|
|
||||||
|
|
||||||
let activity = {
|
|
||||||
...idleStatus,
|
|
||||||
...{
|
|
||||||
startTimestamp: includeTimestamps ? now : undefined,
|
|
||||||
endTimestamp: includeTimestamps ? remaining : undefined,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (mediaInfo.url) {
|
|
||||||
activity = {
|
|
||||||
...activity,
|
|
||||||
...{
|
|
||||||
details: `${detailsPrefix}${mediaInfo.title}`,
|
|
||||||
state: mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)",
|
|
||||||
largeImageKey: mediaInfo.image,
|
|
||||||
largeImageText: mediaInfo.album ? mediaInfo.album : `${idleStatus.largeImageText}`,
|
|
||||||
buttons: [{ label: buttonText, url: mediaInfo.url }],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
activity = {
|
|
||||||
...activity,
|
|
||||||
...{
|
|
||||||
details: `Watching ${mediaInfo.title}`,
|
|
||||||
state: mediaInfo.artists,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
rpc.setActivity(activity);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
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;
|
||||||
|
|
||||||
const idleStatus = {
|
if (includeTimestamps) {
|
||||||
details: `Browsing Tidal`,
|
const currentSeconds = timeToSeconds(mediaInfo.current.split(":"));
|
||||||
largeImageKey: "tidal-hifi-icon",
|
const durationSeconds = timeToSeconds(mediaInfo.duration.split(":"));
|
||||||
largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
const date = new Date();
|
||||||
instance: false,
|
const now = (date.getTime() / 1000) | 0;
|
||||||
|
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
|
||||||
|
presence.startTimestamp = now;
|
||||||
|
presence.endTimestamp = remaining;
|
||||||
|
}
|
||||||
|
|
||||||
|
const detailsPrefix = settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
|
||||||
|
const buttonText = settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";
|
||||||
|
|
||||||
|
if (mediaInfo.url) {
|
||||||
|
presence.details = `${detailsPrefix}${mediaInfo.title}`;
|
||||||
|
presence.state = mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)";
|
||||||
|
presence.largeImageKey = mediaInfo.image;
|
||||||
|
if (mediaInfo.album) {
|
||||||
|
presence.largeImageText = mediaInfo.album;
|
||||||
|
}
|
||||||
|
presence.buttons = [{ label: buttonText, url: mediaInfo.url }];
|
||||||
|
} else {
|
||||||
|
presence.details = `Watching ${mediaInfo.title}`;
|
||||||
|
presence.state = mediaInfo.artists;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
presence.details = settingsStore.get<string, string>(settings.discord.listeningText) ?? "Listening Tidal";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return presence;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -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);
|
||||||
},
|
},
|
||||||
|
@ -19,6 +19,9 @@ export const settingsStore = new Store({
|
|||||||
enableCustomHotkeys: false,
|
enableCustomHotkeys: false,
|
||||||
enableDiscord: false,
|
enableDiscord: false,
|
||||||
discord: {
|
discord: {
|
||||||
|
showSong: false,
|
||||||
|
idleText: "Browsing Tidal",
|
||||||
|
listeningText: "Listening Tidal",
|
||||||
detailsPrefix: "Listening to ",
|
detailsPrefix: "Listening to ",
|
||||||
buttonText: "Play on Tidal",
|
buttonText: "Play on Tidal",
|
||||||
includeTimestamps: true,
|
includeTimestamps: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user