Skip to content

Commit 4b15297

Browse files
committed
electron mock ipc. turn off eslint console
1 parent 58cd8cb commit 4b15297

File tree

10 files changed

+39
-9
lines changed

10 files changed

+39
-9
lines changed

.erb/configs/webpack.config.renderer.dev.ts

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ const configuration: webpack.Configuration = {
168168
shell: true,
169169
stdio: 'inherit',
170170
})
171+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
171172
.on('close', (code: number) => process.exit(code!))
172173
.on('error', (spawnError) => console.error(spawnError));
173174

@@ -178,6 +179,7 @@ const configuration: webpack.Configuration = {
178179
})
179180
.on('close', (code: number) => {
180181
preloadProcess.kill();
182+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
181183
process.exit(code!);
182184
})
183185
.on('error', (spawnError) => console.error(spawnError));

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
'import/no-unresolved': 'error',
77
// Since React 17 and typescript 4.1 you can safely disable the rule
88
'react/react-in-jsx-scope': 'off',
9+
'no-console': 'off',
910
},
1011
parserOptions: {
1112
ecmaVersion: 2020,

globals.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'await-sleep';

package-lock.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110
},
111111
"moduleNameMapper": {
112112
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/.erb/mocks/fileMock.js",
113-
"\\.(css|less|sass|scss)$": "identity-obj-proxy"
113+
"\\.(css|less|sass|scss)$": "identity-obj-proxy",
114+
"^electron$": "<rootDir>/spec/mock/electron-mock.ts"
114115
},
115116
"moduleFileExtensions": [
116117
"js",
@@ -156,6 +157,7 @@
156157
"electron": "^16.0.5",
157158
"electron-builder": "22.13.1",
158159
"electron-devtools-installer": "^3.2.0",
160+
"electron-mock-ipc": "^0.3.12",
159161
"electron-notarize": "^1.1.1",
160162
"electron-rebuild": "^3.2.5",
161163
"electronmon": "^2.0.2",

spec/mock/electron-mock.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import createIPCMock from 'electron-mock-ipc';
2+
3+
const mocked = createIPCMock();
4+
const { ipcMain, ipcRenderer } = mocked;
5+
export { ipcMain, ipcRenderer };

src/main/geth.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import sleep from 'await-sleep';
66
// import fetch from 'node-fetch';
77

88
import { send, CHANNELS, MESSAGES } from './messenger';
9-
import { exec, execAwait } from './execHelper';
9+
import { execAwait } from './execHelper';
1010
import { getNNDirPath, gethDataDir } from './files';
1111

1212
const axios = require('axios').default;
@@ -25,7 +25,7 @@ export const downloadGeth = async () => {
2525
await access(gethDataDir());
2626
} catch {
2727
console.log('making geth data dir...');
28-
const nnDir = await mkdir(gethDataDir());
28+
await mkdir(gethDataDir());
2929
}
3030

3131
try {
@@ -60,7 +60,7 @@ export const downloadGeth = async () => {
6060
console.log('done piping response from github to filestream');
6161
await fileWriteStream.close();
6262
// allow anyone to read the file
63-
const chresults = await chmod(`${getNNDirPath()}/geth.tar.gz`, 0o444);
63+
await chmod(`${getNNDirPath()}/geth.tar.gz`, 0o444);
6464
} catch (err2) {
6565
console.error(err2, 'error extracting geth');
6666
throw err2;

src/main/messenger.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const setWindow = (inMainWindow: BrowserWindow): void => {
66
mainWindow = inMainWindow;
77
};
88

9+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
910
export const send = (channel: string, ...args: any[]): void => {
1011
if (!mainWindow) {
1112
console.error('mainWindow is unset');

src/main/power.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { powerSaveBlocker } from 'electron';
22

3-
let id: number;
3+
let id: number | undefined;
44
// eslint-disable-next-line import/prefer-default-export
55
export const dontSuspendSystem = () => {
66
// "Block the system from entering low-power (sleep) mode."

src/renderer/App.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useCallback, useEffect, useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import { MemoryRouter as Router, Routes, Route } from 'react-router-dom';
3+
import { ipcRenderer } from 'electron';
34
import { CHANNELS } from './messages';
45
import './App.css';
56

@@ -16,7 +17,7 @@ const MainScreen = () => {
1617

1718
useEffect(() => {
1819
console.log('App loaded. Initializing...');
19-
window.electron.ipcRenderer.on(CHANNELS.geth, (message) => {
20+
ipcRenderer.on(CHANNELS.geth, (_event, message) => {
2021
console.log('Geth status received: ', message);
2122
setStatus(message);
2223
});
@@ -27,13 +28,13 @@ const MainScreen = () => {
2728

2829
const onClickStartGeth = async () => {
2930
// Send message to main process to start Geth
30-
const status = await window.electron.startGeth();
31+
await window.electron.startGeth();
3132
refreshGethStatus();
3233
};
3334

3435
const onClickStopGeth = async () => {
3536
// Send message to main process to start Geth
36-
const status = await window.electron.stopGeth();
37+
await window.electron.stopGeth();
3738
refreshGethStatus();
3839
};
3940

0 commit comments

Comments
 (0)