1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// @flow
import log from 'electron-log';
import { shell, ipcRenderer } from 'electron';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { push } from 'react-router-redux';
import Support from '../components/Support';
import { resolveBin } from '../lib/proc';
import { execFile } from 'child_process';
import uuid from 'uuid';
import type { ReduxState, ReduxDispatch } from '../redux/store';
import type { SharedRouteProps } from '../routes';
const mapStateToProps = (state: ReduxState) => state;
const unAnsweredIpcCalls = new Map();
function reapIpcCall(id) {
const promise = unAnsweredIpcCalls.get(id);
unAnsweredIpcCalls.delete(id);
if (promise) {
promise.reject(new Error('Timed out'));
}
}
ipcRenderer.on('collect-logs-reply', (_event, id, err, reportId) => {
const promise = unAnsweredIpcCalls.get(id);
unAnsweredIpcCalls.delete(id);
if(promise) {
if(err) {
promise.reject(err);
} else {
promise.resolve(reportId);
}
}
});
const mapDispatchToProps = (dispatch: ReduxDispatch, _props: SharedRouteProps) => {
const { push: pushHistory } = bindActionCreators({ push }, dispatch);
return {
onClose: () => pushHistory('/settings'),
onCollectLog: (toRedact) => {
return new Promise((resolve, reject) => {
const id = uuid.v4();
unAnsweredIpcCalls.set(id, { resolve, reject });
ipcRenderer.send('collect-logs', id, toRedact);
setTimeout(() => reapIpcCall(id), 1000);
})
.catch((e) => {
const { err, stdout } = e;
log.error('Failed collecting problem report', err);
log.error(' stdout: ' + stdout);
throw e;
});
},
onViewLog: (path) => shell.openItem(path),
onSend: (email, message, savedReport) => {
const args = ['send',
'--email', email,
'--message', message,
'--report', savedReport,
];
const binPath = resolveBin('problem-report');
return new Promise((resolve, reject) => {
execFile(binPath, args, { windowsHide: true }, (err, stdout, stderr) => {
if (err) {
reject({ err, stdout, stderr });
} else {
log.debug('Report sent');
resolve();
}
});
})
.catch((e) => {
const { err, stdout } = e;
log.error('Failed sending problem report', err);
log.error(' stdout: ' + stdout);
throw e;
});
}
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Support);
|