Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JustYuuto committed Nov 23, 2024
1 parent 81d0f74 commit d9596b0
Show file tree
Hide file tree
Showing 8 changed files with 965 additions and 524 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.3.0

* Removed the "Playing" status, now it will always show "Listening to"
* Removed the "Only show if playing" option
* Updated Chrome user agent to version 133
* Updated packages
* Fixed some things

## 1.2.8

* Fixed the app not working because of Deezer and Discord changes
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deezer-discord-rpc",
"version": "1.2.8",
"version": "1.3.0",
"description": "A Discord RPC for Deezer",
"main": "./build/src/index.js",
"scripts": {
Expand All @@ -13,25 +13,24 @@
"copy-assets": "cpy ./src/img/* ./build/src/img/"
},
"dependencies": {
"@cliqz/adblocker-electron": "^1.27.1",
"@ghostery/adblocker-electron": "^2.1.1",
"@xhayper/discord-rpc": "^1.2.0",
"axios": "^1.6.8",
"chalk": "4.1.2",
"discord.js-selfbot-v13": "^2.14.9"
"axios": "^1.7.7",
"chalk": "4.1.2"
},
"devDependencies": {
"@types/discord-rpc": "^4.0.8",
"@types/node": "^20.12.7",
"@types/node": "^22.9.2",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"cpy-cli": "^5.0.0",
"electron": "^30.0.1",
"electron-builder": "^24.13.3",
"electron": "^33.2.0",
"electron-builder": "^25.1.8",
"eslint": "^8.56.0",
"fs-extra": "^11.2.0",
"png-to-ico": "^2.1.4",
"png-to-ico": "^2.1.8",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
"typescript": "^5.7.2"
},
"repository": "https://github.com/JustYuuto/deezer-discord-rpc.git",
"author": {
Expand Down
19 changes: 9 additions & 10 deletions src/utils/Activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { ActivityType } from 'discord-api-types/v10';
export async function setActivity(options: {
client: import('@xhayper/discord-rpc').Client, albumId: number, trackId: string, playing: boolean, timeLeft: number,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
trackTitle: string, trackArtists: any, albumCover: string, albumTitle: string, app: Electron.App, type: string
trackTitle: string, trackArtists: any, albumCover: string, albumTitle: string, app: Electron.App, type: string,
songTime: number
}) {
const {
timeLeft, playing, client, albumTitle, trackArtists, trackTitle,
albumCover, app, type, trackId
albumCover, app, type, trackId, songTime
} = options;
const tooltipText = Config.get(app, 'tooltip_text');
switch (tooltipText) {
Expand All @@ -32,10 +33,8 @@ export async function setActivity(options: {
}
if (!client) return;

if (Config.get(app, 'only_show_if_playing') && !playing) {
await client.user.clearActivity();
return;
}
if (!playing)
return await client.user.clearActivity();

const getTrackLink = () => {
switch (type) {
Expand All @@ -48,16 +47,16 @@ export async function setActivity(options: {

const button = (getTrackLink() && parseInt(trackId) > 0) && { label: 'Play on Deezer', url: getTrackLink() };
const isLivestream = (Date.now() + timeLeft) < Date.now();
const useListening = Config.get(app, 'use_listening_to');
const playedTime = Date.now() - songTime + timeLeft;
client.user.setActivity({
type: useListening ? ActivityType.Listening : ActivityType.Playing,
type: ActivityType.Listening,
details: trackTitle,
state: trackArtists,
largeImageKey: albumCover,
largeImageText: albumTitle,
instance: false,
startTimestamp: playing && Date.now(),
[isLivestream ? 'startTimestamp' : 'endTimestamp']: playing && Date.now() + timeLeft,
startTimestamp: playedTime,
[isLivestream ? 'startTimestamp' : 'endTimestamp']: Date.now() + timeLeft,
buttons: button ? [button] : undefined,
}).catch(() => {});
}
4 changes: 2 additions & 2 deletions src/utils/AdBlock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ElectronBlocker, fullLists } from '@cliqz/adblocker-electron';
import { ElectronBlocker, fullLists } from '@ghostery/adblocker-electron';
import { join } from 'path';
import { readFileSync, writeFileSync } from 'fs';

export default async function (app: Electron.App, win: Electron.BrowserWindow) {
const blocker = await ElectronBlocker.fromLists(fetch, fullLists, {
enableCompression: true
enableCompression: true,
}, {
path: join(app.getPath('userData'), 'engine.bin'),
read: async (...args) => readFileSync(...args),
Expand Down
14 changes: 0 additions & 14 deletions src/utils/Tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export async function init(app: Electron.App, client: import('@xhayper/discord-r
click: (menuItem) => Config.set(app, 'tooltip_text', menuItem.id)
}))
},
{
label: 'Only show RPC if music is playing', type: 'checkbox', checked: Config.get(app, 'only_show_if_playing'),
click: (menuItem) => Config.set(app, 'only_show_if_playing', menuItem.checked)
},
{
label: 'Don\'t close to tray', type: 'checkbox', checked: Config.get(app, 'dont_close_to_tray'),
click: (menuItem) => Config.set(app, 'dont_close_to_tray', menuItem.checked)
Expand All @@ -51,16 +47,6 @@ export async function init(app: Electron.App, client: import('@xhayper/discord-r
.catch(console.error);
}
},
{
label: 'Use "Listening to" instead of "Playing"', type: 'checkbox', checked: Config.get(app, 'use_listening_to'),
click: async (menuItem) => {
Config.set(app, 'use_listening_to', menuItem.checked);
if (menuItem.checked) {
await RPC.disconnect();
await RPC.connect();
}
}
},
{ type: 'separator' },
{
label: 'Quit', type: 'normal', click: async () => {
Expand Down
34 changes: 14 additions & 20 deletions src/utils/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,13 @@ export async function load(app: Electron.App) {
});

session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
if (details.url.includes('deezer.com')) {
if (details.url.includes('deezer.com'))
details.requestHeaders['User-Agent'] = userAgent;
}
if (details.url.startsWith('https://www.deezer.com/ajax/gw-light.php?method=deezer.adConfig')) // Remove ads
return callback({ cancel: true });
callback({ cancel: false, requestHeaders: details.requestHeaders });
});

session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
// delete details.responseHeaders['cross-origin-opener-policy'];
// delete details.responseHeaders['cross-origin-opener-policy-report-only'];
callback({ cancel: false, responseHeaders: details.responseHeaders });
});

win.on('resized', () => {
const [w, h] = win.getSize();
Config.set(app, 'window_width', w);
Expand Down Expand Up @@ -98,7 +93,7 @@ export async function load(app: Electron.App) {
const playingObserver = new MutationObserver(() => ipcRenderer.send('update_activity', false));
playingObserver.observe(document.querySelector('.chakra-button__group > button[data-testid^="play_button_"]'), { childList: true, subtree: true });`);
ipcMain.on('update_activity', (e, currentTimeChanged) => updateActivity(app, currentTimeChanged));
runJs(`const chakraStack = document.querySelector('#dzr-app > div > div.css-efpag6 > div.chakra-stack.css-w8kdg9');
runJs(`const chakraStack = document.querySelector('#dzr-app > .naboo > div > div > a.chakra-link');
const navContainer = document.createElement('div');
navContainer.style.display = 'flex';
navContainer.style.justifyContent = 'space-around';
Expand All @@ -114,16 +109,16 @@ export async function load(app: Electron.App) {
forwardButton.style.opacity = '30%';
navContainer.appendChild(backButton);
navContainer.appendChild(forwardButton);
chakraStack.children[0].replaceWith(navContainer);`);
ipcMain.on('nav_back', () => win.webContents.goBack());
ipcMain.on('nav_forward', () => win.webContents.goForward());
chakraStack.replaceWith(navContainer);`);
ipcMain.on('nav_back', () => win.webContents.navigationHistory.goBack());
ipcMain.on('nav_forward', () => win.webContents.navigationHistory.goForward());
win.webContents.on('did-stop-loading', () => {
if (win.webContents.canGoBack()) {
if (win.webContents.navigationHistory.canGoBack()) {
runJs('backButton.style.opacity = \'100%\';');
} else {
runJs('backButton.style.opacity = \'30%\';');
}
if (win.webContents.canGoForward()) {
if (win.webContents.navigationHistory.canGoForward()) {
runJs('forwardButton.style.opacity = \'100%\';');
} else {
runJs('forwardButton.style.opacity = \'30%\';');
Expand Down Expand Up @@ -207,13 +202,11 @@ async function updateActivity(app: Electron.App, currentTimeChanged?: boolean) {
currentTrack?.trackTitle !== result.trackName || currentTrack?.playing !== result.playing || currentTimeChanged === true ||
currentTrack?.songTime !== realSongTime
) {
let reason;
if (currentTrack?.trackTitle !== result.trackName) {
let reason = '';
if (currentTrack?.trackTitle !== result.trackName)
reason = UpdateReason.MUSIC_CHANGED;
}
else if (currentTrack?.playing !== result.playing) {
else if (currentTrack?.playing !== result.playing)
reason = result.playing ? UpdateReason.MUSIC_PLAYED : UpdateReason.MUSIC_PAUSED;
}
else if (currentTimeChanged && currentTimeChanged === true) reason = UpdateReason.MUSIC_TIME_CHANGED;
else if (currentTrack?.songTime !== realSongTime) reason = UpdateReason.MUSIC_NOT_RIGHT_TIME;
log('Activity', 'Updating because', reason);
Expand All @@ -228,7 +221,8 @@ async function updateActivity(app: Electron.App, currentTimeChanged?: boolean) {
};

await setActivity({
client, albumId: result.albumId, timeLeft: result.timeLeft, app, ...currentTrack, type: result.mediaType
client, albumId: result.albumId, timeLeft: result.timeLeft, app, ...currentTrack, type: result.mediaType,
songTime: realSongTime
}).then(() => log('Activity', 'Updated'));
}
currentTrack.songTime = realSongTime;
Expand Down
2 changes: 1 addition & 1 deletion src/variables.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const clientId = '1258131430928547880';
export const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
export const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36';
Loading

0 comments on commit d9596b0

Please sign in to comment.