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

@@ -87,7 +87,7 @@ class App extends Component {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/app.html', 'html/app.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/app.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/app.html')))
); );
} }

View File

@@ -51,18 +51,18 @@ const SOFTWARE_DEFAULT_CONFIG = {
Config.init = () => { Config.init = () => {
const urlConfig = Url.getConfig(); const urlConfig = Url.getConfig();
Config.BOARD = { Config.BOARD = {
...goog.getJSON(path.join(Env.boardDirPath, 'config.json'), BOARD_DEFAULT_CONFIG), ...goog.readJsonSync(path.join(Env.boardDirPath, 'config.json'), BOARD_DEFAULT_CONFIG),
...urlConfig ...urlConfig
}; };
if (typeof Config.BOARD.board === 'string' if (typeof Config.BOARD.board === 'string'
&& path.extname(Config.BOARD.board) === '.json') { && path.extname(Config.BOARD.board) === '.json') {
Config.BOARD.board = goog.getJSON(path.join(Env.boardDirPath, Config.BOARD.board)); Config.BOARD.board = goog.readJsonSync(path.join(Env.boardDirPath, Config.BOARD.board));
} }
let pathPrefix = '../'; let pathPrefix = '../';
Config.SOFTWARE = goog.getJSON(path.join(Env.srcDirPath, 'sw-config.json'), SOFTWARE_DEFAULT_CONFIG); Config.SOFTWARE = goog.readJsonSync(path.join(Env.srcDirPath, 'sw-config.json'), SOFTWARE_DEFAULT_CONFIG);
Config.pathPrefix = pathPrefix; Config.pathPrefix = pathPrefix;
Env.hasSocketServer = Config.SOFTWARE?.webSocket?.enabled ? true : false; Env.hasSocketServer = Config.SOFTWARE?.webSocket?.enabled ? true : false;

View File

@@ -20,7 +20,7 @@ class ContextMenu {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/context-menu-item.html', 'html/context-menu-item.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/context-menu-item.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/context-menu-item.html')))
); );
this.getItem = (name, hotKey) => HTMLTemplate.get('html/context-menu-item.html').render({ name, hotKey }); this.getItem = (name, hotKey) => HTMLTemplate.get('html/context-menu-item.html').render({ name, hotKey });

View File

@@ -24,16 +24,16 @@ class EditorAce extends EditorBase {
static { static {
this.CTRL_BTNS = ['resetFontSize', 'increaseFontSize', 'decreaseFontSize']; this.CTRL_BTNS = ['resetFontSize', 'increaseFontSize', 'decreaseFontSize'];
this.CTRL_BTN_TEMPLATE = '<div m-id="{{d.mId}}" class="code-editor-btn setFontSize"></div>'; this.CTRL_BTN_TEMPLATE = '<div m-id="{{d.mId}}" class="code-editor-btn setFontSize"></div>';
this.MODE_MAP = goog.getJSON(path.join(Env.templatePath, 'json/ace-mode-map.json')); this.MODE_MAP = goog.readJsonSync(path.join(Env.templatePath, 'json/ace-mode-map.json'));
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-code.html', 'html/editor/editor-code.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-code.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-code.html')))
); );
if (['zh-hans', 'zh-hant'].includes(Msg.nowLang)) { if (['zh-hans', 'zh-hant'].includes(Msg.nowLang)) {
ace.config.setMessages( ace.config.setMessages(
goog.getJSON(path.join(Env.templatePath, `json/ace.i18n.${Msg.nowLang}.json`)) goog.readJsonSync(path.join(Env.templatePath, `json/ace.i18n.${Msg.nowLang}.json`))
); );
} }
} }

View File

@@ -46,12 +46,12 @@ class EditorBlockly extends EditorBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-blockly.html', 'html/editor/editor-blockly.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-blockly.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-blockly.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'xml/default-categories.xml', 'xml/default-categories.xml',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'xml/default-categories.xml'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'xml/default-categories.xml')))
); );
this.$blockly = $('<div class="page-item"></div>'); this.$blockly = $('<div class="page-item"></div>');

