@aiyiran/myclaw 1.0.230 → 1.0.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/myclaw-inject.js +45 -7
- package/package.json +1 -1
package/assets/myclaw-inject.js
CHANGED
|
@@ -586,35 +586,73 @@
|
|
|
586
586
|
var cmdSocket = null;
|
|
587
587
|
var cmdSocketReady = false;
|
|
588
588
|
|
|
589
|
+
// ═══ Toast 提示 ═══
|
|
590
|
+
function showToast(msg, type) {
|
|
591
|
+
var t = document.createElement("div");
|
|
592
|
+
t.style.cssText = [
|
|
593
|
+
"position:fixed",
|
|
594
|
+
"bottom:40px",
|
|
595
|
+
"left:50%",
|
|
596
|
+
"transform:translateX(-50%)",
|
|
597
|
+
"padding:8px 20px",
|
|
598
|
+
"border-radius:6px",
|
|
599
|
+
"font-size:12px",
|
|
600
|
+
"font-family:monospace",
|
|
601
|
+
"color:#fff",
|
|
602
|
+
"z-index:999999",
|
|
603
|
+
"pointer-events:none",
|
|
604
|
+
"animation:myclaw-fade-in 0.2s ease",
|
|
605
|
+
"background:" + (type === "error" ? "#ef4444" : type === "success" ? "#10b981" : "#6366f1"),
|
|
606
|
+
].join(";");
|
|
607
|
+
t.textContent = msg;
|
|
608
|
+
document.body.appendChild(t);
|
|
609
|
+
setTimeout(function () { t.style.opacity = "0"; t.style.transition = "opacity 0.3s"; }, 2000);
|
|
610
|
+
setTimeout(function () { t.remove(); }, 2500);
|
|
611
|
+
}
|
|
612
|
+
|
|
589
613
|
function ensureSocketIO(callback) {
|
|
590
614
|
if (cmdSocketReady) { callback(); return; }
|
|
591
615
|
if (window.io) { connectCmdSocket(callback); return; }
|
|
592
616
|
|
|
617
|
+
showToast("\u52A0\u8F7D Socket.IO...");
|
|
593
618
|
var s = document.createElement("script");
|
|
594
619
|
s.src = window.location.origin + "/cmd/socket.io/socket.io.js";
|
|
595
620
|
s.onload = function () { connectCmdSocket(callback); };
|
|
596
|
-
s.onerror = function () {
|
|
621
|
+
s.onerror = function () {
|
|
622
|
+
showToast("Socket.IO \u52A0\u8F7D\u5931\u8D25", "error");
|
|
623
|
+
console.error("[myclaw-cmd] socket.io-client \u52A0\u8F7D\u5931\u8D25");
|
|
624
|
+
};
|
|
597
625
|
document.head.appendChild(s);
|
|
598
626
|
}
|
|
599
627
|
|
|
600
628
|
function connectCmdSocket(callback) {
|
|
601
|
-
if (cmdSocket
|
|
602
|
-
cmdSocket = window.io("/cmd", { path: "/cmd/socket.io/", transports: ["
|
|
629
|
+
if (cmdSocket && cmdSocketReady) { callback(); return; }
|
|
630
|
+
cmdSocket = window.io("/cmd", { path: "/cmd/socket.io/", transports: ["polling", "websocket"] });
|
|
603
631
|
cmdSocket.on("connect", function () {
|
|
604
632
|
cmdSocketReady = true;
|
|
605
|
-
console.log("[myclaw-cmd] Socket.IO
|
|
633
|
+
console.log("[myclaw-cmd] Socket.IO \u5DF2\u8FDE\u63A5, sid=" + cmdSocket.id);
|
|
634
|
+
showToast("Socket.IO \u5DF2\u8FDE\u63A5", "success");
|
|
606
635
|
callback();
|
|
607
636
|
});
|
|
608
637
|
cmdSocket.on("disconnect", function () {
|
|
609
638
|
cmdSocketReady = false;
|
|
610
|
-
|
|
639
|
+
showToast("Socket.IO \u5DF2\u65AD\u5F00", "error");
|
|
640
|
+
console.log("[myclaw-cmd] Socket.IO \u5DF2\u65AD\u5F00");
|
|
641
|
+
});
|
|
642
|
+
cmdSocket.on("connect_error", function (err) {
|
|
643
|
+
cmdSocketReady = false;
|
|
644
|
+
showToast("\u8FDE\u63A5\u5931\u8D25: " + err.message, "error");
|
|
645
|
+
console.error("[myclaw-cmd] \u8FDE\u63A5\u5931\u8D25:", err);
|
|
611
646
|
});
|
|
612
647
|
}
|
|
613
648
|
|
|
614
649
|
function runCommand(cmd) {
|
|
650
|
+
showToast("\u53D1\u9001: " + cmd);
|
|
615
651
|
ensureSocketIO(function () {
|
|
616
|
-
|
|
617
|
-
|
|
652
|
+
var runId = Date.now();
|
|
653
|
+
cmdSocket.emit("run_command", { cmd: cmd, runId: runId });
|
|
654
|
+
console.log("[myclaw-cmd] \u5DF2\u53D1\u9001 run_command:", { cmd: cmd, runId: runId });
|
|
655
|
+
showToast("\u5DF2\u53D1\u9001: " + cmd, "success");
|
|
618
656
|
});
|
|
619
657
|
}
|
|
620
658
|
|