Skip to content

Commit

Permalink
chore: silent -> logInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Feb 8, 2025
1 parent ffe99f1 commit a9cbd92
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/backend/vst/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const messagePromises = new Map<
resolve: (value: unknown) => void;
reject: (reason?: unknown) => void;
name: string;
silent: boolean;
logInfo: boolean;
}
>();
const initializeMessageHandler = () => {
Expand All @@ -71,15 +71,15 @@ const initializeMessageHandler = () => {
requestId: number;
payload: { Ok: unknown } | { Err: string };
};
const { resolve, reject, name, silent } =
const { resolve, reject, name, logInfo } =
messagePromises.get(requestId) ?? {};
if (!resolve || !reject) {
log.warn(`No promise found for requestId: ${requestId}`);
return;
}
messagePromises.delete(requestId);
if ("Ok" in payload) {
if (!silent) {
if (logInfo) {
log.info(`From plugin: ${name}(${requestId}), Ok`);
}
resolve(payload.Ok);
Expand Down Expand Up @@ -108,9 +108,9 @@ const initializeMessageHandler = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const createMessageFunction = <F extends (arg?: any) => any>(
name: string,
options: Partial<{ silent: boolean }> = {},
options: Partial<{ logInfo: boolean }> = {},
) => {
const silent = options?.silent ?? false;
const logInfo = options?.logOk ?? true;

Check failure on line 113 in src/backend/vst/ipc.ts

View workflow job for this annotation

GitHub Actions / build-test

Property 'logOk' does not exist on type 'Partial<{ logInfo: boolean; }>'.

Check failure on line 113 in src/backend/vst/ipc.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'logOk' does not exist on type 'Partial<{ logInfo: boolean; }>'.
return (arg?: Parameters<F>[0]) => {
if (!window.ipc?.postMessage) {
throw new UnreachableError(
Expand All @@ -122,7 +122,7 @@ const createMessageFunction = <F extends (arg?: any) => any>(
initializeMessageHandler();
}
const currentNonce = getRequestId();
if (!silent) {
if (logInfo) {
log.info(`To plugin: ${name}(${currentNonce})`);
}
window.ipc.postMessage(
Expand All @@ -135,7 +135,12 @@ const createMessageFunction = <F extends (arg?: any) => any>(
}),
);
const { promise, resolve, reject } = Promise.withResolvers();
messagePromises.set(currentNonce, { resolve, reject, name, silent });
messagePromises.set(currentNonce, {
resolve,
reject,
name,
logInfo,
});

return promise as Promise<ReturnType<F>>;
};
Expand Down Expand Up @@ -208,7 +213,7 @@ const ipcSetRouting =

const ipcGetCurrentPosition = createMessageFunction<() => number | null>(
"getCurrentPosition",
{ silent: true },
{ logInfo: false },
);

const ipcStartEngine =
Expand All @@ -221,14 +226,14 @@ const ipcChangeEnginePath =
const ipcZoom = createMessageFunction<(factor: number) => void>("zoom");

const ipcLogInfo = createMessageFunction<(message: string) => void>("logInfo", {
silent: true,
logInfo: false,
});
const ipcLogWarn = createMessageFunction<(message: string) => void>("logWarn", {
silent: true,
logInfo: false,
});
const ipcLogError = createMessageFunction<(message: string) => void>(
"logError",
{ silent: true },
{ logInfo: false },
);

type Config = Record<string, unknown> & Metadata;
Expand Down

0 comments on commit a9cbd92

Please sign in to comment.