Skip to content

Commit ae60cb5

Browse files
committed
Refactor rendering process.
1 parent f35f231 commit ae60cb5

File tree

8 files changed

+57
-42
lines changed

8 files changed

+57
-42
lines changed

src/core/Process.js

+21-25
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,29 @@ export default class Process extends EventEmitter {
1111
start(args) {
1212
logger.log('Starting process:', this.command, (args || []).join(' '));
1313

14-
// Spawn process
15-
const { process, stop, push } = api.spawnProcess(this.command, args);
16-
17-
// Connect handlers
18-
process.stdout.on('data', data => {
19-
this.emit('stdout', data);
20-
});
21-
22-
process.stderr.on('data', data => {
23-
this.emit('stderr', data);
24-
});
25-
26-
process.on('close', (code, signal) => {
27-
logger.log('Process ended with code', code, 'and signal', signal);
14+
const handlers = {
15+
onStdOut: data => {
16+
this.emit('data', data);
17+
},
18+
onStdErr: data => {
19+
this.emit('data', data);
20+
},
21+
onClose: (code, signal) => {
22+
logger.log('Process ended with code', code, 'and signal', signal);
23+
24+
this.emit('close', code, signal);
25+
},
26+
onExit: (code, signal) => {
27+
this.emit('exit', code, signal);
28+
},
29+
onError: err => {
30+
this.emit('error', err);
31+
},
32+
};
2833

29-
this.emit('close', code, signal);
30-
});
31-
32-
process.on('exit', (code, signal) => {
33-
this.emit('exit', code, signal);
34-
});
35-
36-
process.on('error', err => {
37-
this.emit('error', err);
38-
});
34+
// Spawn process
35+
const { stop, push } = api.spawnProcess(this.command, args, handlers);
3936

40-
this.process = process;
4137
this.stop = stop;
4238
this.push = push;
4339

src/main/api/process.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
import { Transform } from 'stream';
22
import { spawn } from 'child_process';
33

4-
export function spawnProcess(command, args) {
4+
export function spawnProcess(command, args, props = {}) {
55
const stream = new Transform();
66
const process = spawn(command, args);
7+
const { onStdOut, onStdErr, onClose, onExit, onError } = props;
8+
9+
if (onStdOut) {
10+
process.stdout.on('data', data => onStdOut(data.toString()));
11+
}
12+
if (onStdErr) {
13+
process.stderr.on('data', data => onStdErr(data.toString()));
14+
}
15+
if (onClose) {
16+
process.on('close', onClose);
17+
}
18+
if (onExit) {
19+
process.on('exit', onExit);
20+
}
21+
if (onError) {
22+
process.on('error', onError);
23+
}
724

825
stream.pipe(process.stdin);
926

1027
const stop = signal => process.kill(signal);
1128
const push = data => stream.push(data);
1229

13-
return { process, stop, push };
30+
return { stop, push };
1431
}

src/main/environment.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const APP_PATH = app.getAppPath();
1111
export const OS_PLATFORM = os.platform();
1212
export const IS_WINDOWS = OS_PLATFORM === 'win32';
1313
export const IS_MACOS = OS_PLATFORM === 'darwin';
14-
export const USER_AGENT = `${APP_NAME}/${APP_VERSION}`;
1514
export const USER_DATA_PATH = app.getPath('userData');
1615
export const TEMP_PATH = path.join(app.getPath('temp'), APP_NAME);
1716
export const FFMPEG_PATH = path.join(APP_PATH, '..', 'bin', IS_WINDOWS ? 'ffmpeg.exe' : 'ffmpeg');
@@ -21,4 +20,12 @@ export const APP_CONFIG_FILE = path.join(
2120
);
2221
export const LICENSE_FILE = path.join(USER_DATA_PATH, 'license.dat');
2322
export const ELECTRON_VERSION = process.versions.electron;
23+
export const CHROME_VERSION = process.versions.chrome;
24+
export const V8_VERSION = process.versions.v8;
25+
export const NODE_VERSION = process.versions.node;
2426
export const MACHINE_ID = machineIdSync();
27+
export const USER_AGENT = [
28+
`${APP_NAME}/${APP_VERSION} (${OS_PLATFORM})`,
29+
`Chrome/${CHROME_VERSION}`,
30+
`Electron/${ELECTRON_VERSION}`,
31+
].join(' ');

src/view/components/modals/VideoSettings.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useEffect } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
3-
import { player } from 'global';
3+
import { api, player } from 'global';
44
import { Settings, Setting } from 'components/editing';
55
import Layout from 'components/layout/Layout';
66
import Button from 'components/interface/Button';
@@ -39,11 +39,9 @@ export default function VideoSettings({ onClose }) {
3939
}));
4040
}, []);
4141

42-
function handleChange(name, value) {
43-
const props = { [name]: value };
44-
45-
if (name === 'format' && videoFile) {
46-
props.videoFile = replaceExt(videoFile, `.${value}`);
42+
function handleChange(props) {
43+
if (props.format && videoFile) {
44+
props.videoFile = replaceExt(videoFile, `.${props.format}`);
4745
}
4846

4947
setState(state => ({ ...state, ...props }));

src/view/components/window/Dialog.less

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
.body {
88
display: flex;
99
flex-direction: row;
10-
padding: 20px;
10+
padding: 40px;
1111
}
1212

1313
.icon {
@@ -18,7 +18,3 @@
1818
.message {
1919
flex: 1;
2020
}
21-
22-
.buttons {
23-
24-
}
File renamed without changes.

src/view/assets/index.html renamed to src/view/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<meta charset="utf-8" />
55
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-eval'; img-src * data:">
66
<title>Astrofox</title>
7-
<link rel="preload" href="fonts/roboto.woff2" as="font" type="font/woff2" crossorigin>
7+
<link rel="preload" href="fonts/roboto.woff2" as="font" type="font/woff2" crossorigin />
8+
<link rel="preload" href="images/about_bg.jpg" as="image" />
89
<link rel="stylesheet" href="fonts.css" />
910
<link rel="stylesheet" href="app.css" />
1011
</head>

src/view/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Provider } from 'react-redux';
44
import App from 'components/App';
55
import * as globals from './global';
66
import getStore from './store';
7-
import 'assets/index.html';
8-
import 'assets/fonts.css';
97
import 'styles/index.less';
8+
import './fonts.css';
9+
import './index.html';
1010

1111
const store = getStore();
1212

0 commit comments

Comments
 (0)