-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add developer option to send logs via email (WEBAPP-6493) (back…
…port) (#3155)
- Loading branch information
Showing
5 changed files
with
92 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2019 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {app} from 'electron'; | ||
import * as fs from 'fs-extra'; | ||
import * as globby from 'globby'; | ||
import * as path from 'path'; | ||
|
||
const logDir = path.join(app.getPath('userData'), 'logs'); | ||
|
||
export function getLogFiles(base: string = logDir, absolute: boolean = false): Promise<string[]> { | ||
return globby('**/*.{log,old}', {cwd: base, followSymbolicLinks: false, onlyFiles: true, absolute}); | ||
} | ||
|
||
export async function gatherLogs(): Promise<string> { | ||
let log = ''; | ||
|
||
const relativeFilePaths = await getLogFiles(); | ||
|
||
for (const relativeFilePath of relativeFilePaths) { | ||
const resolvedPath = path.join(logDir, relativeFilePath); | ||
log += `\n\n+++++++ ${relativeFilePath} +++++++\n`; | ||
try { | ||
const fileContent = await fs.readFile(resolvedPath, 'utf-8'); | ||
log += fileContent || '(no content)\n'; | ||
} catch (error) { | ||
log += '(fle not readable)\n'; | ||
} | ||
log += '++++++++++++++++++++++++++++\n'; | ||
} | ||
|
||
return log || 'No log files found.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,9 @@ | |
* | ||
*/ | ||
|
||
import {MenuItem, app} from 'electron'; | ||
import {MenuItem, app, shell} from 'electron'; | ||
|
||
import {gatherLogs} from '../logging/loggerUtils'; | ||
import * as EnvironmentUtil from '../runtime/EnvironmentUtil'; | ||
import {config} from '../settings/config'; | ||
import {settings} from '../settings/ConfigurationPersistence'; | ||
|
@@ -33,6 +34,17 @@ const reloadTemplate: Electron.MenuItemConstructorOptions = { | |
label: 'Reload', | ||
}; | ||
|
||
const sendLogTemplate: Electron.MenuItemConstructorOptions = { | ||
click: async () => { | ||
const logText = await gatherLogs(); | ||
const subject = encodeURIComponent('Wire Desktop Log'); | ||
const body = encodeURIComponent(logText); | ||
const mailToLink = `mailto:[email protected]?subject=${subject}&body=${body}`; | ||
await shell.openExternal(mailToLink); | ||
}, | ||
label: 'Send Debug Logs', | ||
}; | ||
|
||
const devToolsTemplate: Electron.MenuItemConstructorOptions = { | ||
label: 'Toggle DevTools', | ||
submenu: [ | ||
|
@@ -109,6 +121,7 @@ const menuTemplate: Electron.MenuItemConstructorOptions = { | |
submenu: [ | ||
devToolsTemplate, | ||
reloadTemplate, | ||
sendLogTemplate, | ||
separatorTemplate, | ||
...createEnvironmentTemplates(), | ||
separatorTemplate, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters