|
@@ -1,16 +1,11 @@
|
|
|
const isElectron = () =>
|
|
|
typeof window !== 'undefined' &&
|
|
|
- window.require &&
|
|
|
- window.require('electron')?.ipcRenderer;
|
|
|
+ window.electronAPI &&
|
|
|
+ typeof window.electronAPI.writeLog === 'function';
|
|
|
|
|
|
// 检测是否在 Cypress 测试环境中
|
|
|
const isTestEnvironment = () =>
|
|
|
typeof window !== 'undefined' && window.Cypress;
|
|
|
-
|
|
|
-let ipcRenderer = null;
|
|
|
-if (isElectron()) {
|
|
|
- try { ipcRenderer = window.require('electron').ipcRenderer; } catch {}
|
|
|
-}
|
|
|
//避免obj是递归引用导致崩溃
|
|
|
function safeStringify(obj) {
|
|
|
const cache = new Set();
|
|
@@ -35,8 +30,8 @@ function proxyLog(level) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (ipcRenderer) { // ② Electron 环境
|
|
|
- ipcRenderer.invoke('write-log', level, msg).catch(() => {});
|
|
|
+ if (isElectron()) { // ② Electron 环境
|
|
|
+ window.electronAPI.writeLog(level, msg).catch(() => {});
|
|
|
} else if (typeof fetch !== 'undefined') {
|
|
|
// // ③ 纯 Web 或 pkg-static:发一条异步 POST /log,不阻塞、不报错
|
|
|
// fetch('/log', {
|