From 1a0c15e17fd79202fd4144077ae8a3a28d464c11 Mon Sep 17 00:00:00 2001 From: 3top1a <3top1a.official@gmail.com> Date: Wed, 16 Oct 2024 20:37:47 +0200 Subject: [PATCH 1/4] Maybe? Can't build --- package-lock.json | 33 +++++++++++--------------------- package.json | 5 ++--- src/scripts/discord.ts | 12 +++++++----- src/types/discord-rpc.d.ts | 39 ++++++++++++++++++++++++++++++++++++++ tsconfig.json | 1 + 5 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 src/types/discord-rpc.d.ts diff --git a/package-lock.json b/package-lock.json index 67ba00e..b19fbb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@types/swagger-jsdoc": "^6.0.4", "axios": "^1.7.7", "cors": "^2.8.5", - "discord-rpc": "^4.0.1", + "discord-rpc": "github:sKiLdUsT/RPC#types", "electron-store": "^8.2.0", "express": "^4.21.1", "hotkeys-js": "^3.13.7", @@ -25,7 +25,6 @@ "devDependencies": { "@mastermindzh/prettier-config": "^1.0.0", "@types/cors": "^2.8.17", - "@types/discord-rpc": "^4.0.8", "@types/express": "^4.17.21", "@types/node": "^20.14.10", "@types/request": "^2.48.12", @@ -33,7 +32,7 @@ "@typescript-eslint/eslint-plugin": "^7.16.0", "@typescript-eslint/parser": "^7.15.0", "copyfiles": "^2.4.1", - "electron": "git+https://github.com/castlabs/electron-releases#v31.1.0+wvcus", + "electron": "git+https://github.com/castlabs/electron-releases#v33.1.0+wvcus", "electron-builder": "~24.9.4", "eslint": "^8.57.0", "js-yaml": "^4.1.0", @@ -1230,21 +1229,6 @@ "@types/ms": "*" } }, - "node_modules/@types/discord-rpc": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/@types/discord-rpc/-/discord-rpc-4.0.8.tgz", - "integrity": "sha512-1tZf217Natkj+TziNXRRLwNmdm5GNa1bnrQr8VWowquo/Su5hMjdhobj8URxW1COMk2da28XCU1ahsYCAlxirA==", - "dev": true, - "dependencies": { - "@types/events": "*" - } - }, - "node_modules/@types/events": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.3.tgz", - "integrity": "sha512-trOc4AAUThEz9hapPtSd7wf5tiQKvTtu5b371UxXdTuqzIh0ArcRspRP0i0Viu+LXstIQ1z96t1nsPxT9ol01g==", - "dev": true - }, "node_modules/@types/express": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz", @@ -3382,8 +3366,8 @@ }, "node_modules/discord-rpc": { "version": "4.0.1", - "resolved": "https://registry.npmjs.org/discord-rpc/-/discord-rpc-4.0.1.tgz", - "integrity": "sha512-HOvHpbq5STRZJjQIBzwoKnQ0jHplbEWFWlPDwXXKm/bILh4nzjcg7mNqll0UY7RsjFoaXA7e/oYb/4lvpda2zA==", + "resolved": "git+ssh://git@github.com/sKiLdUsT/RPC.git#1c5b6842fa586a1b7b339a50fa5ec1c4cf6c8867", + "license": "MIT", "dependencies": { "node-fetch": "^2.6.1", "ws": "^7.3.1" @@ -6152,6 +6136,7 @@ "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -8532,7 +8517,8 @@ "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" }, "node_modules/truncate-utf8-bytes": { "version": "1.0.2", @@ -8819,12 +8805,14 @@ "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" }, "node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -8903,6 +8891,7 @@ "version": "7.5.10", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "license": "MIT", "engines": { "node": ">=8.3.0" }, diff --git a/package.json b/package.json index 2aa8b87..a79097b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@types/swagger-jsdoc": "^6.0.4", "axios": "^1.7.7", "cors": "^2.8.5", - "discord-rpc": "^4.0.1", + "discord-rpc": "github:sKiLdUsT/RPC#types", "electron-store": "^8.2.0", "express": "^4.21.1", "hotkeys-js": "^3.13.7", @@ -56,7 +56,6 @@ "devDependencies": { "@mastermindzh/prettier-config": "^1.0.0", "@types/cors": "^2.8.17", - "@types/discord-rpc": "^4.0.8", "@types/express": "^4.17.21", "@types/node": "^20.14.10", "@types/request": "^2.48.12", @@ -64,7 +63,7 @@ "@typescript-eslint/eslint-plugin": "^7.16.0", "@typescript-eslint/parser": "^7.15.0", "copyfiles": "^2.4.1", - "electron": "git+https://github.com/castlabs/electron-releases#v31.1.0+wvcus", + "electron": "git+https://github.com/castlabs/electron-releases#v32.0.0+wvcus", "electron-builder": "~24.9.4", "eslint": "^8.57.0", "js-yaml": "^4.1.0", diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index 4a162a6..6fc06e2 100644 --- a/src/scripts/discord.ts +++ b/src/scripts/discord.ts @@ -1,4 +1,4 @@ -import { Client, Presence } from "discord-rpc"; +import * as DRPC from "discord-rpc"; import { app, ipcMain } from "electron"; import { globalEvents } from "../constants/globalEvents"; import { settings } from "../constants/settings"; @@ -10,7 +10,7 @@ import { settingsStore } from "./settings"; const clientId = "833617820704440341"; -export let rpc: Client; +export let rpc: DRPC.Client; const observer = () => { if (rpc) { @@ -33,8 +33,10 @@ const updateActivity = () => { } }; -const getActivity = (): Presence => { - const presence: Presence = { ...defaultPresence }; +const getActivity = (): DRPC.Presence => { + const presence: DRPC.Presence = { ...defaultPresence }; + + presence.type = DRPC.ActivityTypes.LISTENING if (mediaInfo.status === MediaStatus.paused) { presence.details = @@ -110,7 +112,7 @@ const getActivity = (): Presence => { * Set up the discord rpc and listen on globalEvents.updateInfo */ export const initRPC = () => { - rpc = new Client({ transport: "ipc" }); + rpc = new DRPC.Client({ transport: "ipc" }); rpc.login({ clientId }).then( () => { rpc.on("ready", () => { diff --git a/src/types/discord-rpc.d.ts b/src/types/discord-rpc.d.ts new file mode 100644 index 0000000..e66c00c --- /dev/null +++ b/src/types/discord-rpc.d.ts @@ -0,0 +1,39 @@ +declare module 'discord-rpc' { + export class Client { + constructor(options: { transport: 'ipc' }); + on(event: string, listener: (...args: any[]) => void): this; + login(options: { clientId: string }): Promise; + setActivity(presence: Presence): Promise; + clearActivity(): Promise; + destroy(): Promise; + } + + export interface Presence { + state?: string; + details?: string; + startTimestamp?: number; + endTimestamp?: number; + largeImageKey?: string; + largeImageText?: string; + smallImageKey?: string; + smallImageText?: string; + partyId?: string; + partySize?: number; + partyMax?: number; + matchSecret?: string; + spectateSecret?: string; + joinSecret?: string; + instance?: boolean; + type?: number; + buttons?: Array<{ label: string; url: string }>; + } + + export const ActivityTypes: { + PLAYING: 0, + STREAMING: 1, + LISTENING: 2, + WATCHING: 3, + CUSTOM: 4, + COMPETING: 5 + }; +} diff --git a/tsconfig.json b/tsconfig.json index 89364cb..5440346 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "resolveJsonModule": true, "esModuleInterop": true, "baseUrl": ".", + "allowSyntheticDefaultImports": true, "paths": { "*": ["node_modules/*"] } From b1830f56842c32d6ef4e1ac334e12ecac1da4271 Mon Sep 17 00:00:00 2001 From: 3top1a <3top1a.official@gmail.com> Date: Thu, 17 Oct 2024 20:16:22 +0200 Subject: [PATCH 2/4] Fixed impl --- package-lock.json | 2 +- src/scripts/discord.ts | 20 ++++++++++++-------- src/scripts/settings.ts | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index b19fbb5..64263a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "@typescript-eslint/eslint-plugin": "^7.16.0", "@typescript-eslint/parser": "^7.15.0", "copyfiles": "^2.4.1", - "electron": "git+https://github.com/castlabs/electron-releases#v33.1.0+wvcus", + "electron": "git+https://github.com/castlabs/electron-releases#v32.0.0+wvcus", "electron-builder": "~24.9.4", "eslint": "^8.57.0", "js-yaml": "^4.1.0", diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index 6fc06e2..a61c40b 100644 --- a/src/scripts/discord.ts +++ b/src/scripts/discord.ts @@ -12,6 +12,8 @@ const clientId = "833617820704440341"; export let rpc: DRPC.Client; +const ACTIVITY_LISTENING = 2; + const observer = () => { if (rpc) { updateActivity(); @@ -20,7 +22,7 @@ const observer = () => { const defaultPresence = { largeImageKey: "tidal-hifi-icon", - largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`, + largeImageText: `Tidal`, instance: false, }; @@ -36,7 +38,7 @@ const updateActivity = () => { const getActivity = (): DRPC.Presence => { const presence: DRPC.Presence = { ...defaultPresence }; - presence.type = DRPC.ActivityTypes.LISTENING + presence.type = ACTIVITY_LISTENING; if (mediaInfo.status === MediaStatus.paused) { presence.details = @@ -52,13 +54,14 @@ const getActivity = (): DRPC.Presence => { settingsStore.get(settings.discord.usingText) ?? "Playing media on TIDAL"; } } + return presence; function getFromStore() { const includeTimestamps = settingsStore.get(settings.discord.includeTimestamps) ?? true; const detailsPrefix = - settingsStore.get(settings.discord.detailsPrefix) ?? "Listening to "; + settingsStore.get(settings.discord.detailsPrefix) ?? ""; const buttonText = settingsStore.get(settings.discord.buttonText) ?? "Play on TIDAL"; @@ -100,12 +103,13 @@ const getActivity = (): DRPC.Presence => { const currentSeconds = convertDurationToSeconds(mediaInfo.current); const durationSeconds = convertDurationToSeconds(mediaInfo.duration); 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 now = Math.floor(date.getTime() / 1000); + const startTimestamp = now - currentSeconds; + const endTimestamp = startTimestamp + durationSeconds; + presence.startTimestamp = startTimestamp; + presence.endTimestamp = endTimestamp; } - } + } }; /** diff --git a/src/scripts/settings.ts b/src/scripts/settings.ts index 4e5323a..8e7b296 100644 --- a/src/scripts/settings.ts +++ b/src/scripts/settings.ts @@ -47,7 +47,7 @@ export const settingsStore = new Store({ idleText: "Browsing Tidal", usingText: "Playing media on TIDAL", includeTimestamps: true, - detailsPrefix: "Listening to ", + detailsPrefix: "", buttonText: "Play on Tidal", }, ListenBrainz: { From 3dc42eceb067f56de7a645af7ae2526ac84f8f43 Mon Sep 17 00:00:00 2001 From: 3top1a <3top1a.official@gmail.com> Date: Thu, 17 Oct 2024 20:47:40 +0200 Subject: [PATCH 3/4] Reverted bad changes --- src/scripts/discord.ts | 4 ++-- src/scripts/settings.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index a61c40b..d092e24 100644 --- a/src/scripts/discord.ts +++ b/src/scripts/discord.ts @@ -22,7 +22,7 @@ const observer = () => { const defaultPresence = { largeImageKey: "tidal-hifi-icon", - largeImageText: `Tidal`, + largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`, instance: false, }; @@ -61,7 +61,7 @@ const getActivity = (): DRPC.Presence => { const includeTimestamps = settingsStore.get(settings.discord.includeTimestamps) ?? true; const detailsPrefix = - settingsStore.get(settings.discord.detailsPrefix) ?? ""; + settingsStore.get(settings.discord.detailsPrefix) ?? "Listening to "; const buttonText = settingsStore.get(settings.discord.buttonText) ?? "Play on TIDAL"; diff --git a/src/scripts/settings.ts b/src/scripts/settings.ts index 8e7b296..4e5323a 100644 --- a/src/scripts/settings.ts +++ b/src/scripts/settings.ts @@ -47,7 +47,7 @@ export const settingsStore = new Store({ idleText: "Browsing Tidal", usingText: "Playing media on TIDAL", includeTimestamps: true, - detailsPrefix: "", + detailsPrefix: "Listening to ", buttonText: "Play on Tidal", }, ListenBrainz: { From 21edcd6ad5e4d88b4a54bf653e5275b8ce97c55d Mon Sep 17 00:00:00 2001 From: 3top1a <3top1a.official@gmail.com> Date: Thu, 17 Oct 2024 20:51:23 +0200 Subject: [PATCH 4/4] reverted more ugly/unnecessary changes --- package-lock.json | 2 +- package.json | 2 +- src/scripts/discord.ts | 2 +- tsconfig.json | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 64263a7..85d174f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "@typescript-eslint/eslint-plugin": "^7.16.0", "@typescript-eslint/parser": "^7.15.0", "copyfiles": "^2.4.1", - "electron": "git+https://github.com/castlabs/electron-releases#v32.0.0+wvcus", + "electron": "git+https://github.com/castlabs/electron-releases#v31.1.0+wvcus", "electron-builder": "~24.9.4", "eslint": "^8.57.0", "js-yaml": "^4.1.0", diff --git a/package.json b/package.json index a79097b..9bd83db 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@typescript-eslint/eslint-plugin": "^7.16.0", "@typescript-eslint/parser": "^7.15.0", "copyfiles": "^2.4.1", - "electron": "git+https://github.com/castlabs/electron-releases#v32.0.0+wvcus", + "electron": "git+https://github.com/castlabs/electron-releases#v31.1.0+wvcus", "electron-builder": "~24.9.4", "eslint": "^8.57.0", "js-yaml": "^4.1.0", diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index d092e24..c9c058e 100644 --- a/src/scripts/discord.ts +++ b/src/scripts/discord.ts @@ -109,7 +109,7 @@ const getActivity = (): DRPC.Presence => { presence.startTimestamp = startTimestamp; presence.endTimestamp = endTimestamp; } - } + } }; /** diff --git a/tsconfig.json b/tsconfig.json index 5440346..89364cb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,6 @@ "resolveJsonModule": true, "esModuleInterop": true, "baseUrl": ".", - "allowSyntheticDefaultImports": true, "paths": { "*": ["node_modules/*"] }