Skip to content

Commit

Permalink
Merge pull request #2022 from bugsnag/PLAT-10961/electron-linux-crash
Browse files Browse the repository at this point in the history
Fix Electron Linux crash
  • Loading branch information
lemnik authored Oct 11, 2023
2 parents 86e96f9 + 02e7bad commit 775699d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 130 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-electron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
electron: [ '^12.0.0', '^20.0.0' ]
electron: [ '^12.0.0', '^20.0.0', '^25.0.0', '^26.0.0' ]
node-version: [12, 14]
os: [ ubuntu-20.04, windows-2019 ]
os: [ ubuntu-22.04, windows-2019 ]

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## TBD

### Fixed

- (electron) Fix startup crash when using Electron v26+ on Linux [#2022](https://github.com/bugsnag/bugsnag-js/pull/2022)

## 7.22.0 (2023-09-13)

### Changes
Expand Down
13 changes: 0 additions & 13 deletions packages/electron/src/client/test/client.test-main.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/electron/test/notifier.test-main.ts

This file was deleted.

51 changes: 0 additions & 51 deletions packages/electron/test/notifier.test-renderer.ts

This file was deleted.

80 changes: 41 additions & 39 deletions packages/plugin-electron-device/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,49 @@ module.exports = (app, screen, process, filestore, NativeClient, powerMonitor) =
}
})

client.addMetadata('device', {
// the value for 'idleThreshold' doesn't matter here because it is ignored
// if the system is locked and that's the only state we care about
isLocked: powerMonitor.getSystemIdleState(1) === 'locked',
// note: this is only available from Electron 12, earlier versions cannot
// read the battery state without 'on-ac'/'on-battery' events
usingBattery: powerMonitor.onBatteryPower
app.whenReady().then(() => {
client.addMetadata('device', {
// the value for 'idleThreshold' doesn't matter here because it is ignored
// if the system is locked and that's the only state we care about
isLocked: powerMonitor.getSystemIdleState(1) === 'locked',
// note: this is only available from Electron 12, earlier versions cannot
// read the battery state without 'on-ac'/'on-battery' events
usingBattery: powerMonitor.onBatteryPower
})

powerMonitor.on('on-ac', () => {
client.addMetadata('device', { usingBattery: false })
})

powerMonitor.on('on-battery', () => {
client.addMetadata('device', { usingBattery: true })
})

powerMonitor.on('unlock-screen', () => {
client.addMetadata('device', { isLocked: false })
})

powerMonitor.on('lock-screen', () => {
client.addMetadata('device', { isLocked: true })
})
})

client.addOnError(event => {
event.device = Object.assign(
{},
event.device,
device,
{
freeMemory: kibibytesToBytes(process.getSystemMemoryInfo().free),
time: new Date()
}
)

event.addMetadata('device', { idleTime: powerMonitor.getSystemIdleTime() })

setDefaultUserId(event)
}, true)

app.whenReady().then(() => {
// on windows, app.getLocale won't return the locale until the app is ready
const locale = app.getLocale()
Expand Down Expand Up @@ -88,38 +122,6 @@ module.exports = (app, screen, process, filestore, NativeClient, powerMonitor) =
})
})

powerMonitor.on('on-ac', () => {
client.addMetadata('device', { usingBattery: false })
})

powerMonitor.on('on-battery', () => {
client.addMetadata('device', { usingBattery: true })
})

powerMonitor.on('unlock-screen', () => {
client.addMetadata('device', { isLocked: false })
})

powerMonitor.on('lock-screen', () => {
client.addMetadata('device', { isLocked: true })
})

client.addOnError(event => {
event.device = Object.assign(
{},
event.device,
device,
{
freeMemory: kibibytesToBytes(process.getSystemMemoryInfo().free),
time: new Date()
}
)

event.addMetadata('device', { idleTime: powerMonitor.getSystemIdleTime() })

setDefaultUserId(event)
}, true)

client.addOnSession(session => {
session.device = Object.assign(
{},
Expand Down
3 changes: 2 additions & 1 deletion scripts/cppcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ SUPPRESSED_ERRORS=(\
--suppress='unusedVariable:*/deps/*' \
--suppress='variableScope:*/deps/*' \
--suppress='ConfigurationNotChecked:*/deps/parson/parson.c:1425' \
--suppress='knownConditionTrueFalse:*/deps/parson/parson.c:692' \
--suppress='knownConditionTrueFalse:*/deps/parson/parson.c:600' \
--suppress='memleak:*/plugin-electron-client-state-persistence/src/deps/tinycthread/tinycthread.c:620' \
--suppress='constParameter:*/plugin-electron-client-state-persistence/src/deps/tinycthread/tinycthread.c:591' \
--suppress='unusedFunction:*/plugin-electron-client-state-persistence/src/api.c:513' \
--suppress='unusedFunction:*/plugin-electron-app/src/api.c:60')

Expand Down
2 changes: 1 addition & 1 deletion test/electron/features/support/steps/request-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { readFixtureFile } = require('../utils')
const expect = require('../utils/expect')
const { applySourcemaps } = require('../utils/source-mapper')

const REQUEST_RESOLUTION_TIMEOUT = 3000
const REQUEST_RESOLUTION_TIMEOUT = 5000
const launchConfig = { timeout: 30 * 1000 }
const requestDelay = (callback) => new Promise((resolve, reject) => {
setTimeout(() => callback(resolve), REQUEST_RESOLUTION_TIMEOUT)
Expand Down

0 comments on commit 775699d

Please sign in to comment.