feat(core): 将goog.get接口调整为goog.readJsonSync以指示其同步操作特性

This commit is contained in:
王立帮
2025-04-27 15:40:33 +08:00
parent 46b3da8cc8
commit af2910adb0
44 changed files with 92 additions and 87 deletions

View File

@@ -18,16 +18,16 @@ const {
class AmpyExt extends Ampy {
static {
this.LS = goog.get(path.join(Env.templatePath, 'python/ls.py'));
this.LS_RECURSIVE = goog.get(path.join(Env.templatePath, 'python/ls-recursive.py'));
this.LS_LONG_FORMAT = goog.get(path.join(Env.templatePath, 'python/ls-long-format.py'));
this.MKDIR = goog.get(path.join(Env.templatePath, 'python/mkdir.py'));
this.MKFILE = goog.get(path.join(Env.templatePath, 'python/mkfile.py'));
this.RENAME = goog.get(path.join(Env.templatePath, 'python/rename.py'));
this.RM = goog.get(path.join(Env.templatePath, 'python/rm.py'));
this.RMDIR = goog.get(path.join(Env.templatePath, 'python/rmdir.py'));
this.GET = goog.get(path.join(Env.templatePath, 'python/get.py'));
this.CWD = goog.get(path.join(Env.templatePath, 'python/cwd.py'));
this.LS = goog.readFileSync(path.join(Env.templatePath, 'python/ls.py'));
this.LS_RECURSIVE = goog.readFileSync(path.join(Env.templatePath, 'python/ls-recursive.py'));
this.LS_LONG_FORMAT = goog.readFileSync(path.join(Env.templatePath, 'python/ls-long-format.py'));
this.MKDIR = goog.readFileSync(path.join(Env.templatePath, 'python/mkdir.py'));
this.MKFILE = goog.readFileSync(path.join(Env.templatePath, 'python/mkfile.py'));
this.RENAME = goog.readFileSync(path.join(Env.templatePath, 'python/rename.py'));
this.RM = goog.readFileSync(path.join(Env.templatePath, 'python/rm.py'));
this.RMDIR = goog.readFileSync(path.join(Env.templatePath, 'python/rmdir.py'));
this.GET = goog.readFileSync(path.join(Env.templatePath, 'python/get.py'));
this.CWD = goog.readFileSync(path.join(Env.templatePath, 'python/cwd.py'));
}
#device_ = null;
@@ -223,12 +223,17 @@ class AmpyExt extends Ampy {
return this.#device_.decode(this.unhexlify(data));
}
async put(filename, code, timeout = 5000) {
async put(filename, data, timeout = 5000) {
if (!this.isActive()) {
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
}
await this.exec(`file = open('${filename}', 'wb')`, timeout);
const buffer = this.#device_.encode(code);
let buffer = null;
if (typeof data === 'string') {
buffer = this.#device_.encode(data);
} else {
buffer = data;
}
const len = Math.ceil(buffer.length / 64);
for (let i = 0; i < len; i++) {
const writeBuffer = buffer.slice(i * 64, Math.min((i + 1) * 64, buffer.length));

View File

@@ -54,7 +54,7 @@ BU.uploading = false;
BU.burning = false;
BU.FILMWARE_LAYER = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/filmware-layer.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/filmware-layer.html'))
).render({
cancel: Msg.Lang['nav.btn.cancel'],
burn: Msg.Lang['nav.btn.burn']
@@ -166,7 +166,7 @@ BU.burnByUSB = async () => {
const { web } = SELECTED_BOARD;
const { burn } = web;
const hexStr = goog.get(path.join(Env.boardDirPath, burn.filePath));
const hexStr = goog.readFileSync(path.join(Env.boardDirPath, burn.filePath));
const hex2Blob = new Blob([ hexStr ], { type: 'text/plain' });
const buffer = await hex2Blob.arrayBuffer();
if (!buffer) {
@@ -499,7 +499,7 @@ BU.getImportModules = (code) => {
const libPath = SELECTED_BOARD.upload.libPath;
for (let i = libPath.length - 1; i >= 0; i--) {
const dirname = MString.tpl(libPath[i], { indexPath: Env.boardDirPath });
const map = goog.getJSON(path.join(dirname, 'map.json'));
const map = goog.readJsonSync(path.join(dirname, 'map.json'));
if (!(map && map instanceof Object)) {
continue;
}
@@ -603,7 +603,7 @@ BU.uploadByUSB = async (portName) => {
const importsMap = BU.getImportModules(code);
for (let key in importsMap) {
const filename = importsMap[key]['__name__'];
const data = goog.get(importsMap[key]['__path__']);
const data = goog.readFileSync(importsMap[key]['__path__']);
FSWrapper.writeFile(filename, data);
}
const layerNum = layer.open({
@@ -690,7 +690,7 @@ BU.uploadWithAmpy = (portName) => {
let libraries = {};
for (let key in importsMap) {
const filename = importsMap[key]['__name__'];
const data = goog.get(importsMap[key]['__path__']);
const data = goog.readFileSync(importsMap[key]['__path__']);
libraries[filename] = {
data,
size: importsMap[key]['__size__']

View File

@@ -77,7 +77,7 @@ class FooterLayerExampleExt extends FooterLayerExample {
}
dataToWorkspace(inPath) {
const data = goog.get(path.join(Env.boardDirPath, 'examples', inPath));
const data = goog.readFileSync(path.join(Env.boardDirPath, 'examples', inPath));
this.updateCode(path.extname(inPath), data);
}
}

View File

@@ -43,7 +43,7 @@ class WebSerial extends Serial {
this.devicesRegistry = new Registry();
this.type = Serial.type;
this.DEVICES_SELECT_LAYER = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/devices-select-layer.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/devices-select-layer.html'))
);
this.getConfig = function () {