View File

@@ -28,12 +28,12 @@ class EditorMd extends EditorBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-md.html', 'html/editor/editor-md.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-md.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-md.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-md-btns.html', 'html/editor/editor-md-btns.html',
goog.get(path.join(Env.templatePath, 'html/editor/editor-md-btns.html')) goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-md-btns.html'))
); );
marked.use(markedKatex({ throwOnError: false })); marked.use(markedKatex({ throwOnError: false }));

View File

@@ -49,12 +49,12 @@ class EditorMix extends EditorBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-mix.html', 'html/editor/editor-mix.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-mix.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-mix.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-mix-btns.html', 'html/editor/editor-mix-btns.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-mix-btns.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-mix-btns.html')))
); );
} }

View File

@@ -25,7 +25,7 @@ class EditorMonaco extends EditorBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-code.html', 'html/editor/editor-code.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-code.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-code.html')))
); );
this.$monaco = $('<div class="page-item"></div>'); this.$monaco = $('<div class="page-item"></div>');

View File

@@ -18,7 +18,7 @@ class EditorUnknown extends EditorBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-unknown.html', 'html/editor/editor-unknown.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-unknown.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-unknown.html')))
); );
} }

View File

@@ -17,7 +17,7 @@ class EditorWelcome extends EditorBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-welcome.html', 'html/editor/editor-welcome.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-welcome.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-welcome.html')))
); );
} }

View File

@@ -42,12 +42,12 @@ class EditorsManager extends PagesManager {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-manager.html', 'html/editor/editor-manager.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-manager.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-manager.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/editor/editor-tab.html', 'html/editor/editor-tab.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-tab.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-tab.html')))
); );
this.typesRegistry = new Registry(); this.typesRegistry = new Registry();

View File

@@ -34,12 +34,12 @@ const { USER } = Config;
class FileTree extends Component { class FileTree extends Component {
static { static {
this.FILE_ICON_MAP = goog.getJSON(path.join(Env.templatePath, 'json/file-icons.json')); this.FILE_ICON_MAP = goog.readJsonSync(path.join(Env.templatePath, 'json/file-icons.json'));
this.FOLDER_ICON_MAP = goog.getJSON(path.join(Env.templatePath, 'json/folder-icons.json')); this.FOLDER_ICON_MAP = goog.readJsonSync(path.join(Env.templatePath, 'json/folder-icons.json'));
HTMLTemplate.add( HTMLTemplate.add(
'html/file-tree.html', 'html/file-tree.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/file-tree.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/file-tree.html')))
); );
} }

View File

@@ -39,7 +39,7 @@ class FooterBar extends Component {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/footerbar.html', 'html/footerbar.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/footerbar.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/footerbar.html')))
); );
} }

View File

@@ -25,7 +25,7 @@ class FooterLayerBoardConfig extends FooterLayer {
static { static {
// 弹层模板 // 弹层模板
this.menuHTMLTemplate = new HTMLTemplate( this.menuHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-board-config.html')) goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-board-config.html'))
); );
} }

View File

@@ -25,7 +25,7 @@ class FooterLayerExample extends FooterLayer {
static { static {
// 弹层模板 // 弹层模板
this.menuHTMLTemplate = new HTMLTemplate( this.menuHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-example.html')) goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-example.html'))
); );
} }

View File

@@ -21,15 +21,15 @@ class FooterLayerMessage extends FooterLayer {
// 弹层模板 // 弹层模板
static { static {
this.menuHTMLTemplate = new HTMLTemplate( this.menuHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message.html')) goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message.html'))
); );
this.menuItemHTMLTemplate = new HTMLTemplate( this.menuItemHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message-item.html')) goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message-item.html'))
); );
this.menuItemWithIconHTMLTemplate = new HTMLTemplate( this.menuItemWithIconHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message-item-with-icon.html')) goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message-item-with-icon.html'))
); );
this.STYLES = ['primary', 'secondary', 'success', 'danger', 'warning']; this.STYLES = ['primary', 'secondary', 'success', 'danger', 'warning'];

