Skip to content

Commit

Permalink
fix(powerMonitor): experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
lemnik committed Oct 10, 2023
1 parent 53e18c1 commit 24de901
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/electron/src/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = (opts) => {
require('@bugsnag/plugin-node-unhandled-rejection'),
require('@bugsnag/plugin-electron-app')(NativeClient, process, electron.app, electron.BrowserWindow, filestore),
require('@bugsnag/plugin-electron-app-breadcrumbs')(electron.app, electron.BrowserWindow),
require('@bugsnag/plugin-electron-device')(electron.app, electron.screen, process, filestore, NativeClient, electron.app.whenReady().then(() => electron.powerMonitor)),
require('@bugsnag/plugin-electron-device')(electron.app, electron.screen, process, filestore, NativeClient, electron.powerMonitor),
require('@bugsnag/plugin-electron-session')(electron.app, electron.BrowserWindow, NativeClient),
require('@bugsnag/plugin-console-breadcrumbs'),
require('@bugsnag/plugin-strip-project-root'),
Expand Down
32 changes: 17 additions & 15 deletions packages/plugin-electron-device/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const createDeviceUpdater = (client, NativeClient, device) => newProperties => {
}
}

module.exports = (app, screen, process, filestore, NativeClient, powerMonitorPromise) => ({
module.exports = (app, screen, process, filestore, NativeClient, powerMonitor) => ({
load (client) {
const device = {}
let cachedDevice = {}
Expand Down Expand Up @@ -45,7 +45,7 @@ module.exports = (app, screen, process, filestore, NativeClient, powerMonitorPro
}
})

powerMonitorPromise.then(powerMonitor => {
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
Expand All @@ -70,23 +70,25 @@ module.exports = (app, screen, process, filestore, NativeClient, powerMonitorPro
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()
}
)
client.addOnError(event => {
event.device = Object.assign(
{},
event.device,
device,
{
freeMemory: kibibytesToBytes(process.getSystemMemoryInfo().free),
time: new Date()
}
)

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

setDefaultUserId(event)
}, true)
})
setDefaultUserId(event)
}, true)

app.whenReady().then(() => {
// on windows, app.getLocale won't return the locale until the app is ready
Expand Down

0 comments on commit 24de901

Please sign in to comment.