fix: show Add Device button in Web environment

This commit is contained in:
yczpf2019
2026-01-24 18:30:47 +08:00
parent 49d6ec88f0
commit aa85c7ef27

View File

@@ -1,41 +1,41 @@
goog.loadJs('common', () => { goog.loadJs('common', () => {
goog.require('path'); goog.require('path');
goog.require('hotkeys'); goog.require('hotkeys');
goog.require('Mixly.Url'); goog.require('Mixly.Url');
goog.require('Mixly.Config'); goog.require('Mixly.Config');
goog.require('Mixly.Env'); goog.require('Mixly.Env');
goog.require('Mixly.Msg'); goog.require('Mixly.Msg');
goog.require('Mixly.Drag'); goog.require('Mixly.Drag');
goog.require('Mixly.Nav'); goog.require('Mixly.Nav');
goog.require('Mixly.Menu'); goog.require('Mixly.Menu');
goog.require('Mixly.Workspace'); goog.require('Mixly.Workspace');
goog.require('Mixly.FooterBar'); goog.require('Mixly.FooterBar');
goog.require('Mixly.HTMLTemplate'); goog.require('Mixly.HTMLTemplate');
goog.require('Mixly.LayerExt'); goog.require('Mixly.LayerExt');
goog.require('Mixly.Debug'); goog.require('Mixly.Debug');
goog.require('Mixly.Component'); goog.require('Mixly.Component');
goog.require('Mixly.EditorMix'); goog.require('Mixly.EditorMix');
goog.require('Mixly.Electron.Loader'); goog.require('Mixly.Electron.Loader');
goog.require('Mixly.Electron.FS'); goog.require('Mixly.Electron.FS');
goog.require('Mixly.Electron.File'); goog.require('Mixly.Electron.File');
goog.require('Mixly.Electron.LibManager'); goog.require('Mixly.Electron.LibManager');
goog.require('Mixly.Electron.Serial'); goog.require('Mixly.Electron.Serial');
goog.require('Mixly.Electron.ArduShell'); goog.require('Mixly.Electron.ArduShell');
goog.require('Mixly.Electron.BU'); goog.require('Mixly.Electron.BU');
goog.require('Mixly.Electron.PythonShell'); goog.require('Mixly.Electron.PythonShell');
goog.require('Mixly.Web.BU'); goog.require('Mixly.Web.BU');
goog.require('Mixly.Web.FS'); goog.require('Mixly.Web.FS');
goog.require('Mixly.Web.File'); goog.require('Mixly.Web.File');
goog.require('Mixly.Web.Serial'); goog.require('Mixly.Web.Serial');
goog.require('Mixly.WebCompiler.ArduShell'); goog.require('Mixly.WebCompiler.ArduShell');
goog.require('Mixly.WebSocket.File'); goog.require('Mixly.WebSocket.File');
goog.require('Mixly.WebSocket.Serial'); goog.require('Mixly.WebSocket.Serial');
goog.require('Mixly.WebSocket.ArduShell'); goog.require('Mixly.WebSocket.ArduShell');
goog.require('Mixly.WebSocket.BU'); goog.require('Mixly.WebSocket.BU');
goog.provide('Mixly.App'); goog.provide('Mixly.App');
const { const {
Url, Url,
Config, Config,
Env, Env,
@@ -54,42 +54,42 @@ const {
Web = {}, Web = {},
WebCompiler = {}, WebCompiler = {},
WebSocket = {} WebSocket = {}
} = Mixly; } = Mixly;
const { Loader } = Electron; const { Loader } = Electron;
let currentObj = null; let currentObj = null;
if (goog.isElectron) { if (goog.isElectron) {
currentObj = Electron; currentObj = Electron;
} else { } else {
if (Env.hasSocketServer) { if (Env.hasSocketServer) {
currentObj = WebSocket; currentObj = WebSocket;
} else { } else {
currentObj = Web; currentObj = Web;
} }
} }
const { const {
FS, FS,
File, File,
LibManager, LibManager,
BU, BU,
PythonShell, PythonShell,
Serial Serial
} = currentObj; } = currentObj;
let ArduShell = null; let ArduShell = null;
if (!goog.isElectron && Env.hasCompiler) { if (!goog.isElectron && Env.hasCompiler) {
ArduShell = WebCompiler.ArduShell; ArduShell = WebCompiler.ArduShell;
} else { } else {
ArduShell = currentObj.ArduShell; ArduShell = currentObj.ArduShell;
} }
const { BOARD, SELECTED_BOARD } = Config; const { BOARD, SELECTED_BOARD } = Config;
class App extends Component { class App extends Component {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/app.html', 'html/app.html',
@@ -174,7 +174,8 @@ class App extends Component {
id: 'port-add-btn', id: 'port-add-btn',
displayText: Msg.Lang['nav.btn.addDevice'], displayText: Msg.Lang['nav.btn.addDevice'],
preconditionFn: () => { preconditionFn: () => {
if (goog.isElectron || Env.hasSocketServer) { // 在 Web 环境下始终显示添加设备按钮
if (goog.isElectron) {
return false; return false;
} }
return true; return true;
@@ -470,7 +471,7 @@ class App extends Component {
} }
}); });
hotkeys('ctrl+n', function(event) { hotkeys('ctrl+n', function (event) {
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation(); event.stopImmediatePropagation();
File.new(); File.new();
@@ -489,7 +490,7 @@ class App extends Component {
} }
}); });
hotkeys('ctrl+o', function(event) { hotkeys('ctrl+o', function (event) {
event.preventDefault(); event.preventDefault();
File.open(); File.open();
}); });
@@ -513,7 +514,7 @@ class App extends Component {
} }
}); });
hotkeys('ctrl+s', function(event) { hotkeys('ctrl+s', function (event) {
event.preventDefault(); event.preventDefault();
File.save(); File.save();
}); });
@@ -531,7 +532,7 @@ class App extends Component {
} }
}); });
hotkeys('ctrl+shift+s', function(event) { hotkeys('ctrl+shift+s', function (event) {
event.preventDefault(); event.preventDefault();
File.saveAs(); File.saveAs();
}); });
@@ -559,7 +560,7 @@ class App extends Component {
}); });
if (goog.isElectron && BOARD?.nav?.setting?.thirdPartyLibrary) { if (goog.isElectron && BOARD?.nav?.setting?.thirdPartyLibrary) {
hotkeys('ctrl+e', function(event) { hotkeys('ctrl+e', function (event) {
event.preventDefault(); event.preventDefault();
File.exportLib(); File.exportLib();
}); });
@@ -579,7 +580,7 @@ class App extends Component {
}); });
if (goog.isElectron && BOARD?.nav?.setting?.thirdPartyLibrary) { if (goog.isElectron && BOARD?.nav?.setting?.thirdPartyLibrary) {
hotkeys('ctrl+m', function(event) { hotkeys('ctrl+m', function (event) {
LibManager.showManageDialog(); LibManager.showManageDialog();
}); });
} }
@@ -609,7 +610,7 @@ class App extends Component {
} }
}); });
hotkeys('ctrl+shift+f', function(event) { hotkeys('ctrl+shift+f', function (event) {
const href = 'https://gitee.com/bnu_mixly/mixly3/issues'; const href = 'https://gitee.com/bnu_mixly/mixly3/issues';
Url.open(href); Url.open(href);
}); });
@@ -630,7 +631,7 @@ class App extends Component {
} }
}); });
hotkeys('ctrl+h', function(event) { hotkeys('ctrl+h', function (event) {
const href = 'https://mixly.readthedocs.io/zh-cn/latest/contents.html'; const href = 'https://mixly.readthedocs.io/zh-cn/latest/contents.html';
Url.open(href); Url.open(href);
}); });
@@ -682,8 +683,8 @@ class App extends Component {
this.#workspace_.dispose(); this.#workspace_.dispose();
super.dispose(); super.dispose();
} }
} }
Mixly.App = App; Mixly.App = App;
}); });