View File

@@ -12,7 +12,7 @@ const { Env, XML, Msg } = Mixly;
class FooterLayer { class FooterLayer {
static { static {
// 弹层模板和一些默认配置项 // 弹层模板和一些默认配置项
this.TEMPLATE = goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer.html')); this.TEMPLATE = goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer.html'));
this.DEFAULT_CONFIG_TIPPY = { this.DEFAULT_CONFIG_TIPPY = {
allowHTML: true, allowHTML: true,
trigger: 'manual', trigger: 'manual',

View File

@@ -48,7 +48,7 @@ window.addEventListener('load', () => {
} }
const app = new App($('body')[0]); const app = new App($('body')[0]);
Mixly.app = app; Mixly.app = app;
const $xml = $(goog.get(Env.boardIndexPath)); const $xml = $(goog.readFileSync(Env.boardIndexPath));
let scrpitPaths = []; let scrpitPaths = [];
let cssPaths = []; let cssPaths = [];
let $categories = null; let $categories = null;

View File

@@ -28,7 +28,7 @@ class Nav extends Component {
*/ */
HTMLTemplate.add( HTMLTemplate.add(
'html/nav/nav.html', 'html/nav/nav.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/nav.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/nav.html')))
); );
/** /**
@@ -37,7 +37,7 @@ class Nav extends Component {
*/ */
HTMLTemplate.add( HTMLTemplate.add(
'html/nav/nav-btn.html', 'html/nav/nav-btn.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/nav-btn.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/nav-btn.html')))
); );
/** /**
@@ -46,7 +46,7 @@ class Nav extends Component {
*/ */
HTMLTemplate.add( HTMLTemplate.add(
'html/nav/nav-item-container.html', 'html/nav/nav-item-container.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/nav-item-container.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/nav-item-container.html')))
); );
/** /**
@@ -55,7 +55,7 @@ class Nav extends Component {
*/ */
HTMLTemplate.add( HTMLTemplate.add(
'html/nav/nav-item.html', 'html/nav/nav-item.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/nav-item.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/nav-item.html')))
); );
/** /**
@@ -64,7 +64,7 @@ class Nav extends Component {
*/ */
HTMLTemplate.add( HTMLTemplate.add(
'html/nav/board-selector-div.html', 'html/nav/board-selector-div.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/board-selector-div.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/board-selector-div.html')))
); );
/** /**
@@ -73,7 +73,7 @@ class Nav extends Component {
*/ */
HTMLTemplate.add( HTMLTemplate.add(
'html/nav/port-selector-div.html', 'html/nav/port-selector-div.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/port-selector-div.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/port-selector-div.html')))
); );
Nav.Scope = { Nav.Scope = {

View File

@@ -23,7 +23,7 @@ class SideBarLibs extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/sidebar/sidebar-libs.html', 'html/sidebar/sidebar-libs.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/sidebar-libs.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/sidebar-libs.html')))
); );
} }

View File

@@ -38,7 +38,7 @@ class SideBarLocalStorage extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/sidebar/sidebar-local-storage-open-folder.html', 'html/sidebar/sidebar-local-storage-open-folder.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/sidebar-local-storage-open-folder.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/sidebar-local-storage-open-folder.html')))
); );
} }

View File

@@ -31,22 +31,22 @@ class SideBarsManager extends PagesManager {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/sidebar/left-sidebars-manager.html', 'html/sidebar/left-sidebars-manager.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/left-sidebars-manager.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/left-sidebars-manager.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/sidebar/left-sidebars-tab.html', 'html/sidebar/left-sidebars-tab.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/left-sidebars-tab.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/left-sidebars-tab.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/sidebar/right-sidebars-manager.html', 'html/sidebar/right-sidebars-manager.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/right-sidebars-manager.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/right-sidebars-manager.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/sidebar/right-sidebars-tab.html', 'html/sidebar/right-sidebars-tab.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/right-sidebars-tab.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/right-sidebars-tab.html')))
); );
this.typesRegistry = new Registry(); this.typesRegistry = new Registry();

