Skip to content

Commit

Permalink
perf(app): Upgrade Electron to v3 and remove Node in renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Oct 2, 2018
1 parent be24335 commit 61ab5ac
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 213 deletions.
13 changes: 13 additions & 0 deletions __mocks__/setup-mock-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// sets up a mock global available to all tests
'use strict'

const mockElectron = require('./electron')

global.APP_SHELL = {
__mockElectron: mockElectron,
ipcRenderer: mockElectron.ipcRenderer,
apiUpdate: mockElectron.remote.require('./api-update'),
config: mockElectron.remote.require('./config'),
discovery: mockElectron.remote.require('./discovery'),
update: mockElectron.remote.require('./update'),
}
75 changes: 8 additions & 67 deletions app-shell/build/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Changes since 3.3.0
# Changes since 3.4.0

For more details, please see the full [technical change log][changelog]

Expand All @@ -7,91 +7,32 @@ For more details, please see the full [technical change log][changelog]
<!-- start:@opentrons/app -->
## Opentrons App

We've updated the app to give you information about your protocols _before_ you start calibrating and running your robot. On top of that, our **Linux build of the app is now able to self-update!**

### Known issues

- Downgrading back to `3.4.0` from later releases _may_ cause the app to crash unless you delete the configuration folder (which will reset your app's configuration):
- macOS: `~/Library/Application Support/Opentrons`
- Linux: `~/.config/Opentrons`
- Windows: `%APPDATA%\Opentrons`
- The app's run log is still having problems displaying the current run step, especially if pauses and resumes are involved ([#2047][2047])

### Bug fixes

- Cleaned up some scrolling and modal coverage issues
- Ensured that external links actually get opened in your browser
- Fixed a bug where the arrow keys could change the jog step size (thanks to [Philipp Jaeger][2300] for reporting this issue!)
- Fixed support chat so required configuration information is properly sent

[2047]: https://github.com/Opentrons/opentrons/issues/2047
[2300]: https://github.com/Opentrons/opentrons/issues/2300

### New features
### Bug fixes

- When updating your app, you're going to see these release notes to see what's changed since the last version
- Linux builds are now packaged as [AppImages][appimage], which means:
- The Linux version of the app now supports auto-update
- While we only officially support Ubuntu, the app _should_ now also be able to run on Fedora 21 or later
- We've got a shiny new protocol summary page to give you more information about your protocol at a glance after you upload it
- The app now automatically provides pipette configuration to support chat so our wonderful staff can better help you
### New features

[appimage]: https://appimage.org/
<!-- end:@opentrons/app -->


<!-- start:@opentrons/api -->
## OT2 and Protocol API

This update is all about improving the reliability of your robot and getting you new and updated labware definitions! Remember to update your robot after you update your app to get these changes onto your OT2.

### Known issues

- This update includes updates to several labware definitions. Please note **these will not overwrite your current labware definitions**, unless you reset your robot's labware definitions. If you would like to get the updates:
- In the app, go to "Robots" > your robot > "Advanced Settings" > "Factory Reset"
- Unfortunately **this will clear out all your previous labware calibrations**
- You will, however, get various fixes to the base definitions that will reduce the amount of calibration you need to do in the future
- While the underlying definition is now correct, there is a known API bug that is causing the robot to think a `50ml` tube in a `15/50ml` tuberack is the same height as the `15ml` tube
- While the underlying definition is correct, there is a known API bug that is causing the robot to think a `50ml` tube in a `15/50ml` tuberack is the same height as the `15ml` tube

### Bug fixes

- Fixed some problems with the Bio-Rad PCR and 10µL tiprack definitions
- Fixed a variety of problems with how the robot boots that could result in an unresponsive robot
- Ensured that factory reset really does clear the labware database every time
- Fixed a problem with state from protocol simulation hanging around for the actual run (which could confuse the robot into thinking it had a tip on when it did not)
- Removed deck calibration from the factory reset options, because the proper way to reset your deck calibration is to go through the full deck calibration process

### New features

- Added a bunch of new labware definitions!
- [Opentrons modular tuberack set][tuberacks]
- `opentrons-tuberack-15ml`
- `opentrons-tuberack-50ml`
- `opentrons-tuberack-15_50ml`
- `opentrons-tuberack-2ml-eppendorf`
- `opentrons-tuberack-2ml-screwcap`
- [Opentrons aluminum block set][blocks]
- `opentrons-aluminum-block-2ml-eppendorf`
- `opentrons-aluminum-block-2ml-screwcap`
- `opentrons-aluminum-block-96-PCR-plate`
- `opentrons-aluminum-block-PCR-strips-200ul`
- Enjoy using your shiny new tube rack sets and [Temperature Module][tempdeck]!
- Did a lot of plumbing work for upcoming WiFi improvements. (Enterprise networks! Hidden SSIDs!) Keep an eye out for these changes to be finished in an upcoming release
- The API will now automatically keep the firmware of its Smoothie motor controller board up-to-date
- `robot.pause` now supports an optional message to display in the app's run log

```
robot.pause(msg='Waiting for you to click "Resume"')
```
- The min. and max. volumes of the default pipette constructors in the protocol API can now be optionally overridden (thanks [@rvinzent][rvinzent]!)
```
p300 = instruments.P300_Single(
mount='right',
min_volume=42,
max_volume=240,
)
```
[tuberacks]: https://shop.opentrons.com/collections/opentrons-tips/products/tube-rack-set-1
[blocks]: https://shop.opentrons.com/products/aluminum-block-set
[tempdeck]: https://shop.opentrons.com/products/tempdeck
[rvinzent]: https://github.com/Opentrons/opentrons/pull/2084
<!-- end:@opentrons/api -->
2 changes: 1 addition & 1 deletion app-shell/electron-builder.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"appId": "com.opentrons.app",
"electronVersion": "1.8.3",
"electronVersion": "3.0.2",
"files": [
"**/*",
{
Expand Down
6 changes: 3 additions & 3 deletions app-shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"@opentrons/discovery-client": "3.4.0",
"@thi.ng/paths": "^1.3.8",
"dateformat": "^3.0.3",
"electron-debug": "^1.1.0",
"electron-devtools-installer": "^2.2.0",
"electron-store": "^1.3.0",
"electron-debug": "^2.0.0",
"electron-devtools-installer": "^2.2.4",
"electron-store": "^2.0.0",
"electron-updater": "^3.1.2",
"fs-extra": "^6.0.1",
"merge-options": "^1.0.1",
Expand Down
13 changes: 13 additions & 0 deletions app-shell/src/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @flow
// preload script for renderer process
// defines subset of Electron API that renderer process is allowed to access
// for security reasons
import {ipcRenderer, remote} from 'electron'

global.APP_SHELL = {
ipcRenderer,
apiUpdate: remote.require('./api-update'),
config: remote.require('./config'),
discovery: remote.require('./discovery'),
update: remote.require('./update'),
}
9 changes: 2 additions & 7 deletions app-shell/src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ const WINDOW_OPTS = {
height: config.height,
// allow webPreferences to be set at launchtime from config
webPreferences: Object.assign({
// TODO(mc, 2018-05-15): turn off experimentalFeatures?
experimentalFeatures: true,

// TODO(mc, 2018-05-15): disable nodeIntegration in renderer thread
nodeIntegration: true,
// node integration needed for mdns robot discovery in webworker
nodeIntegrationInWorker: true,
preload: path.join(__dirname, './preload.js'),
nodeIntegration: false,
}, config.webPreferences),
}

Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@opentrons/shared-data": "3.4.0",
"@thi.ng/paths": "^1.3.8",
"classnames": "^2.2.5",
"electron": "1.8.3",
"events": "^3.0.0",
"history": "^4.7.2",
"lodash": "^4.17.4",
"mixpanel-browser": "^2.22.1",
Expand Down
2 changes: 1 addition & 1 deletion app/src/logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
// logger
import {ipcRenderer} from 'electron'
const {ipcRenderer} = global.APP_SHELL

// TODO(mc, 2018-05-17): put this type somewhere common to app and app-shell
export type LogLevel =
Expand Down
6 changes: 2 additions & 4 deletions app/src/shell/__tests__/api-update.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import electron from 'electron'
import {mockResolvedValue} from '../../../__util__/mock-promise'
import * as apiUpdate from '../api-update'

jest.mock('electron')

const {'./api-update': mockApiUpdate} = electron.__mockRemotes
const {apiUpdate: mockApiUpdate} = global.APP_SHELL

describe('shell/api-update', () => {
let _Blob
Expand All @@ -16,6 +13,7 @@ describe('shell/api-update', () => {

afterEach(() => {
global.Blob = _Blob
jest.clearAllMocks()
})

test('reducer puts update info in state', () => {
Expand Down
11 changes: 4 additions & 7 deletions app/src/shell/__tests__/shell.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// tests for the shell module
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import electron from 'electron'

import {shellMiddleware, getShellConfig} from '..'

jest.mock('../../logger')
jest.mock('electron')

const middlewares = [thunk, shellMiddleware]
const mockStore = configureMockStore(middlewares)
const {'./config': mockConfig} = electron.__mockRemotes
const {ipcRenderer: mockIpc, config: mockConfig} = global.APP_SHELL

describe('app shell module', () => {
afterEach(() => {
Expand All @@ -23,17 +21,16 @@ describe('app shell module', () => {
const action = {type: 'foo', meta: {shell: true}}

store.dispatch(action)
expect(electron.ipcRenderer.send).toHaveBeenCalledWith('dispatch', action)
expect(mockIpc.send).toHaveBeenCalledWith('dispatch', action)
})

test('catches actions from main and dispatches them to redux', () => {
const store = mockStore({})
const action = {type: 'foo'}

expect(electron.ipcRenderer.on)
.toHaveBeenCalledWith('dispatch', expect.any(Function))
expect(mockIpc.on).toHaveBeenCalledWith('dispatch', expect.any(Function))

const dispatchHandler = electron.ipcRenderer.on.mock.calls.find(call => {
const dispatchHandler = mockIpc.on.mock.calls.find(call => {
return call[0] === 'dispatch' && typeof call[1] === 'function'
})[1]

Expand Down
6 changes: 3 additions & 3 deletions app/src/shell/api-update.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @flow
import {remote} from 'electron'

import type {State} from '../types'

export type ApiUpdateInfo = {
filename: string,
version: string,
}

const {getUpdateInfo, getUpdateFileContents} = remote.require('./api-update')
const {
apiUpdate: {getUpdateInfo, getUpdateFileContents},
} = global.APP_SHELL

export function apiUpdateReducer (state: ?ApiUpdateInfo) {
if (!state) return getUpdateInfo()
Expand Down
10 changes: 6 additions & 4 deletions app/src/shell/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
// desktop shell module
import {remote, ipcRenderer} from 'electron'
import {combineReducers} from 'redux'

import createLogger from '../logger'
Expand All @@ -16,9 +15,12 @@ import type {ShellUpdateAction} from './update'

export type ShellAction = ShellUpdateAction

const {CURRENT_VERSION, CURRENT_RELEASE_NOTES} = remote.require('./update')
const {getConfig} = remote.require('./config')
const {getRobots} = remote.require('./discovery')
const {
ipcRenderer,
update: {CURRENT_VERSION, CURRENT_RELEASE_NOTES},
config: {getConfig},
discovery: {getRobots},
} = global.APP_SHELL

const log = createLogger(__filename)

Expand Down
15 changes: 8 additions & 7 deletions app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ const OUTPUT_PATH = path.join(__dirname, 'dist')
const JS_OUTPUT_NAME = 'bundle.js'
const CSS_OUTPUT_NAME = 'style.css'

const entry = [
JS_BUNDLE_ENTRY,
]
const entry = [JS_BUNDLE_ENTRY]

const output = {
path: OUTPUT_PATH,
Expand All @@ -42,13 +40,13 @@ const rules = [
namedRules.images,
]

const target = 'electron-renderer'
const target = 'web'

const plugins = [
new webpack.EnvironmentPlugin(
Object.keys(process.env).filter(v => v.startsWith('OT_APP')).concat([
'NODE_ENV',
])
Object.keys(process.env)
.filter(v => v.startsWith('OT_APP'))
.concat(['NODE_ENV'])
),

new ExtractTextPlugin({
Expand Down Expand Up @@ -108,5 +106,8 @@ module.exports = {
devServer,
node: {
__filename: true,
// use userland events because webpack's is out of date
// https://github.com/webpack/node-libs-browser/issues/78
events: false,
},
}
35 changes: 35 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

module.exports = {
setupFiles: ['<rootDir>/__mocks__/setup-mock-globals.js'],
moduleNameMapper: {
'\\.(css)$': 'identity-obj-proxy',
},
transform: {
'^.+\\.js$': 'babel-jest',
'\\.(jpg|png|gif|svg|woff|woff2)$':
'@opentrons/components/src/__mocks__/file.js',
},
transformIgnorePatterns: ['/node_modules/(?!@opentrons/)'],
collectCoverageFrom: [
'**/*.js',
'!.eslintrc.js',
'!.stylelintrc.js',
'!api/**',
'!webpack-config/**',
'!**/scripts/**',
'!components/interfaces/**',
'!components/styleguide.config.js',
'!**/node_modules/**',
'!**/__mocks__/**',
'!**/dist/**',
'!**/build/**',
'!**/webpack*',
'!**/webpack/**',
'!**/coverage/**',
'!**/test/**',
'!**/test-with-flow/**',
'!**/flow-typed/**',
],
coverageReporters: ['lcov', 'text'],
}
Loading

0 comments on commit 61ab5ac

Please sign in to comment.