mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-09-14 23:59:18 +02:00
Compare commits
33 Commits
5.15.0
...
cff5fc37b2
Author | SHA1 | Date | |
---|---|---|---|
|
cff5fc37b2 | ||
|
6be5774001 | ||
|
f96cf2e8da | ||
|
f832bd2712 | ||
91156e5936 | |||
|
57e9a2dcb8 | ||
|
21edcd6ad5 | ||
|
3dc42eceb0 | ||
|
b1830f5684 | ||
|
1a0c15e17f | ||
6e59d59a1d | |||
|
fab7497311 | ||
fccbcc77ea | |||
|
041c19fb52 | ||
e36c562afa | |||
1589aa5251 | |||
8c672dd1eb | |||
|
3769550f24 | ||
|
5a06b6c53f | ||
|
1d4ef66d27 | ||
e02f07401b | |||
118f92e75a | |||
|
788d302ce8 | ||
|
cc09f35b49 | ||
ef13933c66 | |||
4f72e1b35d | |||
2c1c76d2d0 | |||
e2a84e119a | |||
5b85e59fc3 | |||
c3b772919a | |||
|
70f2f5c248 | ||
|
ffcb563b35 | ||
|
2dd96dd48e |
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [5.16.0]
|
||||||
|
|
||||||
|
- Fix issue #449 Discord RPC stuck on "Browsing Tidal".
|
||||||
|
- Fix issue #448 Add option to disable the discord rpc idle text
|
||||||
|
- Notifications are now send at the end of the update process, allowing other events to happen sooner.
|
||||||
|
|
||||||
## [5.15.0]
|
## [5.15.0]
|
||||||
|
|
||||||
- Added all missing swagger/openApi info with the help of [Times-Z](https://github.com/Times-Z)
|
- Added all missing swagger/openApi info with the help of [Times-Z](https://github.com/Times-Z)
|
||||||
|
707
package-lock.json
generated
707
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tidal-hifi",
|
"name": "tidal-hifi",
|
||||||
"version": "5.15.0",
|
"version": "5.16.0",
|
||||||
"description": "Tidal on Electron with widevine(hifi) support",
|
"description": "Tidal on Electron with widevine(hifi) support",
|
||||||
"main": "ts-dist/main.js",
|
"main": "ts-dist/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -42,21 +42,20 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron/remote": "^2.1.2",
|
"@electron/remote": "^2.1.2",
|
||||||
"@types/swagger-jsdoc": "^6.0.4",
|
"@types/swagger-jsdoc": "^6.0.4",
|
||||||
"axios": "^1.7.2",
|
"@xhayper/discord-rpc": "^1.2.0",
|
||||||
|
"axios": "^1.7.7",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"discord-rpc": "^4.0.1",
|
|
||||||
"electron-store": "^8.2.0",
|
"electron-store": "^8.2.0",
|
||||||
"express": "^4.19.2",
|
"express": "^4.21.1",
|
||||||
"hotkeys-js": "^3.13.7",
|
"hotkeys-js": "^3.13.7",
|
||||||
"mpris-service": "^2.1.2",
|
"mpris-service": "^2.1.2",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"sass": "^1.77.7",
|
"sass": "^1.79.4",
|
||||||
"swagger-ui-express": "^5.0.1"
|
"swagger-ui-express": "^5.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@mastermindzh/prettier-config": "^1.0.0",
|
"@mastermindzh/prettier-config": "^1.0.0",
|
||||||
"@types/cors": "^2.8.17",
|
"@types/cors": "^2.8.17",
|
||||||
"@types/discord-rpc": "^4.0.8",
|
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/node": "^20.14.10",
|
"@types/node": "^20.14.10",
|
||||||
"@types/request": "^2.48.12",
|
"@types/request": "^2.48.12",
|
||||||
@@ -81,4 +80,4 @@
|
|||||||
"typescript": "^5.5.3"
|
"typescript": "^5.5.3"
|
||||||
},
|
},
|
||||||
"prettier": "@mastermindzh/prettier-config"
|
"prettier": "@mastermindzh/prettier-config"
|
||||||
}
|
}
|
||||||
|
@@ -27,9 +27,7 @@ export const settings = {
|
|||||||
enableDiscord: "enableDiscord",
|
enableDiscord: "enableDiscord",
|
||||||
discord: {
|
discord: {
|
||||||
detailsPrefix: "discord.detailsPrefix",
|
detailsPrefix: "discord.detailsPrefix",
|
||||||
buttonText: "discord.buttonText",
|
|
||||||
includeTimestamps: "discord.includeTimestamps",
|
includeTimestamps: "discord.includeTimestamps",
|
||||||
showSong: "discord.showSong",
|
|
||||||
idleText: "discord.idleText",
|
idleText: "discord.idleText",
|
||||||
usingText: "discord.usingText",
|
usingText: "discord.usingText",
|
||||||
},
|
},
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"openapi": "3.1.0",
|
"openapi": "3.1.0",
|
||||||
"info": {
|
"info": {
|
||||||
"title": "TIDAL Hi-Fi API",
|
"title": "TIDAL Hi-Fi API",
|
||||||
"version": "5.15.0",
|
"version": "5.16.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"license": {
|
"license": {
|
||||||
"name": "MIT",
|
"name": "MIT",
|
||||||
|
@@ -20,11 +20,6 @@ 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,
|
||||||
@@ -54,12 +49,7 @@ let adBlock: HTMLInputElement,
|
|||||||
ListenBrainzToken: HTMLInputElement,
|
ListenBrainzToken: HTMLInputElement,
|
||||||
listenbrainz_delay: HTMLInputElement,
|
listenbrainz_delay: HTMLInputElement,
|
||||||
enableWaylandSupport: HTMLInputElement,
|
enableWaylandSupport: HTMLInputElement,
|
||||||
discord_details_prefix: HTMLInputElement,
|
discord_details_prefix: HTMLInputElement
|
||||||
discord_include_timestamps: HTMLInputElement,
|
|
||||||
discord_button_text: HTMLInputElement,
|
|
||||||
discord_show_song: HTMLInputElement,
|
|
||||||
discord_idle_text: HTMLInputElement,
|
|
||||||
discord_using_text: HTMLInputElement;
|
|
||||||
|
|
||||||
addCustomCss(app);
|
addCustomCss(app);
|
||||||
|
|
||||||
@@ -148,11 +138,6 @@ function refreshSettings() {
|
|||||||
ListenBrainzToken.value = settingsStore.get(settings.ListenBrainz.token);
|
ListenBrainzToken.value = settingsStore.get(settings.ListenBrainz.token);
|
||||||
listenbrainz_delay.value = settingsStore.get(settings.ListenBrainz.delay);
|
listenbrainz_delay.value = settingsStore.get(settings.ListenBrainz.delay);
|
||||||
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_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_using_text.value = settingsStore.get(settings.discord.usingText);
|
|
||||||
|
|
||||||
// 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) => {
|
||||||
@@ -265,12 +250,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
ListenBrainzAPI = get("ListenBrainzAPI");
|
ListenBrainzAPI = get("ListenBrainzAPI");
|
||||||
ListenBrainzToken = get("ListenBrainzToken");
|
ListenBrainzToken = get("ListenBrainzToken");
|
||||||
discord_details_prefix = get("discord_details_prefix");
|
discord_details_prefix = get("discord_details_prefix");
|
||||||
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_show_song = get("discord_show_song");
|
|
||||||
discord_using_text = get("discord_using_text");
|
|
||||||
discord_idle_text = get("discord_idle_text");
|
|
||||||
|
|
||||||
refreshSettings();
|
refreshSettings();
|
||||||
addInputListener(adBlock, settings.adBlock);
|
addInputListener(adBlock, settings.adBlock);
|
||||||
@@ -305,13 +285,4 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
addInputListener(ListenBrainzToken, settings.ListenBrainz.token);
|
addInputListener(ListenBrainzToken, settings.ListenBrainz.token);
|
||||||
addInputListener(listenbrainz_delay, settings.ListenBrainz.delay);
|
addInputListener(listenbrainz_delay, settings.ListenBrainz.delay);
|
||||||
addInputListener(discord_details_prefix, settings.discord.detailsPrefix);
|
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_using_text, settings.discord.usingText);
|
|
||||||
});
|
});
|
||||||
|
@@ -226,64 +226,13 @@
|
|||||||
</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>Idle Text</h4>
|
<h4>Details prefix</h4>
|
||||||
<p>The text displayed on Discord's rich presence while idling in the app.</p>
|
<p>Prefix for the "details" field of Discord's rich presence.</p>
|
||||||
<input id="discord_idle_text" type="text" class="text-input" name="discord_idle_text" />
|
<input id="discord_details_prefix" type="text" class="text-input" name="discord_details_prefix" />
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
<div class="group">
|
<div class="group">
|
||||||
@@ -457,7 +406,7 @@
|
|||||||
<h4>TIDAL Hi-Fi</h4>
|
<h4>TIDAL Hi-Fi</h4>
|
||||||
<div class="about-section__version">
|
<div class="about-section__version">
|
||||||
<a target="_blank" rel="noopener"
|
<a target="_blank" rel="noopener"
|
||||||
href="https://github.com/Mastermindzh/tidal-hifi/releases/tag/5.15.0">5.15.0</a>
|
href="https://github.com/Mastermindzh/tidal-hifi/releases/tag/5.16.0">5.16.0</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="about-section__links">
|
<div class="about-section__links">
|
||||||
<a target="_blank" rel="noopener" href="https://github.com/mastermindzh/tidal-hifi/"
|
<a target="_blank" rel="noopener" href="https://github.com/mastermindzh/tidal-hifi/"
|
||||||
@@ -480,4 +429,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@@ -394,18 +394,30 @@ function updateMediaInfo(mediaInfo: MediaInfo, notify: boolean) {
|
|||||||
if (mediaInfo) {
|
if (mediaInfo) {
|
||||||
currentMediaInfo = mediaInfo;
|
currentMediaInfo = mediaInfo;
|
||||||
ipcRenderer.send(globalEvents.updateInfo, mediaInfo);
|
ipcRenderer.send(globalEvents.updateInfo, mediaInfo);
|
||||||
if (settingsStore.get(settings.notifications) && notify) {
|
|
||||||
if (currentNotification) currentNotification.close();
|
|
||||||
currentNotification = new Notification({
|
|
||||||
title: mediaInfo.title,
|
|
||||||
body: mediaInfo.artists,
|
|
||||||
icon: mediaInfo.icon,
|
|
||||||
});
|
|
||||||
currentNotification.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateMpris(mediaInfo);
|
updateMpris(mediaInfo);
|
||||||
updateListenBrainz(mediaInfo);
|
updateListenBrainz(mediaInfo);
|
||||||
|
if (notify) {
|
||||||
|
sendNotification(mediaInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a desktop notification if enabled in settings
|
||||||
|
* @param mediaInfo
|
||||||
|
* @param notify Whether to notify
|
||||||
|
*/
|
||||||
|
async function sendNotification(mediaInfo: MediaInfo) {
|
||||||
|
if (settingsStore.get(settings.notifications)) {
|
||||||
|
if (currentNotification) {
|
||||||
|
currentNotification.close();
|
||||||
|
}
|
||||||
|
currentNotification = new Notification({
|
||||||
|
title: mediaInfo.title,
|
||||||
|
body: mediaInfo.artists,
|
||||||
|
icon: mediaInfo.icon,
|
||||||
|
});
|
||||||
|
currentNotification.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Client, Presence } from "discord-rpc";
|
import { Client, SetActivity } from "@xhayper/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";
|
||||||
@@ -12,72 +12,89 @@ const clientId = "833617820704440341";
|
|||||||
|
|
||||||
export let rpc: Client;
|
export let rpc: Client;
|
||||||
|
|
||||||
|
const ACTIVITY_LISTENING = 2;
|
||||||
|
const MAX_RETRIES = 5;
|
||||||
|
const RETRY_DELAY = 10000;
|
||||||
|
|
||||||
const observer = () => {
|
const observer = () => {
|
||||||
if (rpc) {
|
if (rpc) {
|
||||||
rpc.setActivity(getActivity());
|
updateActivity();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultPresence = {
|
const defaultPresence = {
|
||||||
largeImageKey: "tidal-hifi-icon",
|
smallImageKey: "tidal-hifi-icon",
|
||||||
largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
smallImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
||||||
instance: false,
|
instance: false,
|
||||||
|
type: ACTIVITY_LISTENING
|
||||||
};
|
};
|
||||||
|
|
||||||
const getActivity = (): Presence => {
|
const updateActivity = () => {
|
||||||
const presence: Presence = { ...defaultPresence };
|
|
||||||
|
|
||||||
if (mediaInfo.status === MediaStatus.paused) {
|
if (mediaInfo.status === MediaStatus.paused) {
|
||||||
presence.details =
|
rpc.user?.clearActivity();
|
||||||
settingsStore.get<string, string>(settings.discord.idleText) ?? "Browsing Tidal";
|
|
||||||
} else {
|
} else {
|
||||||
const showSong = settingsStore.get<string, boolean>(settings.discord.showSong) ?? false;
|
rpc.user?.setActivity(getActivity());
|
||||||
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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getActivity = (): SetActivity => {
|
||||||
|
const presence: SetActivity = { ...defaultPresence };
|
||||||
|
|
||||||
|
includeTimeStamps();
|
||||||
|
setPresenceFromMediaInfo();
|
||||||
|
|
||||||
return presence;
|
return presence;
|
||||||
|
|
||||||
function getFromStore() {
|
/**
|
||||||
const includeTimestamps =
|
* Pad a string using spaces to at least 2 characters
|
||||||
settingsStore.get<string, boolean>(settings.discord.includeTimestamps) ?? true;
|
* @param input string to pad with 2 characters
|
||||||
const detailsPrefix =
|
* @returns
|
||||||
settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
|
*/
|
||||||
const buttonText =
|
function pad(input: string): string {
|
||||||
settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";
|
return input.padEnd(2, " ");
|
||||||
|
|
||||||
return { includeTimestamps, detailsPrefix, buttonText };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (mediaInfo.url) {
|
||||||
presence.details = `${detailsPrefix}${mediaInfo.title}`;
|
|
||||||
presence.state = mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)";
|
|
||||||
presence.largeImageKey = mediaInfo.image;
|
presence.largeImageKey = mediaInfo.image;
|
||||||
if (mediaInfo.album) {
|
if (album) presence.largeImageText = album;
|
||||||
presence.largeImageText = mediaInfo.album;
|
|
||||||
}
|
|
||||||
presence.buttons = [{ label: buttonText, url: mediaInfo.url }];
|
|
||||||
} else {
|
|
||||||
presence.details = `Watching ${mediaInfo.title}`;
|
|
||||||
presence.state = mediaInfo.artists;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function includeTimeStamps(includeTimestamps: boolean) {
|
function includeTimeStamps() {
|
||||||
if (includeTimestamps) {
|
|
||||||
const currentSeconds = convertDurationToSeconds(mediaInfo.current);
|
const currentSeconds = convertDurationToSeconds(mediaInfo.current);
|
||||||
const durationSeconds = convertDurationToSeconds(mediaInfo.duration);
|
const durationSeconds = convertDurationToSeconds(mediaInfo.duration);
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const now = (date.getTime() / 1000) | 0;
|
const now = Math.floor(date.getTime() / 1000);
|
||||||
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
|
presence.startTimestamp = now - currentSeconds;
|
||||||
presence.startTimestamp = now;
|
presence.endTimestamp = presence.startTimestamp + durationSeconds;
|
||||||
presence.endTimestamp = remaining;
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to login to RPC and retry if it errors
|
||||||
|
* @param retryCount Max retry count
|
||||||
|
*/
|
||||||
|
const connectWithRetry = async (retryCount = 0) => {
|
||||||
|
try {
|
||||||
|
await rpc.login();
|
||||||
|
Logger.log('Connected to Discord');
|
||||||
|
rpc.on("ready", updateActivity);
|
||||||
|
Object.values(globalEvents).forEach(event => ipcMain.on(event, observer));
|
||||||
|
} catch (error) {
|
||||||
|
if (retryCount < MAX_RETRIES) {
|
||||||
|
Logger.log(`Failed to connect to Discord, retrying in ${RETRY_DELAY/1000} seconds... (Attempt ${retryCount + 1}/${MAX_RETRIES})`);
|
||||||
|
setTimeout(() => connectWithRetry(retryCount + 1), RETRY_DELAY);
|
||||||
|
} else {
|
||||||
|
Logger.log('Failed to connect to Discord after maximum retry attempts');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -86,18 +103,8 @@ const getActivity = (): Presence => {
|
|||||||
* Set up the discord rpc and listen on globalEvents.updateInfo
|
* Set up the discord rpc and listen on globalEvents.updateInfo
|
||||||
*/
|
*/
|
||||||
export const initRPC = () => {
|
export const initRPC = () => {
|
||||||
rpc = new Client({ transport: "ipc" });
|
rpc = new Client({ transport: {type: "ipc"}, clientId });
|
||||||
rpc.login({ clientId }).then(
|
connectWithRetry();
|
||||||
() => {
|
|
||||||
rpc.on("ready", () => {
|
|
||||||
rpc.setActivity(getActivity());
|
|
||||||
});
|
|
||||||
ipcMain.on(globalEvents.updateInfo, observer);
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
Logger.log("Can't connect to Discord, is it running?");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +112,7 @@ export const initRPC = () => {
|
|||||||
*/
|
*/
|
||||||
export const unRPC = () => {
|
export const unRPC = () => {
|
||||||
if (rpc) {
|
if (rpc) {
|
||||||
rpc.clearActivity();
|
rpc.user?.clearActivity();
|
||||||
rpc.destroy();
|
rpc.destroy();
|
||||||
rpc = null;
|
rpc = null;
|
||||||
ipcMain.removeListener(globalEvents.updateInfo, observer);
|
ipcMain.removeListener(globalEvents.updateInfo, observer);
|
||||||
|
@@ -42,12 +42,10 @@ export const settingsStore = new Store({
|
|||||||
enableCustomHotkeys: false,
|
enableCustomHotkeys: false,
|
||||||
enableDiscord: false,
|
enableDiscord: false,
|
||||||
discord: {
|
discord: {
|
||||||
showSong: true,
|
|
||||||
idleText: "Browsing Tidal",
|
idleText: "Browsing Tidal",
|
||||||
usingText: "Playing media on TIDAL",
|
usingText: "Playing media on TIDAL",
|
||||||
includeTimestamps: true,
|
includeTimestamps: true,
|
||||||
detailsPrefix: "Listening to ",
|
detailsPrefix: "Listening to ",
|
||||||
buttonText: "Play on Tidal",
|
|
||||||
},
|
},
|
||||||
ListenBrainz: {
|
ListenBrainz: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@@ -88,16 +86,8 @@ export const settingsStore = new Store({
|
|||||||
migrationStore.get(settings.ListenBrainz.delay) ?? 5000
|
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) => {
|
"5.9.0": (migrationStore) => {
|
||||||
buildMigration("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.idleText, value: "Browsing Tidal" },
|
||||||
{
|
{
|
||||||
key: settings.discord.usingText,
|
key: settings.discord.usingText,
|
||||||
@@ -114,7 +104,7 @@ export const settingsStore = new Store({
|
|||||||
buildMigration("5.15.0", migrationStore, [
|
buildMigration("5.15.0", migrationStore, [
|
||||||
{ key: settings.advanced.tidalUrl, value: "https://listen.tidal.com" },
|
{ key: settings.advanced.tidalUrl, value: "https://listen.tidal.com" },
|
||||||
]);
|
]);
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user