mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-11-22 13:32:42 +01:00
Removed redundant RPC settings
This commit is contained in:
parent
f832bd2712
commit
f96cf2e8da
@ -27,10 +27,7 @@ export const settings = {
|
||||
enableDiscord: "enableDiscord",
|
||||
discord: {
|
||||
detailsPrefix: "discord.detailsPrefix",
|
||||
buttonText: "discord.buttonText",
|
||||
includeTimestamps: "discord.includeTimestamps",
|
||||
showSong: "discord.showSong",
|
||||
showIdle: "discord.showIdle",
|
||||
idleText: "discord.idleText",
|
||||
usingText: "discord.usingText",
|
||||
},
|
||||
|
@ -20,11 +20,6 @@ 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,
|
||||
@ -54,13 +49,7 @@ let adBlock: HTMLInputElement,
|
||||
ListenBrainzToken: HTMLInputElement,
|
||||
listenbrainz_delay: HTMLInputElement,
|
||||
enableWaylandSupport: HTMLInputElement,
|
||||
discord_details_prefix: HTMLInputElement,
|
||||
discord_include_timestamps: HTMLInputElement,
|
||||
discord_button_text: HTMLInputElement,
|
||||
discord_show_song: HTMLInputElement,
|
||||
discord_show_idle: HTMLInputElement,
|
||||
discord_idle_text: HTMLInputElement,
|
||||
discord_using_text: HTMLInputElement;
|
||||
discord_details_prefix: HTMLInputElement
|
||||
|
||||
addCustomCss(app);
|
||||
|
||||
@ -149,12 +138,6 @@ function refreshSettings() {
|
||||
ListenBrainzToken.value = settingsStore.get(settings.ListenBrainz.token);
|
||||
listenbrainz_delay.value = settingsStore.get(settings.ListenBrainz.delay);
|
||||
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_show_idle.checked = settingsStore.get(settings.discord.showIdle);
|
||||
discord_idle_text.value = settingsStore.get(settings.discord.idleText);
|
||||
discord_using_text.value = settingsStore.get(settings.discord.usingText);
|
||||
|
||||
// set state of all switches with additional settings
|
||||
Object.values(switchesWithSettings).forEach((settingSwitch) => {
|
||||
@ -267,13 +250,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
ListenBrainzAPI = get("ListenBrainzAPI");
|
||||
ListenBrainzToken = get("ListenBrainzToken");
|
||||
discord_details_prefix = get("discord_details_prefix");
|
||||
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_show_idle = get("discord_show_idle");
|
||||
discord_using_text = get("discord_using_text");
|
||||
discord_idle_text = get("discord_idle_text");
|
||||
|
||||
refreshSettings();
|
||||
addInputListener(adBlock, settings.adBlock);
|
||||
@ -308,14 +285,4 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
addInputListener(ListenBrainzToken, settings.ListenBrainz.token);
|
||||
addInputListener(listenbrainz_delay, settings.ListenBrainz.delay);
|
||||
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_show_idle, settings.discord.showIdle);
|
||||
addInputListener(discord_idle_text, settings.discord.idleText);
|
||||
addInputListener(discord_using_text, settings.discord.usingText);
|
||||
});
|
||||
|
@ -226,75 +226,13 @@
|
||||
</label>
|
||||
</div>
|
||||
<div id="discord_options">
|
||||
|
||||
<div class="group__option" class="hidden">
|
||||
<div class="group__description">
|
||||
<h4>Show Idle Text</h4>
|
||||
<p>Should the idle text be shown when idle?</p>
|
||||
</div>
|
||||
<label class="switch">
|
||||
<input id="discord_show_idle" type="checkbox" />
|
||||
<span class="switch__slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="group__option" class="hidden">
|
||||
<div class="group__description">
|
||||
<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" />
|
||||
<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" class="hidden">
|
||||
<div class="group__description">
|
||||
<h4>Using Tidal Text</h4>
|
||||
<p>The text displayed on Discord's rich presence while "showSong" is turned off</p>
|
||||
<input id="discord_using_text" type="text" class="text-input" name="discord_using_text" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="group__option" class="hidden">
|
||||
<div class="group__description">
|
||||
<h4>Show media</h4>
|
||||
<p>Show the current media in the Discord client</p>
|
||||
</div>
|
||||
<label class="switch">
|
||||
<input id="discord_show_song" type="checkbox" />
|
||||
<span class="switch__slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<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 media information.</p>
|
||||
<input id="discord_button_text" type="text" class="text-input" name="discord_button_text" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="group">
|
||||
|
@ -21,14 +21,14 @@ const observer = () => {
|
||||
};
|
||||
|
||||
const defaultPresence = {
|
||||
largeImageKey: "tidal-hifi-icon",
|
||||
largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
||||
smallImageKey: "tidal-hifi-icon",
|
||||
smallImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
||||
instance: false,
|
||||
type: ACTIVITY_LISTENING
|
||||
};
|
||||
|
||||
const updateActivity = () => {
|
||||
const showIdle = settingsStore.get<string, boolean>(settings.discord.showIdle) ?? true;
|
||||
if (mediaInfo.status === MediaStatus.paused && !showIdle) {
|
||||
if (mediaInfo.status === MediaStatus.paused) {
|
||||
rpc.user?.clearActivity();
|
||||
} else {
|
||||
rpc.user?.setActivity(getActivity());
|
||||
@ -38,36 +38,11 @@ const updateActivity = () => {
|
||||
const getActivity = (): SetActivity => {
|
||||
const presence: SetActivity = { ...defaultPresence };
|
||||
|
||||
presence.type = ACTIVITY_LISTENING;
|
||||
|
||||
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, detailsPrefix, buttonText } = getFromStore();
|
||||
includeTimeStamps(includeTimestamps);
|
||||
setPresenceFromMediaInfo(detailsPrefix, buttonText);
|
||||
} else {
|
||||
presence.details =
|
||||
settingsStore.get<string, string>(settings.discord.usingText) ?? "Playing media on TIDAL";
|
||||
}
|
||||
}
|
||||
includeTimeStamps();
|
||||
setPresenceFromMediaInfo();
|
||||
|
||||
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 ";
|
||||
const buttonText =
|
||||
settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";
|
||||
|
||||
return { includeTimestamps, detailsPrefix, buttonText };
|
||||
}
|
||||
|
||||
/**
|
||||
* Pad a string using spaces to at least 2 characters
|
||||
* @param input string to pad with 2 characters
|
||||
@ -77,36 +52,28 @@ const getActivity = (): SetActivity => {
|
||||
return input.padEnd(2, " ");
|
||||
}
|
||||
|
||||
function setPresenceFromMediaInfo(detailsPrefix: string, buttonText: string) {
|
||||
function setPresenceFromMediaInfo() {
|
||||
// discord requires a minimum of 2 characters
|
||||
const title = pad(mediaInfo.title);
|
||||
const album = pad(mediaInfo.album);
|
||||
const artists = pad(mediaInfo.artists);
|
||||
|
||||
const detailsPrefix = settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
|
||||
presence.details = `${detailsPrefix}${title}`;
|
||||
presence.state = artists ? artists : "unknown artist(s)";
|
||||
if (mediaInfo.url) {
|
||||
presence.details = `${detailsPrefix}${title}`;
|
||||
presence.state = artists ? artists : "unknown artist(s)";
|
||||
presence.largeImageKey = mediaInfo.image;
|
||||
if (album) {
|
||||
presence.largeImageText = album;
|
||||
}
|
||||
|
||||
presence.buttons = [{ label: buttonText, url: mediaInfo.url }];
|
||||
} else {
|
||||
presence.details = `Watching ${title}`;
|
||||
presence.state = artists;
|
||||
if (album) presence.largeImageText = album;
|
||||
}
|
||||
}
|
||||
|
||||
function includeTimeStamps(includeTimestamps: boolean) {
|
||||
if (includeTimestamps) {
|
||||
function includeTimeStamps() {
|
||||
const currentSeconds = convertDurationToSeconds(mediaInfo.current);
|
||||
const durationSeconds = convertDurationToSeconds(mediaInfo.duration);
|
||||
const date = new Date();
|
||||
const now = Math.floor(date.getTime() / 1000);
|
||||
presence.startTimestamp = now - currentSeconds;
|
||||
presence.endTimestamp = presence.startTimestamp + durationSeconds;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -42,13 +42,10 @@ export const settingsStore = new Store({
|
||||
enableCustomHotkeys: false,
|
||||
enableDiscord: false,
|
||||
discord: {
|
||||
showSong: true,
|
||||
showIdle: true,
|
||||
idleText: "Browsing Tidal",
|
||||
usingText: "Playing media on TIDAL",
|
||||
includeTimestamps: true,
|
||||
detailsPrefix: "Listening to ",
|
||||
buttonText: "Play on Tidal",
|
||||
},
|
||||
ListenBrainz: {
|
||||
enabled: false,
|
||||
@ -89,16 +86,8 @@ export const settingsStore = new Store({
|
||||
migrationStore.get(settings.ListenBrainz.delay) ?? 5000
|
||||
);
|
||||
},
|
||||
"5.8.0": (migrationStore) => {
|
||||
console.log("running migrations for 5.8.0");
|
||||
migrationStore.set(
|
||||
settings.discord.includeTimestamps,
|
||||
migrationStore.get(settings.discord.includeTimestamps) ?? true
|
||||
);
|
||||
},
|
||||
"5.9.0": (migrationStore) => {
|
||||
buildMigration("5.9.0", migrationStore, [
|
||||
{ key: settings.discord.showSong, value: "true" },
|
||||
{ key: settings.discord.idleText, value: "Browsing Tidal" },
|
||||
{
|
||||
key: settings.discord.usingText,
|
||||
@ -115,10 +104,7 @@ export const settingsStore = new Store({
|
||||
buildMigration("5.15.0", migrationStore, [
|
||||
{ key: settings.advanced.tidalUrl, value: "https://listen.tidal.com" },
|
||||
]);
|
||||
},
|
||||
"5.16.0": (migrationStore) => {
|
||||
buildMigration("5.16.0", migrationStore, [{ key: settings.discord.showIdle, value: "true" }]);
|
||||
},
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user