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",
|
||||
buttonText: "discord.buttonText",
|
||||
includeTimestamps: "discord.includeTimestamps",
|
||||
showSong: "discord.showSong",
|
||||
idleText: "discord.idleText",
|
||||
listeningText: "discord.listeningText",
|
||||
},
|
||||
ListenBrainz: {
|
||||
root: "ListenBrainz",
|
||||
|
@ -20,6 +20,11 @@ const switchesWithSettings = {
|
||||
classToHide: "discord_options",
|
||||
settingsKey: settings.enableDiscord,
|
||||
},
|
||||
discord_show_song: {
|
||||
switch: "discord_show_song",
|
||||
classToHide: "discord_show_song_options",
|
||||
settingsKey: settings.discord.showSong,
|
||||
}
|
||||
};
|
||||
|
||||
let adBlock: HTMLInputElement,
|
||||
@ -49,7 +54,10 @@ let adBlock: HTMLInputElement,
|
||||
enableWaylandSupport: HTMLInputElement,
|
||||
discord_details_prefix: 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);
|
||||
|
||||
@ -138,6 +146,9 @@ function refreshSettings() {
|
||||
discord_details_prefix.value = settingsStore.get(settings.discord.detailsPrefix);
|
||||
discord_include_timestamps.checked = settingsStore.get(settings.discord.includeTimestamps);
|
||||
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
|
||||
Object.values(switchesWithSettings).forEach((settingSwitch) => {
|
||||
@ -251,6 +262,9 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
discord_include_timestamps = get("discord_include_timestamps");
|
||||
listenbrainz_delay = get("listenbrainz_delay");
|
||||
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();
|
||||
addInputListener(adBlock, settings.adBlock);
|
||||
@ -285,4 +299,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
addInputListener(discord_details_prefix, settings.discord.detailsPrefix);
|
||||
addInputListener(discord_include_timestamps, settings.discord.includeTimestamps);
|
||||
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>
|
||||
</div>
|
||||
<div id="discord_options">
|
||||
|
||||
<div class="group__option" class="hidden">
|
||||
<div class="group__description">
|
||||
<h4>Include timestamps</h4>
|
||||
<p>Show current/end playtime in the Discord client</p>
|
||||
<h4>Idle Text</h4>
|
||||
<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>
|
||||
<label class="switch">
|
||||
<input id="discord_include_timestamps" type="checkbox" />
|
||||
<input id="discord_show_song" 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 id="discord_show_song_options" class="hidden">
|
||||
|
||||
<div class="group__option" class="hidden">
|
||||
<div class="group__description">
|
||||
<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 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 class="group">
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Client } from "discord-rpc";
|
||||
import { Client, Presence } from "discord-rpc";
|
||||
import { app, ipcMain } from "electron";
|
||||
import { globalEvents } from "../constants/globalEvents";
|
||||
import { settings } from "../constants/settings";
|
||||
@ -18,58 +18,54 @@ function timeToSeconds(timeArray: string[]) {
|
||||
export let rpc: Client;
|
||||
|
||||
const observer = () => {
|
||||
if (mediaInfo.status === MediaStatus.paused && rpc) {
|
||||
rpc.setActivity(idleStatus);
|
||||
} 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);
|
||||
if (rpc) {
|
||||
rpc.setActivity(getActivity());
|
||||
}
|
||||
};
|
||||
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 = {
|
||||
details: `Browsing Tidal`,
|
||||
largeImageKey: "tidal-hifi-icon",
|
||||
largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
||||
instance: false,
|
||||
if (includeTimestamps) {
|
||||
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));
|
||||
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.on("ready", () => {
|
||||
rpc.setActivity(idleStatus);
|
||||
rpc.setActivity(getActivity());
|
||||
});
|
||||
ipcMain.on(globalEvents.updateInfo, observer);
|
||||
},
|
||||
|
@ -19,6 +19,9 @@ export const settingsStore = new Store({
|
||||
enableCustomHotkeys: false,
|
||||
enableDiscord: false,
|
||||
discord: {
|
||||
showSong: false,
|
||||
idleText: "Browsing Tidal",
|
||||
listeningText: "Listening Tidal",
|
||||
detailsPrefix: "Listening to ",
|
||||
buttonText: "Play on Tidal",
|
||||
includeTimestamps: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user