Skip to content

Commit

Permalink
fix(app): make shell remote check lazier to avoid spurious assertions (
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Aug 20, 2019
1 parent bd604e2 commit 7aaad6d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
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

0 comments on commit 7aaad6d

Please sign in to comment.