UNPKG

youzanyun-devtool-worker

Version:

91 lines (90 loc) 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const spring4js_nodejs_1 = require("spring4js-nodejs"); let ToolBarService = class ToolBarService { constructor() { this.commandMap = {}; this.currentCommandsMap = {}; this._controlPanelChange = new spring4js_nodejs_1.Emitter(); this.onControlPanelChange = this._controlPanelChange.registerEvent; this._openBrowser = new spring4js_nodejs_1.Emitter(); this.onOpenBrowser = this._openBrowser.registerEvent; this._docKeyChange = new spring4js_nodejs_1.Emitter(); this.onDocKeyChange = this._docKeyChange.registerEvent; } async start() { this.commandMap[this.commandCloseAllMock.getKey()] = this.commandCloseAllMock; this.commandMap[this.commandToggleDevtool.getKey()] = this.commandToggleDevtool; this.commandMap[this.commandContentRefresh.getKey()] = this.commandContentRefresh; this.commandMap[this.commandGoBack.getKey()] = this.commandGoBack; } openBrowser(workbenchId, url) { this._openBrowser.fire({ workbenchId, url }); } async excuteCommand(workbenchId, projectId, commandKey, params = {}) { let command = this.commandMap[commandKey]; if (command) { await command.execute(workbenchId, projectId, params); } } async resetCommand(workbenchId, projectId) { let commandKeys = Object.keys(this.commandMap); for (let commandKey of commandKeys) { await this.commandMap[commandKey].reset(workbenchId, projectId); } } async updateControlPanel(workbenchId, projectId) { let commandConfigs = this.currentCommandsMap[workbenchId] || []; let commands = []; for (let commandItem of commandConfigs) { let commandKey = ''; let commandParam = null; if (typeof commandItem === 'string') { commandKey = commandItem; } else { commandKey = commandItem.key; commandParam = commandItem.params; } let command = this.commandMap[commandKey]; if (command) { let btn = await command.getDescription(workbenchId, projectId); commands.push(Object.assign(Object.assign({}, btn), { params: commandParam })); } } this._controlPanelChange.fire({ workbenchId, commands }); } async setControlPanelButton(workbenchId, projectId, commands) { this.currentCommandsMap[workbenchId] = commands; await this.updateControlPanel(workbenchId, projectId); } setDocKey({ workbenchId, docKey }) { this._docKeyChange.fire({ workbenchId, docKey }); } }; tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ToolBarService.prototype, "commandCloseAllMock", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ToolBarService.prototype, "commandToggleDevtool", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ToolBarService.prototype, "commandContentRefresh", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], ToolBarService.prototype, "commandGoBack", void 0); ToolBarService = tslib_1.__decorate([ (0, spring4js_nodejs_1.Service)() ], ToolBarService); exports.default = ToolBarService;