From 86468116f39246772aa5683d20533907e6468c3a Mon Sep 17 00:00:00 2001 From: Mike Cousins Date: Mon, 19 Aug 2019 18:50:10 -0400 Subject: [PATCH 1/2] fix(app): make shell remote check lazier to avoid spurious assertions --- app/src/shell/remote.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/src/shell/remote.js b/app/src/shell/remote.js index eb4eadb96ff..5fe75427f6d 100644 --- a/app/src/shell/remote.js +++ b/app/src/shell/remote.js @@ -2,20 +2,23 @@ // 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?' -) +const remote = new Proxy( + {}, + { + get(target, propName) { + assert( + global.APP_SHELL_REMOTE, + 'Expected APP_SHELL_REMOTE to be attached to global scope; is app-shell/src/preload.js properly configured?' + ) -const remote = new Proxy(global.APP_SHELL_REMOTE, { - get(target, propName) { - assert( - propName in target, - `Expected APP_SHELL_REMOTE.${propName} to exist, 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] + }, + } +) export default remote From 8a0ed3f7760a0a476bc2f6e9c4addf9d4b2519f3 Mon Sep 17 00:00:00 2001 From: Mike Cousins Date: Mon, 19 Aug 2019 19:42:15 -0400 Subject: [PATCH 2/2] fixup: Type remote now that it isnt an implicit any --- app/src/shell/index.js | 11 ++--------- app/src/shell/remote.js | 31 +++++++++++++++---------------- app/src/shell/types.js | 10 ++++++++++ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/src/shell/index.js b/app/src/shell/index.js index ebcedd826d7..caafae8218d 100644 --- a/app/src/shell/index.js +++ b/app/src/shell/index.js @@ -24,7 +24,7 @@ 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) @@ -32,14 +32,7 @@ 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( - /([\S\s]*?)/, - '' -) - -export { CURRENT_VERSION, CURRENT_RELEASE_NOTES, API_RELEASE_NOTES } +export { CURRENT_VERSION, CURRENT_RELEASE_NOTES } export const shellReducer: Reducer = combineReducers< _, diff --git a/app/src/shell/remote.js b/app/src/shell/remote.js index 5fe75427f6d..c4175b6086e 100644 --- a/app/src/shell/remote.js +++ b/app/src/shell/remote.js @@ -2,23 +2,22 @@ // access main process remote modules via attachments to `global` import assert from 'assert' -const remote = new Proxy( - {}, - { - get(target, propName) { - 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' - assert( - propName in global.APP_SHELL_REMOTE, - `Expected APP_SHELL_REMOTE.${propName} to exist, is app-shell/src/preload.js properly configured?` - ) +const remote = new Proxy((({}: any): Remote), { + get(target, propName) { + assert( + global.APP_SHELL_REMOTE, + 'Expected APP_SHELL_REMOTE to be attached to global scope; is app-shell/src/preload.js properly configured?' + ) - return global.APP_SHELL_REMOTE[propName] - }, - } -) + assert( + propName in global.APP_SHELL_REMOTE, + `Expected APP_SHELL_REMOTE.${propName} to exist, is app-shell/src/preload.js properly configured?` + ) + + return global.APP_SHELL_REMOTE[propName] + }, +}) export default remote diff --git a/app/src/shell/types.js b/app/src/shell/types.js index 1c420ffe97e..3ecd56502f7 100644 --- a/app/src/shell/types.js +++ b/app/src/shell/types.js @@ -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) => void |}, + CURRENT_VERSION: string, + CURRENT_RELEASE_NOTES: string, + INITIAL_CONFIG: Config, + INITIAL_ROBOTS: Array, +|} + export type ShellState = {| update: ShellUpdateState, buildroot: BuildrootState,