View File

@@ -32,17 +32,17 @@ class StatusBarAmpy extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-ampy.html', 'html/statusbar/statusbar-ampy.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-ampy-open-fs.html', 'html/statusbar/statusbar-ampy-open-fs.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy-open-fs.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy-open-fs.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-ampy-editor-empty.html', 'html/statusbar/statusbar-ampy-editor-empty.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy-editor-empty.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy-editor-empty.html')))
); );
} }

View File

@@ -41,7 +41,7 @@ class Panel extends Component {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-fs-panel.html', 'html/statusbar/statusbar-fs-panel.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-fs-panel.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-fs-panel.html')))
); );
} }
@@ -195,7 +195,7 @@ class StatusBarFS extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-fs.html', 'html/statusbar/statusbar-fs.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-fs.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-fs.html')))
); );
} }

View File

@@ -17,7 +17,7 @@ class StatusBarLibsCode extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-libs-mix.html', 'html/statusbar/statusbar-libs-mix.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-libs-mix.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-libs-mix.html')))
); );
} }

View File

@@ -18,7 +18,7 @@ class StatusBarLibsMix extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-libs-mix.html', 'html/statusbar/statusbar-libs-mix.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-libs-mix.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-libs-mix.html')))
); );
} }

View File

@@ -28,7 +28,7 @@ class StatusBarSerialChart extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-serial-chart.html', 'html/statusbar/statusbar-serial-chart.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-serial-chart.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-serial-chart.html')))
); );
} }

View File

@@ -21,7 +21,7 @@ class StatusBarSerialOutput extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-serial-output.html', 'html/statusbar/statusbar-serial-output.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-serial-output.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-serial-output.html')))
); );
} }

View File

@@ -58,7 +58,7 @@ class StatusBarSerial extends PageBase {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbar-serial.html', 'html/statusbar/statusbar-serial.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-serial.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-serial.html')))
); );
SideBarsManager.typesRegistry.register(['serial_output'], StatusBarSerialOutput); SideBarsManager.typesRegistry.register(['serial_output'], StatusBarSerialOutput);
SideBarsManager.typesRegistry.register(['serial_chart'], StatusBarSerialChart); SideBarsManager.typesRegistry.register(['serial_chart'], StatusBarSerialChart);

View File

@@ -53,11 +53,11 @@ class StatusBarsManager extends PagesManager {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbars-manager.html', 'html/statusbar/statusbars-manager.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbars-manager.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbars-manager.html')))
); );
HTMLTemplate.add( HTMLTemplate.add(
'html/statusbar/statusbars-tab.html', 'html/statusbar/statusbars-tab.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbars-tab.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbars-tab.html')))
); );
this.typesRegistry = new Registry(); this.typesRegistry = new Registry();
this.managersRegistry = new Registry(); this.managersRegistry = new Registry();

View File

