Skip to content

Commit

Permalink
Merge pull request #1 from scarqin/main
Browse files Browse the repository at this point in the history
chore: auto updater
  • Loading branch information
scarqin authored Feb 17, 2022
2 parents ba6a63e + 9b5f0bd commit 403357a
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/out-tsc
/app-builds
/release
app/main.js
app/*.js
src/**/*.js
!src/karma.conf.js
!src/ng1/**/*.js
Expand Down
2 changes: 1 addition & 1 deletion README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# 功能

- API 测试:安装后即可对快速 API 发起测试。
- API 管理:可通过界面管理 API 文档,零学习成本。
- API 管理:可通过界面编辑 API 文档,零学习成本。
- 测试环境管理
- 可离线使用

Expand Down
47 changes: 14 additions & 33 deletions app/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { app, BrowserWindow, screen, ipcMain } from 'electron';
import { EoUpdater } from './updater';
import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import * as url from 'url';
import * as child_process from 'child_process';
import { UnitWorker } from './unitWorker';

let win: BrowserWindow = null;
const args = process.argv.slice(1),
serve = args.some((val) => val === '--serve'),
workerLoop = {};
eoUpdater = new EoUpdater(),
workerLoop = {},
serve = args.some((val) => val === '--serve');
function createWindow(): BrowserWindow {
const electronScreen = screen;
const size = electronScreen.getPrimaryDisplay().workAreaSize;
Expand Down Expand Up @@ -40,15 +43,15 @@ function createWindow(): BrowserWindow {
pathIndex = htmlPath;
}
});
let loadPage=()=>{
let loadPage = () => {
win.loadURL(
url.format({
pathname: path.join(__dirname, pathIndex),
protocol: 'file:',
slashes: true,
})
);
}
};
win.webContents.on('did-fail-load', () => {
loadPage();
});
Expand All @@ -65,38 +68,16 @@ function createWindow(): BrowserWindow {

return win;
}
class UnitWorker {
instance: child_process.ChildProcess;
constructor() {}
start(message) {
this.instance = child_process.fork(`${__dirname}/request/main.js`);
this.watch();
this.instance.send(message);
}
finish(message) {
win.webContents.send('unitTest', message);
this.kill();
}
kill() {
this.instance.kill();
}
private watch() {
this.instance.on('message', (message: any) => {
switch (message.action) {
case 'finish': {
this.finish(message.data);
break;
}
}
});
}
}

try {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
// Added 400 ms to fix the black background issue while using transparent window. More detais at https://github.com/electron/electron/issues/15947
app.on('ready', () => setTimeout(createWindow, 400));
app.on('ready', () => {
setTimeout(createWindow, 400);
eoUpdater.check();
});

// Quit when all windows are closed.
app.on('window-all-closed', () => {
Expand Down Expand Up @@ -139,7 +120,7 @@ try {
let id = message.id;
switch (message.action) {
case 'ajax': {
workerLoop[id] = new UnitWorker();
workerLoop[id] = new UnitWorker(win);
workerLoop[id].start(message);
break;
}
Expand Down
Loading

0 comments on commit 403357a

Please sign in to comment.