Skip to content

Commit

Permalink
Merge pull request #23 from eolinker/feature/iframe
Browse files Browse the repository at this point in the history
Use Iframe to replace browserView ( fixed #6)
  • Loading branch information
scarqin committed May 10, 2022
2 parents 39b051d + 35feb45 commit afbf608
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 123 deletions.
6 changes: 1 addition & 5 deletions src/app/electron-main/coreView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ export class CoreViews {
this.watch();
}
watch() {
ipcMain.on('message', this.triggleEvent);
// ipcMain.on('message', this.triggleEvent);
}
triggleEvent(event, arg) {
console.log(`core view ${event.frameId}: recieve render msg=>`, arg, arg.action);
if (event.frameId !== 1) return;
switch (arg.action) {
case 'connect-dropdown': {
this.win.setTopBrowserView((arg.data.action === 'show' ? subView.mainView : subView.appView).view);
break;
}
case 'setBounds': {
//sidebar shrink or expand
break;
Expand Down
49 changes: 17 additions & 32 deletions src/app/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function createWindow(): BrowserWindow {
contextIsolation: false, // false if you want to run e2e test with Spectron
},
});
// main
if (['serve'].includes(processEnv)) {
require('electron-reload')(__dirname, {
electron: require(path.join(__dirname, '../node_modules/electron')),
Expand Down Expand Up @@ -232,40 +233,24 @@ try {
} else if (arg.action === 'hook') {
returnValue = 'hook返回';
} else if (arg.action === 'openApp') {
if (arg.data.moduleID && !arg.data.moduleID.includes('@eo-core')) {
// 如果要打开是同一app,忽略
if (subView.appView?.mainModuleID === arg.data.moduleID) {
return;
}
const module: ModuleInfo = moduleManager.getModule(arg.data.moduleID);
if (module) {
if (!subView.appView) subView.appView = new AppViews(win);
subView.appView.create(module);
}
} else {
if (subView.appView) {
subView.appView.remove();
}
}
returnValue = 'view id';
// if (arg.data.moduleID && !arg.data.moduleID.includes('@eo-core')) {
// // 如果要打开是同一app,忽略
// if (subView.appView?.mainModuleID === arg.data.moduleID) {
// return;
// }
// const module: ModuleInfo = moduleManager.getModule(arg.data.moduleID);
// if (module) {
// if (!subView.appView) subView.appView = new AppViews(win);
// subView.appView.create(module);
// }
// } else {
// if (subView.appView) {
// subView.appView.remove();
// }
// }
// returnValue = 'view id';
} else if (arg.action === 'autoResize') {
resize(arg.data.sideWidth);
} else if (arg.action === 'openModal') {
const background = arg.data.background || '#00000073';
subView.mainView.view.webContents.executeJavaScript(`
var mask = document.querySelector('#mask');
if (mask) {
mask.style.background = '${background}';
mask.style.display = 'block';
}
`);
} else if (arg.action === 'closeModal') {
subView.mainView.view.webContents.executeJavaScript(`
var mask = document.querySelector('#mask');
if (mask) {
mask.style.display = 'none';
}
`);
} else {
returnValue = 'Invalid data';
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/market/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"logo": "icon-apps",
"main_debug": "http://localhost:8080",
"moduleID": "default",
"moduleName": "插件广场",
"moduleName": "拓展广场",
"moduleType": "app",
"features": {
"export": {
Expand All @@ -21,7 +21,7 @@
"extension": "json"
},
"configuration": {
"title": "插件广场配置",
"title": "拓展广场配置",
"properties": {
"core.market.url": {
"type": "string",
Expand Down
1 change: 0 additions & 1 deletion src/core/market/browser/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import App from './App.vue';
import router from './router.js';
import 'windi.css';
import { createPinia } from 'pinia';

createApp(App).use(router).use(Antd).use(createPinia()).mount('#app');
15 changes: 0 additions & 15 deletions src/platform/electron-browser/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,6 @@ if (apiAccessRules.includes('hook')) {
window.eo.tempApi = (params) => {
return ipcRenderer.sendSync('eo-sync', params);
};
window.eo.openModal = (background) => {
background = background || '#00000073';
return ipcRenderer.sendSync('eo-sync', { action: 'openModal', data: { background: background } });
};
window.eo.closeModal = () => {
return ipcRenderer.sendSync('eo-sync', { action: 'closeModal' });
};
window.eo.toogleViewZIndex = (visible) => {
ipcRenderer.send('message', {
action: 'connect-dropdown',
data: {
action: visible ? 'show' : 'hide',
},
});
};
window.eo.autoResize = (sideWidth) => {
ipcRenderer.send('eo-sync', { action: 'autoResize', data: { sideWidth: sideWidth } });
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class ApiGroupEditComponent implements OnInit {
this.modalRef.destroy();
this.messageService.send({ type: 'updateGroupSuccess', data: { group: result.data } });
} else {
console.log(result.data);
console.error(result.data);
}
});
}
Expand All @@ -78,7 +78,7 @@ export class ApiGroupEditComponent implements OnInit {
this.modalRef.destroy();
this.messageService.send({ type: 'updateGroupSuccess', data: { group: result.data } });
} else {
console.log(result.data);
console.error(result.data);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<h1 class="fs20 fwb">概况</h1>
<nz-divider></nz-divider>
<div class="r_row f_js">
<div class="f_row_ac">
<div>
<div class="card_container">
<div class="card_item">
<nz-card [nzActions]="[exportButton]">
<nz-card-meta nzTitle="导出" nzDescription="导出 API 数据"></nz-card-meta>
</nz-card>
<ng-template #exportButton>
<i (click)="export()" nz-icon nzType="export"></i>
</ng-template>
</div>
<div class="ml15">
<div class="card_item">
<nz-card [nzActions]="[syncButton]">
<nz-card-meta nzTitle="推送" nzDescription="将 API 推送/同步到其他平台"></nz-card-meta>
</nz-card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.overview_container{
width: 50%;
width: 70%;
margin: 0 auto;
padding: 20px 0;
}
nz-card{
min-width: 220px;
.card_container{
display: grid;
grid-template-columns: repeat(auto-fill, 250px);
grid-column-gap: 20px;
grid-row-gap: 20px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export class ApiTestHistoryComponent implements OnInit {
private getList() {
this.storage.run('apiTestHistoryLoadAllByApiDataID', [this.apiID], (result: StorageHandleResult) => {
if (result.status === StorageHandleStatus.success) {
console.log(result.data)
result.data.forEach((val: any) => {
this.parseItem(val);
});
Expand Down
12 changes: 10 additions & 2 deletions src/workbench/browser/src/app/pages/pages.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
<eo-setting></eo-setting>
<eo-sidebar></eo-sidebar>
<div class="home fg1">
<router-outlet></router-outlet>
<router-outlet *ngIf="!loadedIframe"></router-outlet>
<iframe
*ngIf="!this.sidebar.currentModule.isOffical"
src="http://localhost:8080"
id="app_iframe"
frameborder="no"
border="0"
style="width: calc(100vw - 90px);height: calc(100vh - var(--NAVBAR_HEIGHT) - 4px);"
></iframe>
</div>
</div>
<!-- <eo-toolbar></eo-toolbar> -->
<eo-toolbar></eo-toolbar>
33 changes: 27 additions & 6 deletions src/workbench/browser/src/app/pages/pages.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import { Component, OnInit } from '@angular/core';
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { SidebarService } from '../shared/components/sidebar/sidebar.service';

@Component({
selector: 'eo-pages',
templateUrl: './pages.component.html',
styleUrls: ['./pages.component.scss']
styleUrls: ['./pages.component.scss'],
})
export class PagesComponent implements OnInit {

constructor() { }

loadedIframe = false;
constructor(private cdRef: ChangeDetectorRef, public sidebar: SidebarService) {}
ngOnInit(): void {
this.watchSidebarItemChange();
}
private watchSidebarItemChange() {
this.sidebar.appChanged$.pipe().subscribe(() => {
this.loadedIframe = false;
if (!this.sidebar.currentModule.isOffical) {
//add loading
setTimeout(() => {
let iframe = document.getElementById('app_iframe') as HTMLIFrameElement;
//add auto script
let iframeDocument = iframe.contentWindow.document;
var el = iframeDocument.createElement('script');
el.text = `window.eo=window.parent.eo;\n`;
iframeDocument.body.appendChild(el);
//loading finish
iframe.onload = () => {
this.loadedIframe = true;
this.cdRef.detectChanges(); // solution
};
}, 0);
}
});
}

}
7 changes: 3 additions & 4 deletions src/workbench/browser/src/app/pages/pages.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { CommonModule } from '@angular/common';
import { PagesRoutingModule } from './pages-routing.module';
import { SettingModule } from './setting/setting.module'
import { PagesComponent } from './pages.component';
import { SharedModule } from '../shared/shared.module';

@NgModule({
declarations: [PagesComponent],
imports: [PagesRoutingModule, FormsModule, SharedModule, SettingModule],
exports: []
imports: [PagesRoutingModule, CommonModule, SharedModule],
exports: [],
})
export class PagesModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</ul>
</nz-dropdown-menu>
</div>
<!-- <span (click)="openApp(item.moduleID)" *ngFor="let item of getModules()" >&nbsp;{{ item.moduleName }}&nbsp;</span> -->
<span class="mr15" nz-dropdown (nzVisibleChange)="changeHelpVisible($event)" [nzDropdownMenu]="menu">
<span class="mr15" nz-dropdown [nzDropdownMenu]="menu">
<i nz-icon nzType="question-circle" class="fs24" nzTheme="outline"></i>
</span>
<nz-dropdown-menu #menu="nzDropdownMenu">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ export class NavbarComponent implements OnInit {
});
});
}
changeHelpVisible(visible) {
if(this.isElectron){
window.eo.toogleViewZIndex(visible);
}
}
minimize() {
this.electron.ipcRenderer.send('message', {
action: 'minimize',
Expand Down Expand Up @@ -79,8 +74,4 @@ export class NavbarComponent implements OnInit {
getModules(): Array<ModuleInfo> {
return Array.from(this.modules.values());
}

openApp(moduleID: string) {
window.eo.openApp({ moduleID: moduleID });
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<div class="eo_sidebar" [ngClass]="{ eo_sidebar_shrink: isCollapsed }">
<a
(click)="openApp(item.moduleID)"
(click)="clickModule(item)"
*ngFor="let item of this.modules"
class="sidebar_item"
nz-tooltip
(nzTooltipVisibleChange)="tooltipVisibleChange($event)"
[nzTooltipTitle]="item.moduleName"
[routerLink]="item.route ? item.route : '/home/blank'"
[ngClass]="{ sidebar_item_active: item.moduleID === this.moduleID }"
[ngClass]="{ sidebar_item_active: item.moduleID === this.sidebar.currentModule.moduleID }"
>
<span *ngIf="item.logo.includes('icon-')" class="iconfont fs28" [ngClass]="item.logo"></span>
<img *ngIf="!item.logo.includes('icon-')" [src]="item.logo" />
Expand Down
Loading

0 comments on commit afbf608

Please sign in to comment.