diff --git a/src/app/electron-main/appView.ts b/src/app/electron-main/appView.ts index 8c5e74d3d..0823ac1f2 100644 --- a/src/app/electron-main/appView.ts +++ b/src/app/electron-main/appView.ts @@ -1,43 +1,35 @@ -import ModuleManager from '../../platform/node/extension-manager/lib/manager'; -import { ModuleInfo, ModuleManagerInterface, ModuleType } from '../../platform/node/extension-manager/types'; +import { ModuleInfo, ModuleType } from '../../platform/node/extension-manager/types'; import { getViewBounds, SidePosition, ViewBounds, ViewZone } from '../../shared/common/bounds'; import { BrowserView, BrowserWindow } from 'electron'; import * as path from 'path'; import { BrowserViewInstance } from '../../platform/electron-main/browserView/browserView'; import { processEnv } from '../../platform/node/constant'; -const browserViews: Map = new Map(); -const moduleManager: ModuleManagerInterface = ModuleManager(); export class AppViews { - mainModuleID: string = 'default'; - moduleID: string = 'default'; + mainModuleID: string; view: BrowserView; sidePosition: SidePosition = SidePosition.left; constructor(private win: BrowserWindow) {} /** - * 根据模块ID启动app模块的加载 - * @param moduleID + * 加载app模块 + * @param module */ - create(moduleID: string) { - this.moduleID = moduleID; - const module: ModuleInfo = moduleManager.getModule(moduleID, true); + create(module: ModuleInfo) { if (module && module.moduleType === ModuleType.app) { - let refresh: boolean = false; if (module.isApp && this.mainModuleID !== module.moduleID) { this.mainModuleID = module.moduleID; this.sidePosition = module.sidePosition; - refresh = true; } - this.createAppView(module, refresh); - } - if (module.main_node) { - const main_node = require(module.main_node); - if (main_node.module && typeof main_node.module === 'object') { - const _fun = main_node.module; - console.log(_fun); - _fun.setup({ - appView: this.view - }); + this.createAppView(module); + + if (module.main_node) { + const main_node = require(module.main_node); + if (main_node.module && typeof main_node.module === 'object') { + const _fun = main_node.module; + _fun.setup({ + appView: this.view + }); + } } } return this.view; @@ -67,9 +59,8 @@ export class AppViews { /** * 创建主视图,主要从模块载入文件 * @param module - * @param window */ - private createAppView(module: ModuleInfo, refresh: boolean) { + private createAppView(module: ModuleInfo) { const windBounds = this.win.getContentBounds(); const _bounds: ViewBounds = getViewBounds(ViewZone.main, windBounds.width, windBounds.height, this.sidePosition); let _view = new BrowserViewInstance({ @@ -79,7 +70,7 @@ export class AppViews { preload: module.preload, viewPath: processEnv === 'development' && module.main_debug ? module.main_debug : module.main, }).init(this.win); - this.remove() + this.remove(); this.view = _view; this.view.webContents.once('did-finish-load', () => { _view.setBackgroundColor('#FFF'); @@ -87,9 +78,6 @@ export class AppViews { this.view.webContents.once('dom-ready', () => { this.rebuildBounds(); require('@electron/remote/main').enable(this.view.webContents); - //_view.setAutoResize({ width: true }); - //this.win.webContents.executeJavaScript(`window.getModules1()`); }); - //return this.view; } } diff --git a/src/app/electron-main/main.ts b/src/app/electron-main/main.ts index 6f422f791..27966a47f 100644 --- a/src/app/electron-main/main.ts +++ b/src/app/electron-main/main.ts @@ -3,7 +3,7 @@ import { EoUpdater } from './updater'; import * as path from 'path'; import * as os from 'os'; import ModuleManager from '../../platform/node/extension-manager/lib/manager'; -import { ModuleManagerInterface } from '../../platform/node/extension-manager'; +import { ModuleInfo, ModuleManagerInterface } from '../../platform/node/extension-manager'; import { StorageHandleStatus, StorageProcessType } from '../../platform/browser/IndexedDB'; import { AppViews } from './appView'; import { CoreViews } from './coreView'; @@ -68,7 +68,7 @@ function createWindow(): BrowserWindow { subView.appView = new AppViews(win); subView.mainView = new CoreViews(win); subView.mainView.create(); - subView.appView.create('default'); + subView.appView.create(moduleManager.getModule('default')); }); loadPage(); @@ -202,7 +202,7 @@ try { } returnValue = Object.assign(data, { modules: moduleManager.getModules() }); } else if (arg.action === 'getSideModuleList') { - returnValue = moduleManager.getSideModuleList(subView.appView.mainModuleID); + returnValue = moduleManager.getSideModuleList(subView.appView.mainModuleID || 'default'); } else if (arg.action === 'getSidePosition') { returnValue = subView.appView.sidePosition; } else if (arg.action === 'hook') { @@ -210,11 +210,13 @@ try { } else if (arg.action === 'openApp') { if (arg.data.moduleID) { // 如果要打开是同一app,忽略 - if (subView.appView.moduleID === arg.data.moduleID) { + if (subView.appView.mainModuleID === arg.data.moduleID) { return; } - // subView.appView = new AppViews(win); - subView.appView.create(arg.data.moduleID); + const module: ModuleInfo = moduleManager.getModule(arg.data.moduleID); + if (module) { + subView.appView.create(module); + } } returnValue = 'view id'; } else if (arg.action === 'autoResize') { diff --git a/src/core/api-manager/node/unitWorker.ts b/src/core/api-manager/node/unitWorker.ts index b86e0ace2..b6d5ee7c9 100644 --- a/src/core/api-manager/node/unitWorker.ts +++ b/src/core/api-manager/node/unitWorker.ts @@ -34,11 +34,8 @@ class UnitWorker { export const module = { works: {}, setup(eo: any) { - console.log('setup'); ipcMain.removeAllListeners('unitTest'); ipcMain.on('unitTest', function (event, message) { - console.log('unitTest run'); - console.log(message); const id = message.id; switch (message.action) { case 'ajax': { diff --git a/src/platform/node/extension-manager/lib/manager.ts b/src/platform/node/extension-manager/lib/manager.ts index 414a707db..1117bb822 100644 --- a/src/platform/node/extension-manager/lib/manager.ts +++ b/src/platform/node/extension-manager/lib/manager.ts @@ -3,6 +3,7 @@ import { ModuleHandler } from './handler'; import { CoreHandler } from './core'; import { ModuleHandlerResult, ModuleInfo, ModuleManagerInfo, ModuleManagerInterface, ModuleType } from '../types'; import * as path from 'path'; +import { isNotEmpty } from '../../../..//shared/common/common'; export class ModuleManager implements ModuleManagerInterface { /** @@ -148,7 +149,7 @@ export class ModuleManager implements ModuleManagerInterface { moduleNames.forEach((moduleName: string) => { // 这里要加上try catch,避免异常 const moduleInfo: ModuleInfo = this.moduleHandler.info(moduleName); - if (moduleInfo.moduleID) { + if (isNotEmpty(moduleInfo.moduleID)) { this.set(moduleInfo); } }); @@ -163,7 +164,7 @@ export class ModuleManager implements ModuleManagerInterface { const moduleNames: string[] = coreHandler.list(); moduleNames.forEach((moduleName: string) => { const moduleInfo: ModuleInfo = coreHandler.info(moduleName); - if (moduleInfo.moduleID) { + if (isNotEmpty(moduleInfo.moduleID)) { this.set(moduleInfo); } });