Skip to content

Commit

Permalink
fix: duplicate module manager load
Browse files Browse the repository at this point in the history
  • Loading branch information
everright committed Apr 19, 2022
1 parent 190e588 commit 3883028
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 40 deletions.
46 changes: 17 additions & 29 deletions src/app/electron-main/appView.ts
Original file line number Diff line number Diff line change
@@ -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<ViewZone, BrowserView> = 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;
Expand Down Expand Up @@ -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({
Expand All @@ -79,17 +70,14 @@ 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');
});
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;
}
}
14 changes: 8 additions & 6 deletions src/app/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -202,19 +202,21 @@ 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') {
returnValue = 'hook返回';
} 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') {
Expand Down
3 changes: 0 additions & 3 deletions src/core/api-manager/node/unitWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
5 changes: 3 additions & 2 deletions src/platform/node/extension-manager/lib/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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);
}
});
Expand All @@ -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);
}
});
Expand Down

0 comments on commit 3883028

Please sign in to comment.