chore(desktop-client): gate dev-only debug paths in packaged builds

Wrap the network observer, renderer-devtools proxy (both the main-side
ipc handler registration and the preload-side response listener), and
the auto-open-devtools triggers behind !app.isPackaged so packaged
builds don't ship debugging side channels. Add a tiny console-guard
imported first in renderer/main.ts that no-ops console.* in
import.meta.env.PROD so a packaged build stays quiet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-01 17:20:00 +08:00
parent fb1351d82b
commit 8b4697d605
6 changed files with 117 additions and 58 deletions
+57 -55
View File
@@ -35,64 +35,66 @@ interface DesktopAppSettings {
const rendererProxyRequestChannel = "desktop:renderer-devtools-proxy:request";
const rendererProxyResponseChannel = "desktop:renderer-devtools-proxy:response";
ipcRenderer.on(
rendererProxyRequestChannel,
async (
_event,
payload: {
requestId?: unknown;
request?: {
url?: unknown;
method?: unknown;
headers?: unknown;
body?: unknown;
};
},
) => {
const requestId = typeof payload?.requestId === "string" ? payload.requestId : "";
const request = payload?.request;
if (!requestId || !request || typeof request !== "object") {
return;
}
const url = typeof request.url === "string" ? request.url : "";
const method = typeof request.method === "string" ? request.method : "GET";
const headers = isStringRecord(request.headers) ? request.headers : {};
const body = typeof request.body === "string" ? request.body : undefined;
const response = await (async () => {
try {
const fetchResponse = await fetch(url, {
method,
headers,
body,
});
const bodyText = await fetchResponse.text();
return {
ok: fetchResponse.ok,
status: fetchResponse.status,
statusText: fetchResponse.statusText,
headers: Object.fromEntries(fetchResponse.headers.entries()),
bodyText,
};
} catch (error) {
return {
ok: false,
status: 0,
statusText: "",
headers: {},
bodyText: "",
error: String(error && ((error as Error).message || error)),
if (import.meta.env.DEV) {
ipcRenderer.on(
rendererProxyRequestChannel,
async (
_event,
payload: {
requestId?: unknown;
request?: {
url?: unknown;
method?: unknown;
headers?: unknown;
body?: unknown;
};
},
) => {
const requestId = typeof payload?.requestId === "string" ? payload.requestId : "";
const request = payload?.request;
if (!requestId || !request || typeof request !== "object") {
return;
}
})();
ipcRenderer.send(rendererProxyResponseChannel, {
requestId,
response,
});
},
);
const url = typeof request.url === "string" ? request.url : "";
const method = typeof request.method === "string" ? request.method : "GET";
const headers = isStringRecord(request.headers) ? request.headers : {};
const body = typeof request.body === "string" ? request.body : undefined;
const response = await (async () => {
try {
const fetchResponse = await fetch(url, {
method,
headers,
body,
});
const bodyText = await fetchResponse.text();
return {
ok: fetchResponse.ok,
status: fetchResponse.status,
statusText: fetchResponse.statusText,
headers: Object.fromEntries(fetchResponse.headers.entries()),
bodyText,
};
} catch (error) {
return {
ok: false,
status: 0,
statusText: "",
headers: {},
bodyText: "",
error: String(error && ((error as Error).message || error)),
};
}
})();
ipcRenderer.send(rendererProxyResponseChannel, {
requestId,
response,
});
},
);
}
const desktopBridge = {
app: {