diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-08-07 12:28:27 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-08-22 08:34:37 +0200 |
| commit | c28b823651dbd4acf90f07f312d422ac91b73b97 (patch) | |
| tree | 373f9e8377e8397c79dab0a54c202d452e5e65f4 | |
| parent | a943574c89a52e8fdbb96748dc91bfc67c9b0c37 (diff) | |
| download | mullvadvpn-c28b823651dbd4acf90f07f312d422ac91b73b97.tar.xz mullvadvpn-c28b823651dbd4acf90f07f312d422ac91b73b97.zip | |
Move problem report code to it's own file
| -rw-r--r-- | gui/src/main/index.ts | 64 | ||||
| -rw-r--r-- | gui/src/main/problem-report.ts | 72 |
2 files changed, 77 insertions, 59 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 1849649a26..96c2665714 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -1,5 +1,4 @@ -import { exec, execFile } from 'child_process'; -import { randomUUID } from 'crypto'; +import { exec } from 'child_process'; import { app, dialog, nativeTheme, session, shell, systemPreferences } from 'electron'; import fs from 'fs'; import * as path from 'path'; @@ -62,7 +61,7 @@ import { OLD_LOG_FILES, } from './logging'; import NotificationController, { NotificationControllerDelegate } from './notification-controller'; -import { resolveBin } from './proc'; +import * as problemReport from './problem-report'; import ReconnectionBackoff from './reconnection-backoff'; import UserInterface, { UserInterfaceDelegate } from './user-interface'; import Version, { VersionDelegate } from './version'; @@ -939,6 +938,7 @@ class ApplicationMain return { countries: [] }; } } + private handleDeviceEvent(deviceEvent: DeviceEvent) { this.deviceState = deviceEvent.deviceState; @@ -1141,58 +1141,6 @@ class ApplicationMain }, ); - IpcMainEventChannel.problemReport.handleCollectLogs((toRedact) => { - const id = randomUUID(); - const reportPath = this.getProblemReportPath(id); - const executable = resolveBin('mullvad-problem-report'); - const args = ['collect', '--output', reportPath]; - if (toRedact) { - args.push('--redact', toRedact); - } - - return new Promise((resolve, reject) => { - execFile(executable, args, { windowsHide: true }, (error, stdout, stderr) => { - if (error) { - log.error( - `Failed to collect a problem report. - Stdout: ${stdout.toString()} - Stderr: ${stderr.toString()}`, - ); - reject(error.message); - } else { - log.verbose(`Problem report was written to ${reportPath}`); - resolve(id); - } - }); - }); - }); - - IpcMainEventChannel.problemReport.handleSendReport(({ email, message, savedReportId }) => { - const executable = resolveBin('mullvad-problem-report'); - const reportPath = this.getProblemReportPath(savedReportId); - const args = ['send', '--email', email, '--message', message, '--report', reportPath]; - - return new Promise((resolve, reject) => { - execFile(executable, args, { windowsHide: true }, (error, stdout, stderr) => { - if (error) { - log.error( - `Failed to send a problem report. - Stdout: ${stdout.toString()} - Stderr: ${stderr.toString()}`, - ); - reject(error.message); - } else { - log.info('Problem report was sent.'); - resolve(); - } - }); - }); - }); - - IpcMainEventChannel.problemReport.handleViewLog((savedReportId) => - shell.openPath(this.getProblemReportPath(savedReportId)), - ); - IpcMainEventChannel.app.handleQuit(() => app.quit()); IpcMainEventChannel.app.handleOpenUrl(async (url) => { if (Object.values(config.links).find((link) => url.startsWith(link))) { @@ -1220,6 +1168,8 @@ class ApplicationMain this.scrollPositions = scrollPositions; }); + problemReport.registerIpcListeners(); + if (windowsSplitTunneling) { this.guiSettings.browsedForSplitTunnelingApplications.forEach( windowsSplitTunneling.addApplicationPathToCache, @@ -1448,10 +1398,6 @@ class ApplicationMain return this.guiSettings.unpinnedWindow && !this.guiSettings.startMinimized; } - private getProblemReportPath(id: string): string { - return path.join(app.getPath('temp'), `${id}.log`); - } - private async updateMacOsScrollbarVisibility(): Promise<void> { const command = 'defaults read kCFPreferencesAnyApplication AppleShowScrollBars || echo Automatic'; diff --git a/gui/src/main/problem-report.ts b/gui/src/main/problem-report.ts new file mode 100644 index 0000000000..be84814d72 --- /dev/null +++ b/gui/src/main/problem-report.ts @@ -0,0 +1,72 @@ +import { execFile } from 'child_process'; +import { randomUUID } from 'crypto'; +import { app, shell } from 'electron'; +import * as path from 'path'; + +import log from '../shared/logging'; +import { IpcMainEventChannel } from './ipc-event-channel'; +import { resolveBin } from './proc'; + +export function registerIpcListeners() { + IpcMainEventChannel.problemReport.handleCollectLogs(collectLogs); + + IpcMainEventChannel.problemReport.handleSendReport(({ email, message, savedReportId }) => { + return send(email, message, savedReportId); + }); + + IpcMainEventChannel.problemReport.handleViewLog((savedReportId) => + shell.openPath(getProblemReportPath(savedReportId)), + ); +} + +function collectLogs(toRedact?: string): Promise<string> { + const id = randomUUID(); + const reportPath = getProblemReportPath(id); + const executable = resolveBin('mullvad-problem-report'); + const args = ['collect', '--output', reportPath]; + if (toRedact) { + args.push('--redact', toRedact); + } + + return new Promise((resolve, reject) => { + execFile(executable, args, { windowsHide: true }, (error, stdout, stderr) => { + if (error) { + log.error( + `Failed to collect a problem report. + Stdout: ${stdout.toString()} + Stderr: ${stderr.toString()}`, + ); + reject(error.message); + } else { + log.verbose(`Problem report was written to ${reportPath}`); + resolve(id); + } + }); + }); +} + +function send(email: string, message: string, savedReportId: string): Promise<void> { + const executable = resolveBin('mullvad-problem-report'); + const reportPath = getProblemReportPath(savedReportId); + const args = ['send', '--email', email, '--message', message, '--report', reportPath]; + + return new Promise((resolve, reject) => { + execFile(executable, args, { windowsHide: true }, (error, stdout, stderr) => { + if (error) { + log.error( + `Failed to send a problem report. + Stdout: ${stdout.toString()} + Stderr: ${stderr.toString()}`, + ); + reject(error.message); + } else { + log.info('Problem report was sent.'); + resolve(); + } + }); + }); +} + +function getProblemReportPath(id: string): string { + return path.join(app.getPath('temp'), `${id}.log`); +} |
