Skip to content

Commit

Permalink
feat: remote (#30)
Browse files Browse the repository at this point in the history
* stash

* stash inceptor

* feat: request success

* fix: resolve conflict

* fix: resolve conflict

* fix: resolve conflict

* fix: style

* feat: add about page

* test

* feat: response http interceptor

* stash

* feat: basic data

* feat:add api

* fix: path error

* feat: connect mock api

* update code

* fix: code conflict

* Delete package-lock.json

* update yarn

* test

* 暂存

* 暂存

* 暂存

* update code

* update code

* update code

* update code

* update code

* update code

* update code

* feat: remote x-api-key token

* 隐藏mock

* update code

* fix: api headers judge error

* fix: lack http batch remove api

* fix some style issue

* update code

* fix code conflict

* fix some thing

* fix: lack sort api&group

* fix packing

* update code

Co-authored-by: buqiyuan <[email protected]>
  • Loading branch information
scarqin and buqiyuan authored Jun 14, 2022
1 parent 2dc4985 commit 7ef31d9
Show file tree
Hide file tree
Showing 104 changed files with 2,131 additions and 18,806 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"extends": [],
"rules": {
"prefer-arrow/prefer-arrow-functions": 0,
"@typescript-eslint/member-ordering": 0,
"@angular-eslint/directive-selector": 0,
"@angular-eslint/component-selector": [
"error",
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ out/
*.js
*.js.map
*.webpack.js
!src/core/market/browser/**/*.js
!src/core/market/browser/dist/icon.png
!src/workbench/node/request/**/*.js
!/api/*.js
!/build/*.js
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@
// },
// "**/*.js.map": true,
// }
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"**/*.lock": true,
}
}
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"test:workbench": "cd src/workbench/browser && yarn test",
"electron:serve": "wait-on tcp:4200 && npm run electron:dev",
"electron:dev:static": "npm run electron:tsc && electron .",
"electron:dev": "npm run electron:tsc && npm run copyfile:out && electron . --development",
"build": "npm-run-all -s build:workbench electron:tsc && electron-builder build && node ./build/afterBuild.js",
"electron:dev": "npm run electron:tsc && electron . --development",
"build": "npm-run-all -s build:workbench electron:tsc && electron-builder build",
"build:static": "npm run electron:tsc && electron-builder build",
"release": "npm-run-all -s build:workbench electron:tsc && electron-builder --publish=always",
"test": "npm-run-all --serial test:*",
Expand All @@ -30,31 +30,23 @@
"dependencies": {
"@bqy/node-module-alias": "^1.0.1",
"@electron/remote": "2.0.8",
"@koa/cors": "3.3.0",
"@koa/router": "10.1.1",
"content-disposition": "^0.5.4",
"copyfiles": "2.4.1",
"cross-spawn": "^7.0.3",
"crypto-js": "^4.1.1",
"dexie": "3.2.2",
"electron-log": "^4.4.7",
"electron-updater": "^5.0.1",
"express": "4.18.1",
"fix-path": "3.0.0",
"form-data": "^4.0.0",
"http-proxy-middleware": "3.0.0-beta.0",
"iconv-lite": "^0.6.3",
"koa": "2.13.4",
"koa-bodyparser": "4.3.0",
"mockjs": "1.1.0",
"npm": "6.14.17",
"portfinder": "1.0.28",
"resolve": "^1.22.0",
"rxjs": "7.5.5",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@types/cross-spawn": "6.0.2",
"@types/koa": "2.13.4",
"@types/koa__router": "8.0.11",
"@types/node": "17.0.32",
"@typescript-eslint/eslint-plugin": "5.23.0",
"@typescript-eslint/parser": "5.23.0",
Expand Down
24 changes: 12 additions & 12 deletions src/app/electron-browser/IndexedDB/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { isNotEmpty } from 'eo/shared/common/common';
import * as fs from 'fs';
import * as path from 'path';
import {
StorageHandleResult,
StorageHandleStatus,
StorageRes,
StorageResStatus,
StorageHandleArgs,
StorageProcessType,
} from 'eo/platform/browser/IndexedDB';
import { Storage } from 'eo/platform/browser/IndexedDB/lib';
} from '../../../../workbench/browser/src/app/shared/services/storage/index.model';
import { IndexedDBStorage } from '../../../../workbench/browser/src/app/shared/services/storage/IndexedDB/lib/index';

class StorageService {
private ipcRenderer: typeof ipcRenderer;
Expand All @@ -29,24 +29,24 @@ class StorageService {
*/
private storageListenHandle(args: StorageHandleArgs): void {
const action: string = args.action || undefined;
const handleResult: StorageHandleResult = {
status: StorageHandleStatus.invalid,
const handleResult: StorageRes = {
status: StorageResStatus.invalid,
data: undefined,
callback: args.callback || null,
};
if (Storage && Storage[action] && typeof Storage[action] === 'function') {
Storage[action](...args.params).subscribe(
if (IndexedDBStorage && IndexedDBStorage[action] && typeof IndexedDBStorage[action] === 'function') {
IndexedDBStorage[action](...args.params).subscribe(
(result: any) => {
handleResult.data = result;
if (isNotEmpty(result)) {
handleResult.status = StorageHandleStatus.success;
handleResult.status = StorageResStatus.success;
} else {
handleResult.status = StorageHandleStatus.empty;
handleResult.status = StorageResStatus.empty;
}
this.storageListenHandleNotify(args.type, handleResult);
},
(error: any) => {
handleResult.status = StorageHandleStatus.error;
handleResult.status = StorageResStatus.error;
this.storageListenHandleNotify(args.type, handleResult);
}
);
Expand All @@ -60,7 +60,7 @@ class StorageService {
* @param type
* @param result
*/
private storageListenHandleNotify(type: string, result: StorageHandleResult): void {
private storageListenHandleNotify(type: string, result: StorageRes): void {
try {
if (StorageProcessType.default === type) {
this.ipcRenderer.send('eo-storage', { type: 'result', result: result });
Expand Down
65 changes: 34 additions & 31 deletions src/app/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ import { app, BrowserWindow, ipcMain, screen } from 'electron';
import { EoUpdater } from './updater';
import * as path from 'path';
import * as os from 'os';
import ModuleManager from 'eo/platform/node/extension-manager/lib/manager';
import { ModuleManagerInterface } from 'eo/platform/node/extension-manager';
import { StorageHandleStatus, StorageProcessType } from 'eo/platform/browser/IndexedDB';
import { processEnv } from 'eo/platform/node/constant';
import { proxyOpenExternal } from 'eo/shared/common/browserView';
import { deleteFile, readJson } from 'eo/shared/node/file';
import { STORAGE_TEMP as storageTemp } from 'eo/shared/common/constant';
import { UnitWorkerModule } from 'eo/workbench/node/unitWorker';
import Configuration from 'eo/platform/node/configuration/lib';
import ModuleManager from '../../platform/node/extension-manager/lib/manager';
import { ModuleManagerInterface } from '../../platform/node/extension-manager';
// TODO 引入问题
// import {
// StorageResStatus,
// StorageProcessType,
// } from '../../workbench/browser/src/app/shared/services/storage/index.model';
import { processEnv } from '../../platform/node/constant';
import { proxyOpenExternal } from '../../shared/common/browserView';
import { deleteFile, readJson } from '../../shared/node/file';
import { STORAGE_TEMP as storageTemp } from '../../shared/common/constant';
import { UnitWorkerModule } from '../../workbench/node/unitWorker';
import Configuration from '../../platform/node/configuration/lib';
import { ConfigurationInterface } from 'src/platform/node/configuration';
import { MockServer } from 'eo/platform/node/mock-server';
// import { MockServer } from 'eo/platform/node/mock-server';

let win: BrowserWindow = null;
export const subView = {
appView: null,
mainView: null,
};
const eoUpdater = new EoUpdater();
const mockServer = new MockServer();
// const mockServer = new MockServer();
const moduleManager: ModuleManagerInterface = ModuleManager();
const configuration: ConfigurationInterface = Configuration();
// Remote
Expand All @@ -36,8 +40,8 @@ function createWindow(): BrowserWindow {
const size = electronScreen.getPrimaryDisplay().workAreaSize;
// Create the browser window.
win = new BrowserWindow({
width: Math.round(size.width * 0.8),
height: Math.round(size.height * 0.8),
width: Math.round(size.width * 0.85),
height: Math.round(size.height * 0.85),
useContentSize: true, // 这个要设置,不然计算显示区域尺寸不准
frame: os.type() === 'Darwin' ? true : false, //mac use default frame
webPreferences: {
Expand All @@ -49,7 +53,7 @@ function createWindow(): BrowserWindow {
},
});
proxyOpenExternal(win);
let loadPage = () => {
let loadPage = async () => {
const file: string =
processEnv === 'development'
? 'http://localhost:4200'
Expand All @@ -63,6 +67,8 @@ function createWindow(): BrowserWindow {
UnitWorkerModule.setup({
view: win,
});
// 启动mock服务
// await mockServer.start(win as any);
};
win.webContents.on('did-fail-load', (event, errorCode) => {
console.error('did-fail-load', errorCode);
Expand Down Expand Up @@ -91,8 +97,6 @@ try {
app.on('ready', async () => {
setTimeout(createWindow, 400);
eoUpdater.check();
// 启动mock服务
await mockServer.start();
});
//!TODO only api manage app need this
// setupUnit(subView.appView);
Expand All @@ -104,7 +108,7 @@ try {
if (process.platform !== 'darwin') {
app.quit();
}
mockServer.stop();
// mockServer.stop();
});

app.on('activate', () => {
Expand Down Expand Up @@ -140,18 +144,19 @@ try {

ipcMain.on('eo-storage', (event, args) => {
let returnValue: any;
if (args.type === StorageProcessType.default || args.type === StorageProcessType.remote) {
if (args.type === 'default' || args.type === 'remote') {
win.webContents.send('eo-storage', args);
returnValue = null;
} else if (args.type === StorageProcessType.sync) {
} else if (args.type === 'sync') {
deleteFile(storageTemp);
win.webContents.send('eo-storage', args);
let data = readJson(storageTemp);
let count: number = 0;
while (data === null) {
if (count > 1500) {
data = {
status: StorageHandleStatus.error,
// status: StorageResStatus.error,
status: 500,
data: 'storage sync load error',
};
break;
Expand Down Expand Up @@ -210,27 +215,25 @@ try {
returnValue = configuration.getModuleSettings(arg.data.moduleID);
} else if (arg.action === 'getSidePosition') {
returnValue = subView.appView?.sidePosition;
// 注册单个mock路由
} else if (arg.action === 'registerMockRoute') {
const { method, path, data } = arg.data;
returnValue = mockServer.registerRoute(method, path, data);
// 注销mock路由
} else if (arg.action === 'unRegisterMockRoute') {
const { method, path } = arg.data;
returnValue = mockServer.unRegisterRoute(method, path);
// 获取mock服务地址
} else if (arg.action === 'getMockUrl') {
returnValue = mockServer.getMockUrl();
// returnValue = mockServer.getMockUrl();
// 重置并初始化mock路由
} else if (arg.action === 'resetAndInitRoutes') {
returnValue = mockServer.resetAndInitRoutes();
} else if (arg.action === 'hook') {
returnValue = 'hook返回';
} else {
returnValue = 'Invalid data';
}
event.returnValue = returnValue;
});
ipcMain.on('get-system-info', (event) => {
const systemInfo = {
homeDir: path.dirname(app.getPath('exe')),
...process.versions,
os: `${os.type()} ${os.arch()} ${os.release()}`,
};
event.returnValue = systemInfo;
});
} catch (e) {
// Catch Error
// throw e;
Expand Down
1 change: 0 additions & 1 deletion src/platform/browser/IndexedDB/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/platform/node/configuration/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class Configuration implements ConfigurationInterface {
* @param section
* @returns
*/
getModuleSettings(section?: string): ConfigurationValueInterface {
getModuleSettings<T = any>(section?: string): T {
const localSettings = this.getSettings();
localSettings.nestedSettings ??= {};
if (section) {
return section.split('.').reduce((p, k) => p[k], localSettings.nestedSettings);
return section.split('.')?.reduce((p, k) => p?.[k], localSettings.nestedSettings);
}
return localSettings.nestedSettings;
}
Expand Down
53 changes: 0 additions & 53 deletions src/platform/node/mock-server/index copy.ts

This file was deleted.

Loading

0 comments on commit 7ef31d9

Please sign in to comment.