Skip to content

Commit

Permalink
优化debug模式
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyuesaves committed Jan 25, 2024
1 parent eebf8af commit 2b107a7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
12 changes: 11 additions & 1 deletion src/config/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,23 @@ <h2>调试功能</h2>
<hr class="horizontal-dividing-line" />
<li class="vertical-list-item">
<div>
<h2>debug模式</h2>
<h2>渲染进程调试</h2>
<span class="secondary-text">调试用,普通用户请勿开启</span>
</div>
<div class="switchDebug q-switch">
<span class="q-switch__handle"></span>
</div>
</li>
<hr class="horizontal-dividing-line" />
<li class="vertical-list-item">
<div>
<h2>主进程调试</h2>
<span class="secondary-text">调试用,普通用户请勿开启</span>
</div>
<div class="switchMainDebug q-switch">
<span class="q-switch__handle"></span>
</div>
</li>
</ul>
</setting-panel>
<h1 class="version">当前版本<a class="link">v0.0.0</a></h1>
Expand Down
5 changes: 4 additions & 1 deletion src/defaultConfig/defaultConfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"debug": false,
"debug": {
"console": false,
"mainConsole": false
},
"wordSearch": {
"enabled": false,
"searchUrl": "https://www.bing.com/search?q=%search%"
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function onLoad(plugin) {
setOptions(options);
localEmoticonsConfig = loadOptions(defalutLocalEmoticonsConfig, localEmoticonsPath);

if (options.debug) {
if (options.debug.mainConsole) {
let mainLogs = new logs("主进程");
mainLogs.startLogServer();
log = mainLogs.log;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/configView.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ async function onConfigView(view) {
addSwitchEventlistener("message.convertMiniPrgmArk", ".switchDisabledMiniPrgm");

// debug开关
addSwitchEventlistener("debug", ".switchDebug");
addSwitchEventlistener("debug.console", ".switchDebug");
addSwitchEventlistener("debug.mainConsole", ".switchMainDebug");

// 显示每条消息发送时间
addSwitchEventlistener("message.showMsgTime", ".showMsgTime");
Expand Down
18 changes: 10 additions & 8 deletions src/render_modules/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { options } from "./options.js";
const logList = [];

window.LT_logs = () => {
if (options.debug) {
if (options.debug.console) {
logList.forEach((el) => {
console.log(`[${el.name}]`, ...el.log);
});
Expand All @@ -15,17 +15,19 @@ window.LT_logs = () => {
class logs {
constructor(moduleName) {
this.moduleName = moduleName;
this.log = (...args) => {
console.log(`[${this.moduleName}]`, ...args);
// lite_tools.log(`[${this.moduleName}]`, ...args);
// 没有开启debug开关的情况下,阻止保存log数据
if (options.debug) {
if (options.debug.console) {
this.log = (...args) => {
console.log(`[${this.moduleName}]`, ...args);
// lite_tools.log(`[${this.moduleName}]`, ...args);
// 没有开启debug开关的情况下,阻止保存log数据
logList.push({
name: this.moduleName,
log: [...args],
});
}
};
};
} else {
this.log = () => {};
}
}
}

Expand Down

0 comments on commit 2b107a7

Please sign in to comment.