diff --git a/package-lock.json b/package-lock.json index 3ce905c..04e82db 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", @@ -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", @@ -3388,8 +3372,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" @@ -6162,6 +6146,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" }, @@ -8575,7 +8560,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", @@ -8862,12 +8848,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" @@ -8946,6 +8934,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 d2e72ff..3a64fc4 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", diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index 4a162a6..c9c058e 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,9 @@ import { settingsStore } from "./settings"; const clientId = "833617820704440341"; -export let rpc: Client; +export let rpc: DRPC.Client; + +const ACTIVITY_LISTENING = 2; const observer = () => { if (rpc) { @@ -33,8 +35,10 @@ const updateActivity = () => { } }; -const getActivity = (): Presence => { - const presence: Presence = { ...defaultPresence }; +const getActivity = (): DRPC.Presence => { + const presence: DRPC.Presence = { ...defaultPresence }; + + presence.type = ACTIVITY_LISTENING; if (mediaInfo.status === MediaStatus.paused) { presence.details = @@ -50,6 +54,7 @@ const getActivity = (): Presence => { settingsStore.get(settings.discord.usingText) ?? "Playing media on TIDAL"; } } + return presence; function getFromStore() { @@ -98,10 +103,11 @@ const getActivity = (): 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; } } }; @@ -110,7 +116,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 + }; +}