summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoranderklander <anderklander@gmail.com>2018-01-19 09:34:18 +0100
committeranderklander <anderklander@gmail.com>2018-01-20 10:03:04 +0100
commita11ed1b5c6490bfd5a8d855ab278dba6c9832f38 (patch)
tree99bfcddb74c1f9d3e13af6e4db5e95876f580928
parent8b66a953f244dbe04148f550dc7a8c8b4f50d2a0 (diff)
downloadmullvadvpn-a11ed1b5c6490bfd5a8d855ab278dba6c9832f38.tar.xz
mullvadvpn-a11ed1b5c6490bfd5a8d855ab278dba6c9832f38.zip
Move problem report handling from supportPage
To be able to handle problem reports on mobile. Also moves ipc for collect-logs from tray to onReady.
-rw-r--r--app/containers/SupportPage.js71
-rw-r--r--app/lib/problem-report.android.js12
-rw-r--r--app/lib/problem-report.js71
-rw-r--r--app/main.js76
4 files changed, 125 insertions, 105 deletions
diff --git a/app/containers/SupportPage.js b/app/containers/SupportPage.js
index 1681ffd943..aaa9f786cd 100644
--- a/app/containers/SupportPage.js
+++ b/app/containers/SupportPage.js
@@ -1,41 +1,16 @@
// @flow
-
-import { log, openItem } from '../lib/platform';
-import { 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 { openItem } from '../lib/platform';
+import { collectProblemReport, sendProblemReport } from '../lib/problem-report';
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);
@@ -43,51 +18,13 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, _props: SharedRouteProps) =
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;
- });
+ return collectProblemReport(toRedact);
},
onViewLog: (path) => 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;
- });
+ return sendProblemReport(email, message, savedReport);
}
};
};
diff --git a/app/lib/problem-report.android.js b/app/lib/problem-report.android.js
new file mode 100644
index 0000000000..63deb102e4
--- /dev/null
+++ b/app/lib/problem-report.android.js
@@ -0,0 +1,12 @@
+// @flow
+import { MobileAppBridge } from 'NativeModules';
+
+const collectProblemReport = (toRedact: string) => {
+ return MobileAppBridge.collectProblemReport(toRedact);
+};
+
+const sendProblemReport = (email: string, message: string, savedReport: string) => {
+ return MobileAppBridge.sendProblemReport(email, message, savedReport);
+};
+
+export { collectProblemReport, sendProblemReport }; \ No newline at end of file
diff --git a/app/lib/problem-report.js b/app/lib/problem-report.js
new file mode 100644
index 0000000000..17130fd05d
--- /dev/null
+++ b/app/lib/problem-report.js
@@ -0,0 +1,71 @@
+// @flow
+import { resolveBin } from './proc';
+import { execFile } from 'child_process';
+import { ipcRenderer } from 'electron';
+import { log } from './platform';
+import uuid from 'uuid';
+
+const collectProblemReport = (toRedact: string) => {
+ 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);
+ }
+ }
+ });
+ 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;
+ });
+};
+
+const sendProblemReport = (email: string, message: string, savedReport: string) => {
+ 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 { collectProblemReport, sendProblemReport }; \ No newline at end of file
diff --git a/app/main.js b/app/main.js
index f754f71634..8cda655f47 100644
--- a/app/main.js
+++ b/app/main.js
@@ -104,6 +104,44 @@ const appDelegate = {
window.webContents.send('shutdown');
});
+ ipcMain.on('collect-logs', (event, id, toRedact) => {
+ log.info('Collecting logs in', appDelegate._logFileLocation);
+ fs.readdir(appDelegate._logFileLocation, (err, files) => {
+ if (err) {
+ event.sender.send('collect-logs-reply', id, err);
+ return;
+ }
+
+ const logFiles = files.filter(file => file.endsWith('.log'))
+ .map(f => path.join(appDelegate._logFileLocation, f));
+ const reportPath = path.join(writableDirectory, uuid.v4() + '.report');
+
+ const binPath = resolveBin('problem-report');
+ let args = [
+ 'collect',
+ '--output', reportPath,
+ ];
+
+ if (toRedact.length > 0) {
+ args = args.concat([
+ '--redact', ...toRedact,
+ '--',
+ ]);
+ }
+
+ args = args.concat(logFiles);
+
+ execFile(binPath, args, {windowsHide: true}, (err) => {
+ if (err) {
+ event.sender.send('collect-logs-reply', id, err);
+ } else {
+ log.debug('Report written to', reportPath);
+ event.sender.send('collect-logs-reply', id, null, reportPath);
+ }
+ });
+ });
+ });
+
// create tray icon on macOS
if(isMacOS) {
appDelegate._tray = appDelegate._createTray(window);
@@ -385,44 +423,6 @@ const appDelegate = {
// add IPC handler to change tray icon from renderer
ipcMain.on('changeTrayIcon', (_: Event, type: TrayIconType) => trayIconManager.iconType = type);
- ipcMain.on('collect-logs', (event, id, toRedact) => {
- log.info('Collecting logs in', appDelegate._logFileLocation);
- fs.readdir(appDelegate._logFileLocation, (err, files) => {
- if (err) {
- event.sender.send('collect-logs-reply', id, err);
- return;
- }
-
- const logFiles = files.filter(file => file.endsWith('.log'))
- .map(f => path.join(appDelegate._logFileLocation, f));
- const reportPath = path.join(writableDirectory, uuid.v4() + '.report');
-
- const binPath = resolveBin('problem-report');
- let args = [
- 'collect',
- '--output', reportPath,
- ];
-
- if (toRedact.length > 0) {
- args = args.concat([
- '--redact', ...toRedact,
- '--',
- ]);
- }
-
- args = args.concat(logFiles);
-
- execFile(binPath, args, {windowsHide: true}, (err) => {
- if (err) {
- event.sender.send('collect-logs-reply', id, err);
- } else {
- log.debug('Report written to', reportPath);
- event.sender.send('collect-logs-reply', id, null, reportPath);
- }
- });
- });
- });
-
// setup event handlers
window.on('show', () => macEventMonitor.start(eventMask, () => window.hide()));
window.on('hide', () => macEventMonitor.stop());