feat(core): 在线版添加对web compiler的支持

This commit is contained in:
王立帮
2025-05-04 14:38:32 +08:00
parent b9c0574780
commit e3f5caf0ce
21 changed files with 641 additions and 498 deletions

View File

@@ -27,6 +27,7 @@ goog.require('Mixly.Web.BU');
goog.require('Mixly.Web.FS');
goog.require('Mixly.Web.File');
goog.require('Mixly.Web.Serial');
goog.require('Mixly.WebCompiler.ArduShell');
goog.require('Mixly.WebSocket.File');
goog.require('Mixly.WebSocket.Serial');
goog.require('Mixly.WebSocket.ArduShell');
@@ -49,6 +50,7 @@ const {
EditorMix,
Electron = {},
Web = {},
WebCompiler = {},
WebSocket = {}
} = Mixly;
@@ -70,12 +72,18 @@ const {
FS,
File,
LibManager,
ArduShell,
BU,
PythonShell,
Serial
} = currentObj;
let ArduShell = null;
if (!goog.isElectron && Env.hasCompiler) {
ArduShell = WebCompiler.ArduShell;
} else {
ArduShell = currentObj.ArduShell;
}
const { BOARD, SELECTED_BOARD } = Config;
const { layer } = layui;

View File

@@ -16,7 +16,8 @@ goog.require('Mixly.Debug');
goog.require('Mixly.API2');
goog.require('Mixly.Electron.LibManager');
goog.require('Mixly.Electron.File');
goog.require('Mixly.WebSocket.Socket');
goog.require('Mixly.WebCompiler.Loader');
goog.require('Mixly.WebSocket.Loader');
goog.provide('Mixly.Loader');
const {
@@ -35,16 +36,20 @@ const {
API2,
Electron = {},
Web = {},
WebCompiler = {},
WebSocket = {}
} = Mixly;
const { LibManager, File } = goog.isElectron? Electron : Web;
const { Socket } = WebSocket;
window.addEventListener('load', () => {
if (!goog.isElectron && Env.hasSocketServer) {
Socket.init();
if (!goog.isElectron) {
if (Env.hasSocketServer) {
WebSocket.Loader.init();
} else if (Env.hasCompiler) {
WebCompiler.Loader.init();
}
}
const app = new App($('body')[0]);
Mixly.app = app;

View File

@@ -0,0 +1,91 @@
goog.loadJs('common', () => {
goog.require('io');
goog.require('Mixly');
goog.provide('Mixly.Socket');
class Socket {
#socket_ = null;
constructor(path, option) {
this.#socket_ = io(path, option);
}
#detectStatus_(status, callback) {
window.setTimeout(() => {
if (status.finished) {
return;
}
if (this.isConnected()) {
this.#detectStatus_(status, callback);
} else {
callback({
error: 'socket is not connected'
});
status.finished = true;
}
}, 1000);
}
emit(eventName, ...args) {
const callback = args.pop();
if (this.isConnected()) {
let emitStatus = {
finished: false
};
let status = this.#socket_.emit(eventName, ...args, (...callbackArgs) => {
if (emitStatus.finished) {
return;
}
emitStatus.finished = true;
callback(...callbackArgs);
});
this.#detectStatus_(emitStatus, callback);
return status;
} else {
callback({
error: 'socket is not connected'
});
return false;
}
}
async emitAsync(eventName, ...args) {
return new Promise((resolve, reject) => {
if (this.isConnected()) {
const callback = (...callbackArgs) => {
if (callbackArgs[0].error) {
reject(callbackArgs[0].error);
return;
}
resolve(...callbackArgs);
}
let emitStatus = {
finished: false
};
let status = this.#socket_.emit(eventName, ...args, (...callbackArgs) => {
if (emitStatus.finished) {
return;
}
emitStatus.finished = true;
callback(...callbackArgs);
});
this.#detectStatus_(emitStatus, callback);
} else {
reject('socket is not connected');
}
})
}
getSocket() {
return this.#socket_;
}
isConnected() {
return this.#socket_?.connected;
}
}
Mixly.Socket = Socket;
});