From a223705d078fd49481ed2efeb943f9ef6039cbc6 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Tue, 26 Sep 2023 14:46:09 -0400 Subject: [PATCH] fix linux SIGTRAP related to power monitor (#1670) * fix linux SIGTRAP related to power monitor * update tests --------- Co-authored-by: Jordan Muir --- main/chains/index.js | 24 +++++++++++++----------- package-lock.json | 14 +++++++------- package.json | 2 +- test/__mocks__/electron.js | 13 ++++++------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/main/chains/index.js b/main/chains/index.js index a02063c0d..ab1471a58 100644 --- a/main/chains/index.js +++ b/main/chains/index.js @@ -1,6 +1,6 @@ // status = Network Mismatch, Not Connected, Connected, Standby, Syncing -const { powerMonitor } = require('electron') +const { app, powerMonitor } = require('electron') const EventEmitter = require('events') const { addHexPrefix } = require('@ethereumjs/util') const { Hardfork } = require('@ethereumjs/common') @@ -491,19 +491,21 @@ class Chains extends EventEmitter { }) } - powerMonitor.on('resume', () => { - const activeConnections = Object.keys(this.connections) - .map((type) => Object.keys(this.connections[type]).map((chainId) => `${type}:${chainId}`)) - .flat() + app.on('ready', () => { + powerMonitor.on('resume', () => { + const activeConnections = Object.keys(this.connections) + .map((type) => Object.keys(this.connections[type]).map((chainId) => `${type}:${chainId}`)) + .flat() - log.info('System resuming, resetting active connections', { chains: activeConnections }) + log.info('System resuming, resetting active connections', { chains: activeConnections }) - activeConnections.forEach((id) => { - const [type, chainId] = id.split(':') - removeConnection(chainId, type) - }) + activeConnections.forEach((id) => { + const [type, chainId] = id.split(':') + removeConnection(chainId, type) + }) - updateConnections() + updateConnections() + }) }) store.observer(updateConnections, 'chains:connections') diff --git a/package-lock.json b/package-lock.json index 2fb43955c..f61efc65f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -107,7 +107,7 @@ "@types/zxcvbn": "4.4.1", "@typescript-eslint/eslint-plugin": "5.54.1", "@typescript-eslint/parser": "5.54.1", - "electron": "25.8.2", + "electron": "^26.2.2", "electron-builder": "23.6.0", "electron-devtools-installer": "3.2.0", "electron-extension-installer": "1.2.0", @@ -13882,9 +13882,9 @@ } }, "node_modules/electron": { - "version": "25.8.2", - "resolved": "https://registry.npmjs.org/electron/-/electron-25.8.2.tgz", - "integrity": "sha512-AM1ra6b16EQuO1bJtiA8ZiWqqFLLgVfxD56ykiy+EA5C63Hkx8OmIbe+5JAsLiTwRVvBZ4oCAj6wa2qT+iq8ww==", + "version": "26.2.2", + "resolved": "https://registry.npmjs.org/electron/-/electron-26.2.2.tgz", + "integrity": "sha512-Ihb3Zt4XYnHF52DYSq17ySkgFqJV4OT0VnfhUYZASAql7Vembz3VsAq7mB3OALBHXltAW34P8BxTIwTqZaMS3g==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -38181,9 +38181,9 @@ } }, "electron": { - "version": "25.8.2", - "resolved": "https://registry.npmjs.org/electron/-/electron-25.8.2.tgz", - "integrity": "sha512-AM1ra6b16EQuO1bJtiA8ZiWqqFLLgVfxD56ykiy+EA5C63Hkx8OmIbe+5JAsLiTwRVvBZ4oCAj6wa2qT+iq8ww==", + "version": "26.2.2", + "resolved": "https://registry.npmjs.org/electron/-/electron-26.2.2.tgz", + "integrity": "sha512-Ihb3Zt4XYnHF52DYSq17ySkgFqJV4OT0VnfhUYZASAql7Vembz3VsAq7mB3OALBHXltAW34P8BxTIwTqZaMS3g==", "dev": true, "requires": { "@electron/get": "^2.0.0", diff --git a/package.json b/package.json index 724f4e40e..d3af9e63e 100644 --- a/package.json +++ b/package.json @@ -158,7 +158,7 @@ "@types/zxcvbn": "4.4.1", "@typescript-eslint/eslint-plugin": "5.54.1", "@typescript-eslint/parser": "5.54.1", - "electron": "25.8.2", + "electron": "26.2.2", "electron-builder": "23.6.0", "electron-devtools-installer": "3.2.0", "electron-extension-installer": "1.2.0", diff --git a/test/__mocks__/electron.js b/test/__mocks__/electron.js index 0d4d2e76b..dd9f92118 100644 --- a/test/__mocks__/electron.js +++ b/test/__mocks__/electron.js @@ -4,14 +4,13 @@ const dataPaths = { userData: './test/.userData' } -const app = { - getVersion: () => '0.1', - getName: () => 'frame-test-app', - getPath: (key) => dataPaths[key] -} - -const setDataPath = (key, path) => (dataPaths[key] = path) +const app = new EventEmitter() +app.getVersion = () => '0.1' +app.getName = () => 'frame-test-app' +app.getPath = (key) => dataPaths[key] const powerMonitor = new EventEmitter() +const setDataPath = (key, path) => (dataPaths[key] = path) + export { app, setDataPath as _setDataPath, powerMonitor }