Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): make shell remote check lazier to avoid spurious assertions #3895

Merged
merged 2 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions app/src/shell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,15 @@ import type {
import type { ViewableRobot } from '../discovery'
import type { ShellState } from './types'

const { ipcRenderer } = remote
const { ipcRenderer, CURRENT_VERSION, CURRENT_RELEASE_NOTES } = remote

const log = createLogger(__filename)

export * from './update'
export * from './buildroot'
export * from './types'

const CURRENT_VERSION: string = remote.CURRENT_VERSION
const CURRENT_RELEASE_NOTES: string = remote.CURRENT_RELEASE_NOTES
const API_RELEASE_NOTES = CURRENT_RELEASE_NOTES.replace(
/<!-- start:@opentrons\/app -->([\S\s]*?)<!-- end:@opentrons\/app -->/,
''
)

export { CURRENT_VERSION, CURRENT_RELEASE_NOTES, API_RELEASE_NOTES }
export { CURRENT_VERSION, CURRENT_RELEASE_NOTES }

export const shellReducer: Reducer<ShellState, Action> = combineReducers<
_,
Expand Down
16 changes: 9 additions & 7 deletions app/src/shell/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
// access main process remote modules via attachments to `global`
import assert from 'assert'

assert(
global.APP_SHELL_REMOTE,
'Expected APP_SHELL_REMOTE to be attached to global scope; is app-shell/src/preload.js properly configured?'
)
import type { Remote } from './types'

const remote = new Proxy(global.APP_SHELL_REMOTE, {
const remote = new Proxy((({}: any): Remote), {
get(target, propName) {
assert(
propName in target,
global.APP_SHELL_REMOTE,
'Expected APP_SHELL_REMOTE to be attached to global scope; is app-shell/src/preload.js properly configured?'
)

assert(
propName in global.APP_SHELL_REMOTE,
`Expected APP_SHELL_REMOTE.${propName} to exist, is app-shell/src/preload.js properly configured?`
)

return target[propName]
return global.APP_SHELL_REMOTE[propName]
},
})

Expand Down
10 changes: 10 additions & 0 deletions app/src/shell/types.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// @flow
import type { Service } from '@opentrons/discovery-client'
import type { Config } from '../config/types'
import type { BuildrootState, BuildrootAction } from './buildroot/types'
import type { ShellUpdateState, ShellUpdateAction } from './update'

export type Remote = {|
ipcRenderer: {| send: (string, ...args: Array<mixed>) => void |},
CURRENT_VERSION: string,
CURRENT_RELEASE_NOTES: string,
INITIAL_CONFIG: Config,
INITIAL_ROBOTS: Array<Service>,
|}

export type ShellState = {|
update: ShellUpdateState,
buildroot: BuildrootState,
Expand Down