Skip to content

Commit

Permalink
update interfaces and expose types in the app
Browse files Browse the repository at this point in the history
  • Loading branch information
shlokamin authored and mjhuff committed Dec 2, 2024
1 parent e40300a commit 97da10c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 23 deletions.
8 changes: 4 additions & 4 deletions app-shell/src/__tests__/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('update', () => {

vi.mocked(ElectronUpdater.autoUpdater).emit('update-available', {
version: '1.0.0',
})
} as any)

expect(dispatch).toHaveBeenCalledWith({
type: 'shell:CHECK_UPDATE_RESULT',
Expand All @@ -50,7 +50,7 @@ describe('update', () => {
handleAction({ type: 'shell:CHECK_UPDATE', meta: { shell: true } })
vi.mocked(ElectronUpdater.autoUpdater).emit('update-not-available', {
version: '1.0.0',
})
} as any)

expect(dispatch).toHaveBeenCalledWith({
type: 'shell:CHECK_UPDATE_RESULT',
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('update', () => {
vi.mocked(ElectronUpdater.autoUpdater).downloadUpdate
).toHaveBeenCalledTimes(1)

const progress = {
const progress: any = {
percent: 20,
}

Expand All @@ -97,7 +97,7 @@ describe('update', () => {

vi.mocked(ElectronUpdater.autoUpdater).emit('update-downloaded', {
version: '1.0.0',
})
} as any)

expect(dispatch).toHaveBeenCalledWith({
type: 'shell:DOWNLOAD_UPDATE_RESULT',
Expand Down
2 changes: 2 additions & 0 deletions app-shell/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { UpdateFileInfo } from 'electron-updater'
import type { ReleaseNoteInfo } from 'builder-util-runtime'
// TODO(mc, 2018-08-08): figure out type exports from app
import type {
Action,
Expand Down
12 changes: 3 additions & 9 deletions app-shell/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import updater from 'electron-updater'
import { createLogger } from './log'
import { getConfig } from './config'
import { UI_INITIALIZED, UPDATE_VALUE } from './constants'
import type { UpdateInfo } from '@opentrons/app/src/redux/shell/types'
import type { UpdateInfo } from '@opentrons/app'
import type { Action, Dispatch, PlainError } from './types'

const autoUpdater = updater.autoUpdater

autoUpdater.logger = createLogger('update')
autoUpdater.autoDownload = false
autoUpdater.forceDevUpdateConfig = true

export const CURRENT_VERSION: string = autoUpdater.currentVersion.version

Expand Down Expand Up @@ -77,16 +78,9 @@ interface ProgressInfo {
percent: number
bytesPerSecond: number
}
interface DownloadingPayload {
progress: ProgressInfo
bytesPerSecond: number
percent: number
total: number
transferred: number
}

function downloadUpdate(dispatch: Dispatch): void {
const onDownloading = (payload: DownloadingPayload): void => {
const onDownloading = (payload: ProgressInfo): void => {
dispatch({ type: 'shell:DOWNLOAD_PERCENTAGE', payload })
}
const onDownloaded = (): void => {
Expand Down
5 changes: 4 additions & 1 deletion app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HashRouter } from 'react-router-dom'

import { ApiClientProvider } from '@opentrons/react-api-client'

import { App } from './App'
import { createLogger } from './logger'

import { uiInitialized } from './redux/shell'
Expand All @@ -16,8 +17,10 @@ import '../src/atoms/SoftwareKeyboard/FullKeyboard/index.css'
import '../src/atoms/SoftwareKeyboard/IndividualKey/index.css'
import '../src/atoms/SoftwareKeyboard/NumericalKeyboard/index.css'

// export public types so they can be accessed by external deps
export * from './redux/types'

// component tree
import { App } from './App'

const log = createLogger(new URL('', import.meta.url).pathname)

Expand Down
11 changes: 9 additions & 2 deletions app/src/organisms/Desktop/UpdateAppModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ export function UpdateAppModal(props: UpdateAppModalProps): JSX.Element {
error,
info: updateInfo,
} = updateState
const releaseNotes = updateInfo?.releaseNotes
let releaseNotesText = updateInfo?.releaseNotes
if (Array.isArray(releaseNotesText)) {
// it is unclear to me why/how electron-updater would ever expose
// release notes this way, but this should never happen...
// this string representation should always be returned
releaseNotesText = releaseNotesText[0].note
}

const { t } = useTranslation(['app_settings', 'branded'])
const navigate = useNavigate()
const { removeActiveAppUpdateToast } = useRemoveActiveAppUpdateToast()
Expand Down Expand Up @@ -192,7 +199,7 @@ export function UpdateAppModal(props: UpdateAppModalProps): JSX.Element {
<UpdateAppBanner type="informing" marginBottom={SPACING.spacing8}>
{t('branded:update_requires_restarting_app')}
</UpdateAppBanner>
<ReleaseNotes source={releaseNotes} />
<ReleaseNotes source={releaseNotesText} />
</Flex>
</Modal>
) : null}
Expand Down
1 change: 1 addition & 0 deletions app/src/redux/shell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export * from './selectors'
export * from './update'
export * from './is-ready/actions'
export * from './is-ready/selectors'
export * from './types'

export const CURRENT_VERSION: string = _PKG_VERSION_
11 changes: 4 additions & 7 deletions app/src/redux/shell/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { IpcMainEvent } from 'electron'
import type { UpdateFileInfo } from 'electron-updater'
import type { ReleaseNoteInfo } from 'builder-util-runtime'
import type { Error } from '../types'
import type { RobotSystemAction } from './is-ready/types'

Expand Down Expand Up @@ -31,16 +33,11 @@ export type NotifyBrokerResponses = NotifyRefetchData | NotifyUnsubscribeData
export type NotifyNetworkError = 'ECONNFAILED' | 'ECONNREFUSED'
export type NotifyResponseData = NotifyBrokerResponses | NotifyNetworkError

interface File {
sha512: string
url: string
[key: string]: unknown
}
export interface UpdateInfo {
version: string
files: File[]
files: UpdateFileInfo[]
releaseDate?: string
releaseNotes?: string
releaseNotes?: string | null | ReleaseNoteInfo[]
}

export interface ShellUpdateState {
Expand Down
2 changes: 2 additions & 0 deletions app/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ export type Epic = (
) => Observable<Action>

export type Error = Partial<{ name: string; message: string }>

export * from './shell/types'

0 comments on commit 97da10c

Please sign in to comment.