@@ -20,7 +20,7 @@ const {
class ToolboxSearcher { class ToolboxSearcher {
static { static {
this.searchHtmlTemplate = new HTMLTemplate( this.searchHtmlTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/search-div.html')) goog.readFileSync(path.join(Env.templatePath, 'html/search-div.html'))
); );
} }

View File

@@ -35,7 +35,7 @@ class Workspace extends Component {
static { static {
HTMLTemplate.add( HTMLTemplate.add(
'html/workspace.html', 'html/workspace.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/workspace.html'))) new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/workspace.html')))
); );
this.workspaces = []; this.workspaces = [];

View File

@@ -123,7 +123,7 @@ XML.convert = function (str, trimEscaped) {
for (let i of XML.TEMPLATE_CONFIG) { for (let i of XML.TEMPLATE_CONFIG) {
const { type, config, appendToBody } = i; const { type, config, appendToBody } = i;
if (XML.TEMPLATE_ENV[type]) { if (XML.TEMPLATE_ENV[type]) {
const xmlStr = goog.get(path.join(Env.templatePath, i.path)); const xmlStr = goog.readFileSync(path.join(Env.templatePath, i.path));
if (xmlStr) { if (xmlStr) {
XML.TEMPLATE_STR[type] = xmlStr; XML.TEMPLATE_STR[type] = xmlStr;
XML.TEMPLATE_STR_RENDER[type] = XML.render(xmlStr, config); XML.TEMPLATE_STR_RENDER[type] = XML.render(xmlStr, config);
@@ -139,7 +139,7 @@ if (layui._typeof(BOARD.board) === 'object') {
const boardConfig = BOARD.board[i]; const boardConfig = BOARD.board[i];
if (layui._typeof(boardConfig) === 'object' if (layui._typeof(boardConfig) === 'object'
&& layui._typeof(boardConfig.xmlPath) === 'string') { && layui._typeof(boardConfig.xmlPath) === 'string') {
const categoriesStr = goog.get(path.join(Env.boardDirPath, boardConfig.xmlPath)); const categoriesStr = goog.readFileSync(path.join(Env.boardDirPath, boardConfig.xmlPath));
if (categoriesStr) if (categoriesStr)
XML.CATEGORIES_STR[i] = categoriesStr; XML.CATEGORIES_STR[i] = categoriesStr;
} }

View File

@@ -45,7 +45,7 @@ const {
Shell Shell
} = Electron; } = Electron;
ArduShell.DEFAULT_CONFIG = goog.getJSON(path.join(Env.templatePath, 'json/arduino-cli-config.json')); ArduShell.DEFAULT_CONFIG = goog.readJsonSync(path.join(Env.templatePath, 'json/arduino-cli-config.json'));
ArduShell.binFilePath = ''; ArduShell.binFilePath = '';

View File

@@ -49,7 +49,7 @@ BU.burning = false;
BU.shell = null; BU.shell = null;
BU.FILMWARE_LAYER = new HTMLTemplate( 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({ ).render({
cancel: Msg.Lang['nav.btn.cancel'], cancel: Msg.Lang['nav.btn.cancel'],
burn: Msg.Lang['nav.btn.burn'] burn: Msg.Lang['nav.btn.burn']

View File

@@ -18,8 +18,8 @@ const fs = Mixly.require('fs');
class WikiGenerator { class WikiGenerator {
static { static {
this.WIKI_PAGE_FILE = goog.get(path.join(Env.templatePath, 'markdown/wiki-page-file.md')); this.WIKI_PAGE_FILE = goog.readFileSync(path.join(Env.templatePath, 'markdown/wiki-page-file.md'));
this.WIKI_PAGE_DIR = goog.get(path.join(Env.templatePath, 'markdown/wiki-page-dir.md')); this.WIKI_PAGE_DIR = goog.readFileSync(path.join(Env.templatePath, 'markdown/wiki-page-dir.md'));
} }
#$xml_ = null; #$xml_ = null;

View File

@@ -18,16 +18,16 @@ const {
class AmpyExt extends Ampy { class AmpyExt extends Ampy {
static { static {
this.LS = goog.get(path.join(Env.templatePath, 'python/ls.py')); this.LS = goog.readFileSync(path.join(Env.templatePath, 'python/ls.py'));
this.LS_RECURSIVE = goog.get(path.join(Env.templatePath, 'python/ls-recursive.py')); this.LS_RECURSIVE = goog.readFileSync(path.join(Env.templatePath, 'python/ls-recursive.py'));
this.LS_LONG_FORMAT = goog.get(path.join(Env.templatePath, 'python/ls-long-format.py')); this.LS_LONG_FORMAT = goog.readFileSync(path.join(Env.templatePath, 'python/ls-long-format.py'));
this.MKDIR = goog.get(path.join(Env.templatePath, 'python/mkdir.py')); this.MKDIR = goog.readFileSync(path.join(Env.templatePath, 'python/mkdir.py'));
this.MKFILE = goog.get(path.join(Env.templatePath, 'python/mkfile.py')); this.MKFILE = goog.readFileSync(path.join(Env.templatePath, 'python/mkfile.py'));
this.RENAME = goog.get(path.join(Env.templatePath, 'python/rename.py')); this.RENAME = goog.readFileSync(path.join(Env.templatePath, 'python/rename.py'));
this.RM = goog.get(path.join(Env.templatePath, 'python/rm.py')); this.RM = goog.readFileSync(path.join(Env.templatePath, 'python/rm.py'));
this.RMDIR = goog.get(path.join(Env.templatePath, 'python/rmdir.py')); this.RMDIR = goog.readFileSync(path.join(Env.templatePath, 'python/rmdir.py'));
this.GET = goog.get(path.join(Env.templatePath, 'python/get.py')); this.GET = goog.readFileSync(path.join(Env.templatePath, 'python/get.py'));
this.CWD = goog.get(path.join(Env.templatePath, 'python/cwd.py')); this.CWD = goog.readFileSync(path.join(Env.templatePath, 'python/cwd.py'));
} }
#device_ = null; #device_ = null;
@@ -223,12 +223,17 @@ class AmpyExt extends Ampy {
return this.#device_.decode(this.unhexlify(data)); return this.#device_.decode(this.unhexlify(data));
} }
async put(filename, code, timeout = 5000) { async put(filename, data, timeout = 5000) {
if (!this.isActive()) { if (!this.isActive()) {
throw new Error(Msg.Lang['ampy.portIsNotOpen']); throw new Error(Msg.Lang['ampy.portIsNotOpen']);
} }
await this.exec(`file = open('${filename}', 'wb')`, timeout); 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); const len = Math.ceil(buffer.length / 64);
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
const writeBuffer = buffer.slice(i * 64, Math.min((i + 1) * 64, buffer.length)); 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.burning = false;
BU.FILMWARE_LAYER = new HTMLTemplate( 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({ ).render({
cancel: Msg.Lang['nav.btn.cancel'], cancel: Msg.Lang['nav.btn.cancel'],
burn: Msg.Lang['nav.btn.burn'] burn: Msg.Lang['nav.btn.burn']
@@ -166,7 +166,7 @@ BU.burnByUSB = async () => {
const { web } = SELECTED_BOARD; const { web } = SELECTED_BOARD;
const { burn } = web; 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 hex2Blob = new Blob([ hexStr ], { type: 'text/plain' });
const buffer = await hex2Blob.arrayBuffer(); const buffer = await hex2Blob.arrayBuffer();
if (!buffer) { if (!buffer) {
@@ -499,7 +499,7 @@ BU.getImportModules = (code) => {
const libPath = SELECTED_BOARD.upload.libPath; const libPath = SELECTED_BOARD.upload.libPath;
for (let i = libPath.length - 1; i >= 0; i--) { for (let i = libPath.length - 1; i >= 0; i--) {
const dirname = MString.tpl(libPath[i], { indexPath: Env.boardDirPath }); 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)) { if (!(map && map instanceof Object)) {
continue; continue;
} }
@@ -603,7 +603,7 @@ BU.uploadByUSB = async (portName) => {
const importsMap = BU.getImportModules(code); const importsMap = BU.getImportModules(code);
for (let key in importsMap) { for (let key in importsMap) {
const filename = importsMap[key]['__name__']; const filename = importsMap[key]['__name__'];
const data = goog.get(importsMap[key]['__path__']); const data = goog.readFileSync(importsMap[key]['__path__']);
FSWrapper.writeFile(filename, data); FSWrapper.writeFile(filename, data);
} }
const layerNum = layer.open({ const layerNum = layer.open({
@@ -690,7 +690,7 @@ BU.uploadWithAmpy = (portName) => {
let libraries = {}; let libraries = {};
for (let key in importsMap) { for (let key in importsMap) {
const filename = importsMap[key]['__name__']; const filename = importsMap[key]['__name__'];
const data = goog.get(importsMap[key]['__path__']); const data = goog.readFileSync(importsMap[key]['__path__']);
libraries[filename] = { libraries[filename] = {
data, data,
size: importsMap[key]['__size__'] size: importsMap[key]['__size__']

View File

@@ -77,7 +77,7 @@ class FooterLayerExampleExt extends FooterLayerExample {
} }
dataToWorkspace(inPath) { 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); this.updateCode(path.extname(inPath), data);
} }
} }

View File

@@ -43,7 +43,7 @@ class WebSerial extends Serial {
this.devicesRegistry = new Registry(); this.devicesRegistry = new Registry();
this.type = Serial.type; this.type = Serial.type;
this.DEVICES_SELECT_LAYER = new HTMLTemplate( 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 () { this.getConfig = function () {

View File

@@ -49,8 +49,8 @@ class microbitFsWrapper {
* initial main.py * initial main.py
*/ */
setupFilesystem(folderPath) { setupFilesystem(folderPath) {
const uPyV1 = goog.get(path.join(folderPath, 'microbit-micropython-v1.hex')); const uPyV1 = goog.readFileSync(path.join(folderPath, 'microbit-micropython-v1.hex'));
const uPyV2 = goog.get(path.join(folderPath, 'microbit-micropython-v2.hex')); const uPyV2 = goog.readFileSync(path.join(folderPath, 'microbit-micropython-v2.hex'));
if (!uPyV1 || !uPyV2) { if (!uPyV1 || !uPyV2) {
console.error('There was an issue loading the MicroPython Hex files.'); console.error('There was an issue loading the MicroPython Hex files.');
} }

View File

@@ -8,7 +8,7 @@ const { Msg, Env } = Mixly;
if (['zh-hans', 'zh-hant'].includes(Msg.nowLang)) { if (['zh-hans', 'zh-hant'].includes(Msg.nowLang)) {
const i18nFilePath = path.join(Env.templatePath, `json/monaco.i18n.${Msg.nowLang}.json`); const i18nFilePath = path.join(Env.templatePath, `json/monaco.i18n.${Msg.nowLang}.json`);
window.monacoI18N = goog.getJSON(i18nFilePath); window.monacoI18N = goog.readJsonSync(i18nFilePath);
} else { } else {
window.monacoI18N = {}; window.monacoI18N = {};
} }

View File

@@ -24,9 +24,9 @@ Config.USER = {
* @return {void} * @return {void}
**/ **/
Config.init = () => { Config.init = () => {
Config.SOFTWARE = goog.getJSON('./sw-config.json', {}); Config.SOFTWARE = goog.readJsonSync('./sw-config.json', {});
console.log('Config.SOFTWARE:', Config.SOFTWARE); console.log('Config.SOFTWARE:', Config.SOFTWARE);
Config.BOARDS_INFO = goog.getJSON('./boards.json', {}); Config.BOARDS_INFO = goog.readJsonSync('./boards.json', {});
console.log('Config.BOARDS_INFO:', Config.BOARDS_INFO); console.log('Config.BOARDS_INFO:', Config.BOARDS_INFO);
const boardPageConfig = Url.getConfig(); const boardPageConfig = Url.getConfig();
Config.BOARD_PAGE = boardPageConfig ?? {}; Config.BOARD_PAGE = boardPageConfig ?? {};

View File

@@ -211,7 +211,7 @@ for (let i of XML.TEMPLATE_CONFIG) {
generateDom generateDom
} = i; } = i;
if (XML.TEMPLATE_ENV[type]) { if (XML.TEMPLATE_ENV[type]) {
const xmlStr = goog.get(XML.TEMPLATE_DIR_PATH + path); const xmlStr = goog.readFileSync(XML.TEMPLATE_DIR_PATH + path);
if (xmlStr) { if (xmlStr) {
XML.TEMPLATE_STR[type] = xmlStr; XML.TEMPLATE_STR[type] = xmlStr;
if (generateDom) { if (generateDom) {