Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit b4568dd

Browse files
authored
Merge pull request #6410 from bsclifton/fix-about-brave
Get each version in a more safe way; if one field fails, it won't break the whole thing
2 parents b590743 + e0b2e6d commit b4568dd

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

app/sessionStore.js

+38-20
Original file line numberDiff line numberDiff line change
@@ -342,30 +342,48 @@ module.exports.cleanSessionDataOnShutdown = () => {
342342
return p
343343
}
344344

345+
const safeGetVersion = (fieldName, getFieldVersion) => {
346+
const versionField = {
347+
name: fieldName,
348+
version: undefined
349+
}
350+
try {
351+
if (typeof getFieldVersion === 'function') {
352+
versionField.version = getFieldVersion()
353+
return versionField
354+
}
355+
console.log('ERROR getting value for field ' + fieldName + ' in sessionStore::setVersionInformation(): ', getFieldVersion, ' is not a function')
356+
} catch (e) {
357+
console.log('ERROR getting value for field ' + fieldName + ' in sessionStore::setVersionInformation(): ', e)
358+
}
359+
return versionField
360+
}
361+
345362
/**
346363
* version information (shown on about:brave)
347364
*/
348365
const setVersionInformation = (data) => {
349-
try {
350-
const os = require('os')
351-
const versionInformation = [
352-
{name: 'Brave', version: app.getVersion()},
353-
{name: 'rev', version: Channel.browserLaptopRev()},
354-
{name: 'Muon', version: process.versions['atom-shell']},
355-
{name: 'libchromiumcontent', version: process.versions['chrome']},
356-
{name: 'V8', version: process.versions.v8},
357-
{name: 'Node.js', version: process.versions.node},
358-
{name: 'Update Channel', version: Channel.channel()},
359-
{name: 'os.platform', version: os.platform()},
360-
{name: 'os.release', version: os.release()},
361-
{name: 'os.arch', version: os.arch()}
362-
]
363-
data.about = data.about || {}
364-
data.about.brave = {
365-
versionInformation: versionInformation
366-
}
367-
} catch (e) {
368-
console.log('ERROR calling sessionStore::setVersionInformation(): ', e)
366+
const versionFields = [
367+
['Brave', app.getVersion],
368+
['rev', Channel.browserLaptopRev],
369+
['Muon', () => { return process.versions['atom-shell'] }],
370+
['libchromiumcontent', () => { return process.versions['chrome'] }],
371+
['V8', () => { return process.versions.v8 }],
372+
['Node.js', () => { return process.versions.node }],
373+
['Update Channel', Channel.channel],
374+
['os.platform', require('os').platform],
375+
['os.release', require('os').release],
376+
['os.arch', require('os').arch]
377+
]
378+
const versionInformation = []
379+
380+
versionFields.forEach((field) => {
381+
versionInformation.push(safeGetVersion(field[0], field[1]))
382+
})
383+
384+
data.about = data.about || {}
385+
data.about.brave = {
386+
versionInformation: versionInformation
369387
}
370388
return data
371389
}

0 commit comments

Comments
 (0)