Skip to content

Commit

Permalink
lib - trace.native, discordRPC.native
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Jun 26, 2024
1 parent b5d03d1 commit a4bec09
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 141 deletions.
136 changes: 3 additions & 133 deletions plugins/DiscordRPC/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions plugins/DiscordRPC/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"dependencies": {
"@inrixia/lib": "../_lib",
"discord-rpc": "^4.0.1"
},
"devDependencies": {
"@types/discord-rpc": "^4.0.8"
"@inrixia/lib": "../_lib"
}
}
3 changes: 1 addition & 2 deletions plugins/DiscordRPC/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +27,6 @@ const onUnloadTimeUpdate = intercept("playbackControls/TIME_UPDATE", ([newTime])
});
const onUnloadNewTrack = intercept("playbackControls/MEDIA_PRODUCT_TRANSITION", ([{ playbackContext }]) => {
currentPlaybackContext = <any>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"));
Expand Down
6 changes: 6 additions & 0 deletions plugins/_lib/nativeBridge/broadcast.native.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};
2 changes: 2 additions & 0 deletions plugins/_lib/nativeBridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/_lib/nativeBridge/native/discordRPC/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./updateRPC.native";
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/_lib/nativeBridge/native/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./request";
export * from "./discordRPC";
export * from "./dasha.native";
export * from "./getTrackInfo.native";
export * from "./crypto.native";
Expand Down
2 changes: 1 addition & 1 deletion plugins/_lib/nativeBridge/nativeBridge.native.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
35 changes: 35 additions & 0 deletions plugins/_lib/nativeBridge/trace.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { broadcast } from "./broadcast.native";

type LoggerFunc = (...data: any[]) => void;

type Logger<T extends LoggerFunc = LoggerFunc> = {
(...data: Parameters<T>): undefined;
withContext(context: string): (...data: Parameters<T>) => undefined;
};

export const Tracer = (source: string) => {
const createLogger = <T extends LoggerFunc>(logger: T): Logger<T> => {
const _logger = (...data: Parameters<T>) => {
logger("native", source, ...data);
return undefined;
};
_logger.withContext =
(context: string) =>
(...data: Parameters<T>) => {
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]");
2 changes: 2 additions & 0 deletions plugins/_lib/nativeBridge/whereami.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const inRenderer = globalThis?.process === undefined;
export const inNative = !inRenderer;
Loading

0 comments on commit a4bec09

Please sign in to comment.