feat(websocket-arduino): 委托给 WebCompiler.ArduShell 处理本地上传
This commit is contained in:
@@ -1,32 +1,37 @@
|
|||||||
goog.loadJs('web', () => {
|
goog.loadJs('web', () => {
|
||||||
|
|
||||||
goog.require('layui');
|
goog.require('layui');
|
||||||
goog.require('dayjs.duration');
|
goog.require('dayjs.duration');
|
||||||
goog.require('Mixly.Boards');
|
goog.require('Mixly.Boards');
|
||||||
goog.require('Mixly.Debug');
|
goog.require('Mixly.Debug');
|
||||||
goog.require('Mixly.LayerExt');
|
goog.require('Mixly.LayerExt');
|
||||||
goog.require('Mixly.Msg');
|
goog.require('Mixly.Msg');
|
||||||
goog.require('Mixly.Workspace');
|
goog.require('Mixly.Workspace');
|
||||||
goog.require('Mixly.LayerProgress');
|
goog.require('Mixly.LayerProgress');
|
||||||
goog.require('Mixly.WebSocket.Serial');
|
goog.require('Mixly.WebSocket.Serial');
|
||||||
goog.provide('Mixly.WebSocket.ArduShell');
|
goog.require('Mixly.WebCompiler.ArduShell');
|
||||||
|
goog.provide('Mixly.WebSocket.ArduShell');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Boards,
|
Boards,
|
||||||
Debug,
|
Debug,
|
||||||
LayerExt,
|
LayerExt,
|
||||||
Msg,
|
Msg,
|
||||||
Workspace,
|
Workspace,
|
||||||
LayerProgress,
|
LayerProgress,
|
||||||
WebSocket
|
WebSocket,
|
||||||
} = Mixly;
|
WebCompiler = {}
|
||||||
|
} = Mixly;
|
||||||
|
|
||||||
const { Serial } = WebSocket;
|
// 动态获取 WebCompiler.ArduShell,用于本地上传
|
||||||
|
const getWebCompilerArduShell = () => Mixly.WebCompiler?.ArduShell;
|
||||||
|
|
||||||
const { layer } = layui;
|
const { Serial } = WebSocket;
|
||||||
|
|
||||||
|
const { layer } = layui;
|
||||||
|
|
||||||
|
|
||||||
class WebSocketArduShell {
|
class WebSocketArduShell {
|
||||||
static {
|
static {
|
||||||
this.mixlySocket = null;
|
this.mixlySocket = null;
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
@@ -92,6 +97,13 @@ class WebSocketArduShell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.initUpload = function () {
|
this.initUpload = function () {
|
||||||
|
// 委托给 WebCompiler.ArduShell 处理本地上传(使用 AVRUploader 或 esptool-js)
|
||||||
|
// 服务器无法访问用户本地的串口设备,必须在浏览器端完成上传
|
||||||
|
const WebCompilerArduShell = getWebCompilerArduShell();
|
||||||
|
if (WebCompilerArduShell) {
|
||||||
|
return WebCompilerArduShell.initUpload();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.mixlySocket.isConnected()) {
|
if (!this.mixlySocket.isConnected()) {
|
||||||
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
||||||
return;
|
return;
|
||||||
@@ -152,8 +164,7 @@ class WebSocketArduShell {
|
|||||||
statusBarTerminal.addValue(`\n==${message}==\n`);
|
statusBarTerminal.addValue(`\n==${message}==\n`);
|
||||||
} else {
|
} else {
|
||||||
message = (this.shell.isCompiling() ? Msg.Lang['shell.compileSucc'] : Msg.Lang['shell.uploadSucc']);
|
message = (this.shell.isCompiling() ? Msg.Lang['shell.compileSucc'] : Msg.Lang['shell.uploadSucc']);
|
||||||
statusBarTerminal.addValue(`\n==${message}(${Msg.Lang['shell.timeCost']} ${
|
statusBarTerminal.addValue(`\n==${message}(${Msg.Lang['shell.timeCost']} ${dayjs.duration(time).format('HH:mm:ss.SSS')
|
||||||
dayjs.duration(time).format('HH:mm:ss.SSS')
|
|
||||||
})==\n`);
|
})==\n`);
|
||||||
}
|
}
|
||||||
layer.msg(message, { time: 1000 });
|
layer.msg(message, { time: 1000 });
|
||||||
@@ -268,8 +279,8 @@ class WebSocketArduShell {
|
|||||||
isCompiling() {
|
isCompiling() {
|
||||||
return this.#running_ && !this.#upload_;
|
return this.#running_ && !this.#upload_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocket.ArduShell = WebSocketArduShell;
|
WebSocket.ArduShell = WebSocketArduShell;
|
||||||
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user