Skip to content

Commit 076185b

Browse files
Merge pull request #272 from entrylabs/revert-271-feature/react_renderer
Revert "[feature] renderer process react"
2 parents 3a05ce8 + bbfde8e commit 076185b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+7025
-5780
lines changed

.babelrc

-3
This file was deleted.

.eslintrc

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"rules": {
1414
"prefer-const": "warn",
1515
"no-var": "warn",
16-
"quotes": ["warn", "single"],
1716
"eqeqeq": 0,
1817
"no-const-assign": "error",
1918
"no-new-object": "warn",

app/index.js

-50
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function createAboutWindow(mainWindow) {
7171
show: false,
7272
webPreferences: {
7373
nodeIntegration: true,
74-
preload: path.resolve(__dirname, 'src', 'renderer', 'preload.js'),
7574
},
7675
});
7776

@@ -193,7 +192,6 @@ if (!app.requestSingleInstanceLock()) {
193192
mainWindow = new BrowserWindow({
194193
width: 800,
195194
height: 670,
196-
minWidth: 420,
197195
title: title + packageJson.version,
198196
webPreferences: {
199197
backgroundThrottling: false,
@@ -271,47 +269,6 @@ if (!app.requestSingleInstanceLock()) {
271269
});
272270
});
273271

274-
ipcMain.handle('checkUpdate', () => new Promise((resolve, reject) => {
275-
const request = net.request({
276-
method: 'POST',
277-
host: hostURI,
278-
protocol: hostProtocol,
279-
path: '/api/checkVersion',
280-
});
281-
let body = '';
282-
request.on('response', (res) => {
283-
res.on('data', (chunk) => {
284-
body += chunk.toString();
285-
});
286-
res.on('end', () => {
287-
let data = {};
288-
try {
289-
data = JSON.parse(body);
290-
} catch (e) {
291-
}
292-
293-
/**
294-
* _id: string;
295-
* version: string (semver)
296-
* padded_version: 4 digit padded string
297-
* hasNewVersion: boolean
298-
* currentVersion: string
299-
*/
300-
data.currentVersion = packageJson.version;
301-
resolve(data);
302-
});
303-
});
304-
request.on('error', reject);
305-
request.setHeader('content-type', 'application/json; charset=utf-8');
306-
request.write(
307-
JSON.stringify({
308-
category: 'hardware',
309-
version: packageJson.version,
310-
}),
311-
);
312-
request.end();
313-
}));
314-
315272
ipcMain.on('checkUpdate', (e, msg) => {
316273
const request = net.request({
317274
method: 'POST',
@@ -352,13 +309,6 @@ if (!app.requestSingleInstanceLock()) {
352309
});
353310
});
354311

355-
ipcMain.handle('checkVersion', (e, lastCheckVersion) => {
356-
const version = getPaddedVersion(packageJson.version);
357-
const lastVersion = getPaddedVersion(lastCheckVersion);
358-
359-
return lastVersion > version;
360-
});
361-
362312
ipcMain.on('checkVersion', (e, lastCheckVersion) => {
363313
const version = getPaddedVersion(packageJson.version);
364314
const lastVersion = getPaddedVersion(lastCheckVersion);

app/src/main/hardwareListManager.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ const { app } = require('electron');
33
const path = require('path');
44

55
module.exports = class {
6-
constructor(router) {
6+
constructor() {
77
this.moduleBasePath = path.resolve(app.getAppPath(), __dirname, '..', '..', 'modules');
88
this.allHardwareList = [];
9-
this.router = router;
109
this.initialize();
11-
this.notifyHardwareListChanged();
1210
}
1311

1412
/**
1513
* 파일을 읽어와 리스트에 작성한다.
14+
*
1615
*/
1716
initialize() {
1817
// noinspection JSCheckFunctionSignatures
@@ -40,9 +39,4 @@ module.exports = class {
4039
console.error('error occurred while reading module json files');
4140
}
4241
}
43-
44-
notifyHardwareListChanged() {
45-
this.router &&
46-
this.router.sendEventToMainWindow('hardwareListChanged');
47-
}
4842
};

app/src/main/mainRouter.js

+49-66
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ class MainRouter {
2424

2525
constructor(mainWindow, entryServer) {
2626
global.$ = require('lodash');
27-
rendererConsole.initialize(mainWindow);
2827
this.browser = mainWindow;
28+
rendererConsole.initialize(mainWindow);
2929
this.scanner = new Scanner(this);
3030
this.server = entryServer;
3131
this.flasher = new Flasher();
32-
this.hardwareListManager = new HardwareListManager(this);
32+
this.hardwareListManager = new HardwareListManager();
3333

34-
this.selectedPort = undefined;
3534
this.config = undefined;
3635
/** @type {Connector} */
3736
this.connector = undefined;
@@ -49,12 +48,10 @@ class MainRouter {
4948
try {
5049
await this.startScan(config);
5150
} catch (e) {
52-
rendererConsole.error('startScan err : ', e);
51+
console.error(e);
52+
rendererConsole.error(`startScan err : `, e);
5353
}
5454
});
55-
ipcMain.on('selectPort', (e, portName) => {
56-
this.selectedPort = portName;
57-
});
5855
ipcMain.on('stopScan', () => {
5956
this.close();
6057
});
@@ -63,23 +60,15 @@ class MainRouter {
6360
});
6461
ipcMain.on('requestFlash', (e, firmwareName) => {
6562
this.flashFirmware(firmwareName)
66-
.then((firmware) => {
63+
.then(() => {
6764
if (!e.sender.isDestroyed()) {
6865
e.sender.send('requestFlash');
6966
}
70-
return firmware;
7167
})
7268
.catch((err) => {
7369
if (!e.sender.isDestroyed()) {
7470
e.sender.send('requestFlash', err);
7571
}
76-
})
77-
.then(async (firmware) => {
78-
this.flasher.kill();
79-
if (firmware && firmware.afterDelay) {
80-
await new Promise((resolve) => setTimeout(resolve, firmware.afterDelay));
81-
}
82-
await this.startScan(this.config);
8372
});
8473
});
8574
ipcMain.on('executeDriver', (e, driverPath) => {
@@ -106,10 +95,9 @@ class MainRouter {
10695
*/
10796
flashFirmware(firmwareName) {
10897
if (this.connector && this.connector.serialPort && this.config) {
109-
this.sendState('flash');
11098
let firmware = firmwareName;
11199
const {
112-
firmware: firmwareInConfig,
100+
configfirmware,
113101
firmwareBaudRate: baudRate,
114102
firmwareMCUType: MCUType,
115103
tryFlasherNumber: maxFlashTryCount = 10,
@@ -118,12 +106,10 @@ class MainRouter {
118106
this.firmwareTryCount = 0;
119107

120108
if (firmwareName === undefined || firmwareName === '') {
121-
console.warn('firmware requested without firmware info!');
122-
console.warn('try to default firmware info in config file');
123-
firmware = firmwareInConfig;
109+
firmware = configfirmware;
124110
}
125111

126-
this.close({ saveSelectedPort: true }); // 서버 통신 중지, 시리얼포트 연결 해제
112+
this.close(); // 서버 통신 중지, 시리얼포트 연결 해제
127113

128114
const flashFunction = () => new Promise((resolve, reject) => {
129115
setTimeout(() => {
@@ -143,15 +129,30 @@ class MainRouter {
143129
reject(new Error('Failed Firmware Upload'));
144130
}
145131
} else {
146-
resolve(firmware);
132+
resolve();
147133
}
148134
})
149135
.catch(reject);
150136
}, 500);
151137
});
152138

153139
// 에러가 발생하거나, 정상종료가 되어도 일단 startScan 을 재시작한다.
154-
return flashFunction();
140+
return flashFunction()
141+
.then(() => {
142+
console.log('flash successed');
143+
})
144+
.catch((e) => {
145+
rendererConsole.error('flash failed', e);
146+
console.log('flash failed');
147+
throw e;
148+
})
149+
.finally(async () => {
150+
this.flasher.kill();
151+
if (firmware.afterDelay) {
152+
await new Promise((resolve) => setTimeout(resolve, firmware.afterDelay));
153+
}
154+
await this.startScan(this.config);
155+
});
155156
} else {
156157
return Promise.reject(new Error('Hardware Device Is Not Connected'));
157158
}
@@ -184,23 +185,23 @@ class MainRouter {
184185
}
185186
}
186187

187-
this.sendEventToMainWindow('state', resultState, ...args);
188+
if (!this.browser.isDestroyed()) {
189+
this.browser.webContents.send('state', resultState, ...args);
190+
}
188191
}
189192

190193
notifyCloudModeChanged(mode) {
191-
this.sendEventToMainWindow('cloudMode', mode);
194+
if (!this.browser.isDestroyed()) {
195+
this.browser.webContents.send('cloudMode', mode);
196+
}
192197
this.currentCloudMode = mode;
193198
}
194199

195200
notifyServerRunningModeChanged(mode) {
196-
this.sendEventToMainWindow('serverMode', mode);
197-
this.currentServerRunningMode = mode;
198-
}
199-
200-
sendEventToMainWindow(eventName, ...args) {
201201
if (!this.browser.isDestroyed()) {
202-
this.browser.webContents.send(eventName, ...args);
202+
this.browser.webContents.send('serverMode', mode);
203203
}
204+
this.currentServerRunningMode = mode;
204205
}
205206

206207
/**
@@ -222,29 +223,21 @@ class MainRouter {
222223
this.config = config;
223224
if (this.scanner) {
224225
this.hwModule = require(`../../modules/${config.module}`);
225-
this.sendState('scan');
226-
this.scanner.stopScan();
227-
const connector = await this.scanner.startScan(this.hwModule, this.config);
228-
if (connector) {
229-
this.sendState('connected');
230-
this.connector = connector;
231-
connector.setRouter(this);
232-
this._connect(connector);
233-
/*if (this.scanner.isScanning) {
234-
this.scanner.config = config;
235-
return;
226+
if (this.scanner.isScanning) {
227+
this.scanner.config = config;
228+
return;
229+
}
230+
231+
if (this.scanner.isScanning) {
232+
this.scanner.setConfig(config);
233+
} else {
234+
const connector = await this.scanner.startScan(this.hwModule, this.config);
235+
if (connector) {
236+
this.sendState('connected');
237+
this.connector = connector;
238+
connector.setRouter(this);
239+
this._connect(connector);
236240
}
237-
238-
if (this.scanner.isScanning) {
239-
this.scanner.setConfig(config);
240-
} else {
241-
const connector = await this.scanner.startScan(this.hwModule, this.config);
242-
if (connector) {
243-
this.sendState('connected');
244-
this.connector = connector;
245-
connector.setRouter(this);
246-
this._connect(connector);
247-
}*/
248241
}
249242
}
250243
}
@@ -366,34 +359,24 @@ class MainRouter {
366359
}
367360
}
368361

369-
/**
370-
*
371-
* @param option {Object=} true 인 경우, 포트선택했던 내역을 지우지 않는다.
372-
*/
373-
close(option) {
374-
const { saveSelectedPort = false } = option || {};
375-
362+
close() {
376363
if (this.server) {
377364
this.server.disconnectHardware();
378365
}
379366
if (this.connector) {
367+
rendererConsole.log('disconnect');
380368
if (this.hwModule.disconnect) {
381369
this.hwModule.disconnect(this.connector);
382370
} else {
383371
this.connector.close();
384372
}
385-
this.sendState('disconnected');
386373
}
387374
if (this.scanner) {
388375
this.scanner.stopScan();
389376
}
390377
if (this.handler) {
391378
this.handler = undefined;
392379
}
393-
394-
if (!saveSelectedPort) {
395-
this.selectedPort = undefined;
396-
}
397380
};
398381

399382
/**

app/src/main/serial/connector.js

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class Connector {
282282

283283
serialPort.on('disconnect', () => {
284284
this.close();
285+
this._sendState('disconnected');
285286
});
286287

287288
// 디바이스 연결 잃어버린 상태에 대한 관리를 모듈에 맡기거나, 직접 관리한다.

app/src/main/serial/electPortFunction.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const { compact } = require('lodash');
66
* @param hwConfig {Object}
77
* @param hwModule {Object}
88
* @param beforeConnectCallback {Function=}
9-
* @return Promise <{port: string, connector: Connector} | void>
109
*/
1110
const electPort = async (ports, hwConfig, hwModule, beforeConnectCallback) => {
1211
// 선출 후보 포트 모두 오픈

app/src/main/serial/scanner.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ class Scanner {
5555
}
5656

5757
const serverMode = this.router.currentCloudMode;
58-
const selectedComPortName = this.router.selectedPort;
59-
const { hardware } = this.config;
58+
const { hardware, this_com_port: selectedComPortName } = this.config;
6059
let { select_com_port: needCOMPortSelect } = this.config;
6160
const {
6261
comName: verifiedComPortNames,
@@ -83,6 +82,8 @@ class Scanner {
8382

8483
// 전체 포트 가져오기
8584
const comPorts = await SerialPort.list();
85+
rendererConsole.log(JSON.stringify(comPorts));
86+
8687
const selectedPorts = [];
8788

8889
// 포트 선택을 유저에게서 직접 받아야 하는가?
@@ -97,8 +98,7 @@ class Scanner {
9798
}
9899
selectedPorts.push(selectedComPortName);
99100
} else {
100-
rendererConsole.log(comPorts);
101-
this.router.sendEventToMainWindow('portListScanned', comPorts);
101+
this.router.sendState('select_port', comPorts);
102102
return;
103103
}
104104
} else {

0 commit comments

Comments
 (0)