1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| import { inspect } from "util";
// 在 Main 代码中编写一个 log 方法
export function renderLog(...data) {
if (!mainWindow) return;
let dataStr = data.toString();
try {
dataStr = JSON.stringify(data);
} catch (e) {
try {
dataStr = JSON.stringify(inspect(data));
} catch (e) {}
}
mainWindow.webContents.executeJavaScript(
` try {
console.log('%cFROM MAIN', 'color: #800', JSON.parse(${dataStr}));
} catch (e) {
console.log('%cFROM MAIN', 'color: #800', ${dataStr});
}`
);
}
|