diff --git a/plugins/DiscordRPC/package-lock.json b/plugins/DiscordRPC/package-lock.json index eb22152..3ca6c65 100644 --- a/plugins/DiscordRPC/package-lock.json +++ b/plugins/DiscordRPC/package-lock.json @@ -5,15 +5,13 @@ "packages": { "": { "dependencies": { - "@inrixia/lib": "../_lib", - "discord-rpc": "^4.0.1" - }, - "devDependencies": { - "@types/discord-rpc": "^4.0.8" + "@inrixia/lib": "../_lib" } }, "../_lib": { + "name": "@inrixia/lib", "dependencies": { + "flac-stream-tagger": "^1.0.9", "idb": "^8.0.0", "music-metadata": "^7.14.0" } @@ -21,134 +19,6 @@ "node_modules/@inrixia/lib": { "resolved": "../_lib", "link": true - }, - "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, - "license": "MIT", - "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, - "license": "MIT" - }, - "node_modules/bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "license": "MIT", - "optional": true, - "dependencies": { - "file-uri-to-path": "1.0.0" - } - }, - "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==", - "license": "MIT", - "dependencies": { - "node-fetch": "^2.6.1", - "ws": "^7.3.1" - }, - "optionalDependencies": { - "register-scheme": "github:devsnek/node-register-scheme" - } - }, - "node_modules/file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "license": "MIT", - "optional": true - }, - "node_modules/node-addon-api": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz", - "integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==", - "license": "MIT", - "optional": true - }, - "node_modules/node-fetch": { - "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" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, - "node_modules/register-scheme": { - "version": "0.0.2", - "resolved": "git+ssh://git@github.com/devsnek/node-register-scheme.git#e7cc9a63a1f512565da44cb57316d9fb10750e17", - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "dependencies": { - "bindings": "^1.3.0", - "node-addon-api": "^1.3.0" - } - }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "license": "MIT" - }, - "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==", - "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" - } - }, - "node_modules/ws": { - "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" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } } } } diff --git a/plugins/DiscordRPC/package.json b/plugins/DiscordRPC/package.json index 91e4ea3..6625568 100644 --- a/plugins/DiscordRPC/package.json +++ b/plugins/DiscordRPC/package.json @@ -1,9 +1,5 @@ { "dependencies": { - "@inrixia/lib": "../_lib", - "discord-rpc": "^4.0.1" - }, - "devDependencies": { - "@types/discord-rpc": "^4.0.8" + "@inrixia/lib": "../_lib" } } diff --git a/plugins/DiscordRPC/src/index.ts b/plugins/DiscordRPC/src/index.ts index 675e040..575d6f7 100644 --- a/plugins/DiscordRPC/src/index.ts +++ b/plugins/DiscordRPC/src/index.ts @@ -8,7 +8,7 @@ export { Settings } from "./Settings"; import getPlaybackControl from "@inrixia/lib/getPlaybackControl"; import { TrackItemCache } from "@inrixia/lib/Caches/TrackItemCache"; -import { onRpcCleanup, updateRPC } from "./updateRPC.native"; +import { onRpcCleanup, updateRPC } from "@inrixia/lib/nativeBridge"; import { type PlaybackContext } from "@inrixia/lib/AudioQualityTypes"; let currentPlaybackContext: PlaybackContext | undefined; @@ -27,7 +27,6 @@ const onUnloadTimeUpdate = intercept("playbackControls/TIME_UPDATE", ([newTime]) }); const onUnloadNewTrack = intercept("playbackControls/MEDIA_PRODUCT_TRANSITION", ([{ playbackContext }]) => { currentPlaybackContext = playbackContext; - console.log("SET", currentPlaybackContext?.actualProductId); onTimeUpdate(settings.keepRpcOnPause).catch(trace.msg.err.withContext("Failed to update")); }); onTimeUpdate(settings.keepRpcOnPause).catch(trace.msg.err.withContext("Failed to update")); diff --git a/plugins/_lib/nativeBridge/broadcast.native.ts b/plugins/_lib/nativeBridge/broadcast.native.ts new file mode 100644 index 0000000..f471bf4 --- /dev/null +++ b/plugins/_lib/nativeBridge/broadcast.native.ts @@ -0,0 +1,6 @@ +// @ts-nocheck +export const broadcast = (channel: string, ...args: any[]) => { + for (const window of electron.BrowserWindow.getAllWindows()) { + window.webContents.send(channel, ...args); + } +}; diff --git a/plugins/_lib/nativeBridge/index.ts b/plugins/_lib/nativeBridge/index.ts index 81f5fa0..4d8bbba 100644 --- a/plugins/_lib/nativeBridge/index.ts +++ b/plugins/_lib/nativeBridge/index.ts @@ -30,3 +30,5 @@ export const startTrackDownload = invoke("startTrackDownload"); export const saveDialog = invoke("saveDialog"); export const openDialog = invoke("openDialog"); export const getDownloadProgress = invoke("getDownloadProgress"); +export const updateRPC = invoke("updateRPC"); +export const onRpcCleanup = invoke("onRpcCleanup"); diff --git a/plugins/DiscordRPC/src/DiscordRPC.native.ts b/plugins/_lib/nativeBridge/native/discordRPC/DiscordRPC.native.ts similarity index 100% rename from plugins/DiscordRPC/src/DiscordRPC.native.ts rename to plugins/_lib/nativeBridge/native/discordRPC/DiscordRPC.native.ts diff --git a/plugins/_lib/nativeBridge/native/discordRPC/index.ts b/plugins/_lib/nativeBridge/native/discordRPC/index.ts new file mode 100644 index 0000000..62e98a5 --- /dev/null +++ b/plugins/_lib/nativeBridge/native/discordRPC/index.ts @@ -0,0 +1 @@ +export * from "./updateRPC.native"; diff --git a/plugins/DiscordRPC/src/updateRPC.native.ts b/plugins/_lib/nativeBridge/native/discordRPC/updateRPC.native.ts similarity index 100% rename from plugins/DiscordRPC/src/updateRPC.native.ts rename to plugins/_lib/nativeBridge/native/discordRPC/updateRPC.native.ts diff --git a/plugins/_lib/nativeBridge/native/index.ts b/plugins/_lib/nativeBridge/native/index.ts index 8aec824..0f00a79 100644 --- a/plugins/_lib/nativeBridge/native/index.ts +++ b/plugins/_lib/nativeBridge/native/index.ts @@ -1,4 +1,5 @@ export * from "./request"; +export * from "./discordRPC"; export * from "./dasha.native"; export * from "./getTrackInfo.native"; export * from "./crypto.native"; diff --git a/plugins/_lib/nativeBridge/nativeBridge.native.ts b/plugins/_lib/nativeBridge/nativeBridge.native.ts index 388a522..5e40b9f 100644 --- a/plugins/_lib/nativeBridge/nativeBridge.native.ts +++ b/plugins/_lib/nativeBridge/nativeBridge.native.ts @@ -1,6 +1,6 @@ // @ts-nocheck import * as nativeBridge from "./native"; -electron.ipcMain.removeAllListeners("___nativeBridge___"); +electron.ipcMain.removeHandler("___nativeBridge___"); electron.ipcMain.handle("___nativeBridge___", (_, method: string, ...args) => { if (nativeBridge[method] === undefined) throw new Error(`Method "${method}" not found! Available methods: ${Object.keys(nativeBridge).join(", ")}.`); return nativeBridge[method](...args); diff --git a/plugins/_lib/nativeBridge/trace.native.ts b/plugins/_lib/nativeBridge/trace.native.ts new file mode 100644 index 0000000..18e74d1 --- /dev/null +++ b/plugins/_lib/nativeBridge/trace.native.ts @@ -0,0 +1,35 @@ +import { broadcast } from "./broadcast.native"; + +type LoggerFunc = (...data: any[]) => void; + +type Logger = { + (...data: Parameters): undefined; + withContext(context: string): (...data: Parameters) => undefined; +}; + +export const Tracer = (source: string) => { + const createLogger = (logger: T): Logger => { + const _logger = (...data: Parameters) => { + logger("native", source, ...data); + return undefined; + }; + _logger.withContext = + (context: string) => + (...data: Parameters) => { + logger("native", source, context, ...data); + return undefined; + }; + return _logger; + }; + + const log = createLogger((...args) => broadcast("NEPTUNE_RENDERER_LOG", "log", ...args)); + const warn = createLogger((...args) => broadcast("NEPTUNE_RENDERER_LOG", "warn", ...args)); + const err = createLogger((...args) => broadcast("NEPTUNE_RENDERER_LOG", "error", ...args)); + + return { + log, + warn, + err, + }; +}; +export const libTrace = Tracer("[lib]"); diff --git a/plugins/_lib/nativeBridge/whereami.ts b/plugins/_lib/nativeBridge/whereami.ts new file mode 100644 index 0000000..87f0384 --- /dev/null +++ b/plugins/_lib/nativeBridge/whereami.ts @@ -0,0 +1,2 @@ +export const inRenderer = globalThis?.process === undefined; +export const inNative = !inRenderer; diff --git a/plugins/_lib/package-lock.json b/plugins/_lib/package-lock.json index b827228..8d898be 100644 --- a/plugins/_lib/package-lock.json +++ b/plugins/_lib/package-lock.json @@ -6,9 +6,13 @@ "": { "name": "@inrixia/lib", "dependencies": { + "discord-rpc": "^4.0.1", "flac-stream-tagger": "^1.0.9", "idb": "^8.0.0", "music-metadata": "^7.14.0" + }, + "devDependencies": { + "@types/discord-rpc": "^4.0.8" } }, "node_modules/@tokenizer/token": { @@ -17,6 +21,33 @@ "integrity": "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==", "license": "MIT" }, + "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, + "license": "MIT", + "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, + "license": "MIT" + }, + "node_modules/bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "license": "MIT", + "optional": true, + "dependencies": { + "file-uri-to-path": "1.0.0" + } + }, "node_modules/content-type": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", @@ -43,6 +74,19 @@ } } }, + "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==", + "license": "MIT", + "dependencies": { + "node-fetch": "^2.6.1", + "ws": "^7.3.1" + }, + "optionalDependencies": { + "register-scheme": "github:devsnek/node-register-scheme" + } + }, "node_modules/file-type": { "version": "16.5.4", "resolved": "https://registry.npmjs.org/file-type/-/file-type-16.5.4.tgz", @@ -60,6 +104,13 @@ "url": "https://github.com/sindresorhus/file-type?sponsor=1" } }, + "node_modules/file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "license": "MIT", + "optional": true + }, "node_modules/flac-stream-tagger": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/flac-stream-tagger/-/flac-stream-tagger-1.0.9.tgz", @@ -146,6 +197,33 @@ "url": "https://github.com/sponsors/Borewit" } }, + "node_modules/node-addon-api": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz", + "integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==", + "license": "MIT", + "optional": true + }, + "node_modules/node-fetch": { + "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" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/peek-readable": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-4.1.0.tgz", @@ -189,6 +267,17 @@ "url": "https://github.com/sponsors/Borewit" } }, + "node_modules/register-scheme": { + "version": "0.0.2", + "resolved": "git+ssh://git@github.com/devsnek/node-register-scheme.git#e7cc9a63a1f512565da44cb57316d9fb10750e17", + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "dependencies": { + "bindings": "^1.3.0", + "node-addon-api": "^1.3.0" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -252,11 +341,54 @@ "url": "https://github.com/sponsors/Borewit" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "license": "MIT" + }, + "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==", + "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" + } + }, + "node_modules/ws": { + "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" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } } } } diff --git a/plugins/_lib/package.json b/plugins/_lib/package.json index 92f3009..24f1ce9 100644 --- a/plugins/_lib/package.json +++ b/plugins/_lib/package.json @@ -1,8 +1,12 @@ { "name": "@inrixia/lib", "dependencies": { + "discord-rpc": "^4.0.1", "flac-stream-tagger": "^1.0.9", "idb": "^8.0.0", "music-metadata": "^7.14.0" + }, + "devDependencies": { + "@types/discord-rpc": "^4.0.8" } }