文档: 整合开发计划文档 & 修复: TypeScript 编译及可靠性改进
This commit is contained in:
141
dist/IpcManager.js
vendored
Normal file
141
dist/IpcManager.js
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
||||
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IpcManager = void 0;
|
||||
// @ts-ignore
|
||||
var fs = require('fs');
|
||||
// @ts-ignore
|
||||
var path = require('path');
|
||||
/**
|
||||
* IPC 消息管理器
|
||||
* 负责解析 IPC 文档并执行消息测试
|
||||
*/
|
||||
var IpcManager = /** @class */ (function () {
|
||||
function IpcManager() {
|
||||
}
|
||||
/**
|
||||
* 获取所有 IPC 消息列表
|
||||
* @returns 消息定义列表
|
||||
*/
|
||||
IpcManager.getIpcMessages = function () {
|
||||
// 获取文档路径
|
||||
// @ts-ignore
|
||||
var docPath = Editor.url('packages://mcp-bridge/IPC_MESSAGES.md');
|
||||
if (!fs.existsSync(docPath)) {
|
||||
// @ts-ignore
|
||||
Editor.error("[IPC Manager] Document not found: ".concat(docPath));
|
||||
return [];
|
||||
}
|
||||
var content = fs.readFileSync(docPath, 'utf-8');
|
||||
var messages = [];
|
||||
// 正则匹配 ### `message-name`
|
||||
var regex = /### `(.*?)`\r?\n([\s\S]*?)(?=### `|$)/g;
|
||||
var match;
|
||||
while ((match = regex.exec(content)) !== null) {
|
||||
var name_1 = match[1];
|
||||
var body = match[2];
|
||||
// 解析用途
|
||||
var purposeMatch = body.match(/- \*\*用途\*\*: (.*)/);
|
||||
var description = purposeMatch ? purposeMatch[1].trim() : "无描述";
|
||||
// 解析参数
|
||||
var paramsMatch = body.match(/- \*\*参数\*\*: (.*)/);
|
||||
var params = paramsMatch ? paramsMatch[1].trim() : "无";
|
||||
// 解析返回值
|
||||
var returnMatch = body.match(/- \*\*返回值\*\*: (.*)/);
|
||||
var returns = returnMatch ? returnMatch[1].trim() : "无";
|
||||
// 解析类型
|
||||
var typeMatch = body.match(/- \*\*类型\*\*: (.*)/);
|
||||
var type = typeMatch ? typeMatch[1].trim() : "未定义";
|
||||
// 解析状态
|
||||
var statusMatch = body.match(/- \*\*状态\*\*: (.*)/);
|
||||
var status_1 = statusMatch ? statusMatch[1].trim() : "未测试";
|
||||
// 过滤掉广播事件和渲染进程监听的事件
|
||||
if (type === "广播事件" || type === "Events listened by Renderer Process" || type === "渲染进程监听") {
|
||||
continue;
|
||||
}
|
||||
messages.push({
|
||||
name: name_1,
|
||||
description: description,
|
||||
params: params,
|
||||
returns: returns,
|
||||
type: type,
|
||||
status: status_1
|
||||
});
|
||||
}
|
||||
return messages;
|
||||
};
|
||||
/**
|
||||
* 测试发送 IPC 消息
|
||||
* @param name 消息名称
|
||||
* @param args 参数
|
||||
* @returns Promise<any> 测试结果
|
||||
*/
|
||||
IpcManager.testIpcMessage = function (name_2) {
|
||||
return __awaiter(this, arguments, void 0, function (name, args) {
|
||||
if (args === void 0) { args = null; }
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, new Promise(function (resolve) {
|
||||
// 简单防呆:防止执行危险操作
|
||||
// 如果消息包含 "delete", "remove", "close", "stop" 且没有明确参数确认,则警告
|
||||
// 但用户要求"快速验证",所以我们默认允许,但如果是无参调用可能有风险
|
||||
// 这里我们尝试使用 Editor.Ipc.sendToMain 或 requestToMain
|
||||
// @ts-ignore
|
||||
// 简单的测试:只是发送看看是否报错。
|
||||
// 对于 request 类型的消息,我们期望有回调
|
||||
// Cocos Creator 2.4 API: Editor.Ipc.sendToMain(message, ...args)
|
||||
try {
|
||||
// @ts-ignore
|
||||
if (Editor.Ipc.sendToMain) {
|
||||
// @ts-ignore
|
||||
Editor.Ipc.sendToMain(name, args);
|
||||
resolve({ success: true, message: "Message sent (sendToMain)" });
|
||||
}
|
||||
else {
|
||||
resolve({ success: false, message: "Editor.Ipc.sendToMain not available" });
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
resolve({ success: false, message: "Error: ".concat(e.message) });
|
||||
}
|
||||
})];
|
||||
});
|
||||
});
|
||||
};
|
||||
return IpcManager;
|
||||
}());
|
||||
exports.IpcManager = IpcManager;
|
||||
233
dist/IpcUi.js
vendored
Normal file
233
dist/IpcUi.js
vendored
Normal file
@@ -0,0 +1,233 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
||||
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IpcUi = void 0;
|
||||
// @ts-ignore
|
||||
var Editor = window.Editor;
|
||||
var IpcUi = /** @class */ (function () {
|
||||
function IpcUi(root) {
|
||||
this.logArea = null;
|
||||
this.ipcList = null;
|
||||
this.allMessages = [];
|
||||
this.filterSelect = null;
|
||||
this.paramInput = null;
|
||||
this.root = root;
|
||||
this.bindEvents();
|
||||
}
|
||||
IpcUi.prototype.bindEvents = function () {
|
||||
var _this = this;
|
||||
var btnScan = this.root.querySelector("#btnScanIpc");
|
||||
var btnTest = this.root.querySelector("#btnTestIpc");
|
||||
var cbSelectAll = this.root.querySelector("#cbSelectAllIpc");
|
||||
this.logArea = this.root.querySelector("#ipcLog");
|
||||
this.ipcList = this.root.querySelector("#ipcList");
|
||||
this.filterSelect = this.root.querySelector("#ipcFilter");
|
||||
this.paramInput = this.root.querySelector("#ipcParams");
|
||||
if (btnScan) {
|
||||
btnScan.addEventListener("confirm", function () { return _this.scanMessages(); });
|
||||
}
|
||||
if (btnTest) {
|
||||
btnTest.addEventListener("confirm", function () { return _this.testSelected(); });
|
||||
}
|
||||
if (cbSelectAll) {
|
||||
cbSelectAll.addEventListener("change", function (e) { return _this.toggleAll(e.detail ? e.detail.value : (e.target.value === 'true' || e.target.checked)); });
|
||||
}
|
||||
if (this.filterSelect) {
|
||||
this.filterSelect.addEventListener("change", function () { return _this.filterMessages(); });
|
||||
}
|
||||
};
|
||||
IpcUi.prototype.scanMessages = function () {
|
||||
var _this = this;
|
||||
this.log("Scanning IPC messages...");
|
||||
// @ts-ignore
|
||||
Editor.Ipc.sendToMain("mcp-bridge:scan-ipc-messages", function (err, msgs) {
|
||||
if (err) {
|
||||
_this.log("Scan Error: ".concat(err));
|
||||
return;
|
||||
}
|
||||
if (msgs) {
|
||||
_this.allMessages = msgs;
|
||||
_this.filterMessages();
|
||||
_this.log("Found ".concat(msgs.length, " messages."));
|
||||
}
|
||||
else {
|
||||
_this.log("No messages found.");
|
||||
}
|
||||
});
|
||||
};
|
||||
IpcUi.prototype.filterMessages = function () {
|
||||
if (!this.allMessages)
|
||||
return;
|
||||
var filter = this.filterSelect ? this.filterSelect.value : "all";
|
||||
var filtered = this.allMessages;
|
||||
if (filter === "available") {
|
||||
filtered = this.allMessages.filter(function (m) { return m.status === "可用"; });
|
||||
}
|
||||
else if (filter === "unavailable") {
|
||||
filtered = this.allMessages.filter(function (m) { return m.status && m.status.includes("不可用"); });
|
||||
}
|
||||
else if (filter === "untested") {
|
||||
filtered = this.allMessages.filter(function (m) { return !m.status || m.status === "未测试"; });
|
||||
}
|
||||
this.renderList(filtered);
|
||||
};
|
||||
IpcUi.prototype.renderList = function (msgs) {
|
||||
var _this = this;
|
||||
if (!this.ipcList)
|
||||
return;
|
||||
this.ipcList.innerHTML = "";
|
||||
msgs.forEach(function (msg) {
|
||||
var item = document.createElement("div");
|
||||
item.className = "ipc-item";
|
||||
item.style.padding = "4px";
|
||||
item.style.borderBottom = "1px solid #333";
|
||||
item.style.display = "flex";
|
||||
item.style.alignItems = "center";
|
||||
// Checkbox
|
||||
var checkbox = document.createElement("ui-checkbox");
|
||||
// @ts-ignore
|
||||
checkbox.value = false;
|
||||
checkbox.setAttribute("data-name", msg.name);
|
||||
checkbox.style.marginRight = "8px";
|
||||
// Content
|
||||
var content = document.createElement("div");
|
||||
content.style.flex = "1";
|
||||
content.style.fontSize = "11px";
|
||||
var statusColor = "#888"; // Untested
|
||||
if (msg.status === "可用")
|
||||
statusColor = "#4CAF50"; // Green
|
||||
else if (msg.status && msg.status.includes("不可用"))
|
||||
statusColor = "#F44336"; // Red
|
||||
content.innerHTML = "\n <div style=\"display:flex; justify-content:space-between;\">\n <span style=\"color: #4CAF50; font-weight: bold;\">".concat(msg.name, "</span>\n <span style=\"color: ").concat(statusColor, "; font-size: 10px; border: 1px solid ").concat(statusColor, "; padding: 0 4px; border-radius: 4px;\">").concat(msg.status || "未测试", "</span>\n </div>\n <div style=\"color: #888;\">").concat(msg.description || "No desc", "</div>\n <div style=\"color: #666; font-size: 10px;\">Params: ").concat(msg.params || "None", "</div>\n ");
|
||||
// Action Button
|
||||
var btnRun = document.createElement("ui-button");
|
||||
btnRun.innerText = "Run";
|
||||
btnRun.className = "tiny";
|
||||
btnRun.style.height = "20px";
|
||||
btnRun.style.lineHeight = "20px";
|
||||
btnRun.addEventListener("confirm", function () {
|
||||
_this.runTest(msg.name);
|
||||
});
|
||||
item.appendChild(checkbox);
|
||||
item.appendChild(content);
|
||||
item.appendChild(btnRun);
|
||||
_this.ipcList.appendChild(item);
|
||||
});
|
||||
};
|
||||
IpcUi.prototype.testSelected = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var checkboxes, toTest, _i, toTest_1, name_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
checkboxes = this.root.querySelectorAll("#ipcList ui-checkbox");
|
||||
toTest = [];
|
||||
checkboxes.forEach(function (cb) {
|
||||
// In Cocos 2.x, ui-checkbox value is boolean
|
||||
if (cb.checked || cb.value === true) {
|
||||
toTest.push(cb.getAttribute("data-name"));
|
||||
}
|
||||
});
|
||||
if (toTest.length === 0) {
|
||||
this.log("No messages selected.");
|
||||
return [2 /*return*/];
|
||||
}
|
||||
this.log("Starting batch test for ".concat(toTest.length, " messages..."));
|
||||
_i = 0, toTest_1 = toTest;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
if (!(_i < toTest_1.length)) return [3 /*break*/, 4];
|
||||
name_1 = toTest_1[_i];
|
||||
return [4 /*yield*/, this.runTest(name_1)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
_i++;
|
||||
return [3 /*break*/, 1];
|
||||
case 4:
|
||||
this.log("Batch test completed.");
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
IpcUi.prototype.runTest = function (name) {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve) {
|
||||
var params = null;
|
||||
if (_this.paramInput && _this.paramInput.value.trim()) {
|
||||
try {
|
||||
params = JSON.parse(_this.paramInput.value.trim());
|
||||
}
|
||||
catch (e) {
|
||||
_this.log("[Error] Invalid JSON Params: ".concat(e));
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
}
|
||||
_this.log("Testing: ".concat(name, " with params: ").concat(JSON.stringify(params), "..."));
|
||||
// @ts-ignore
|
||||
Editor.Ipc.sendToMain("mcp-bridge:test-ipc-message", { name: name, params: params }, function (err, result) {
|
||||
if (err) {
|
||||
_this.log("[".concat(name, "] Failed: ").concat(err));
|
||||
}
|
||||
else {
|
||||
_this.log("[".concat(name, "] Success: ").concat(JSON.stringify(result)));
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
IpcUi.prototype.toggleAll = function (checked) {
|
||||
var checkboxes = this.root.querySelectorAll("#ipcList ui-checkbox");
|
||||
checkboxes.forEach(function (cb) {
|
||||
cb.value = checked;
|
||||
});
|
||||
};
|
||||
IpcUi.prototype.log = function (msg) {
|
||||
if (this.logArea) {
|
||||
// @ts-ignore
|
||||
var time = new Date().toLocaleTimeString();
|
||||
this.logArea.value += "[".concat(time, "] ").concat(msg, "\n");
|
||||
this.logArea.scrollTop = this.logArea.scrollHeight;
|
||||
}
|
||||
};
|
||||
return IpcUi;
|
||||
}());
|
||||
exports.IpcUi = IpcUi;
|
||||
Reference in New Issue
Block a user