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

[CP-1742] fixes after QA #1089

Merged
merged 5 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,17 @@
"module.overview.systemUpdateAction": "Update now",
"module.overview.systemUpdateAvailable": "Update is available",
"module.overview.systemUpdateDownloaded": "Update is available",
"module.overview.systemUpdateCheckFailed": "Checking for update failed",
"module.overview.systemUpdateUpToDate": "You’re up to date.",
"module.overview.systemVersion": "MuditaOS version",
"module.overview.systemVersionTitle": "Current version:",
"module.overview.updateAvailableAboutOsVersionSubDescription": "the device will be upgraded to this version",
"module.overview.updateAvailableAboutUpdatesTitle": "{num, plural, =1 {ABOUT UPDATE} other {ABOUT UPDATES}}",
"module.overview.updateAvailableButton": "{num, plural, =1 {Download} other {Download all}}",
"module.overview.installUpdateButton": "{num, plural, =1 {Update} other {Update all}}",
"module.overview.updateAvailableCautionSectionTitle": "Caution",
"module.overview.updateAvailableDescription": "{num, plural, =1 {You can download the latest MuditaOS version.} other {You can download all the MuditaOS versions available to you with one click.}}",
"module.overview.updateAvailableForInstallDescription": "{num, plural, =1 {You can install the latest MuditaOS version.} other {You can install all the MuditaOS versions available to you with one click.}}",
"module.overview.updateAvailableMessage": "{num, plural, =1 {New update is available!} other {New updates are available!}}",
"module.overview.updateAvailableOsVersionDescription": "MuditaOS v{version} ({date})",
"module.overview.updateAvailableSequenceUpdateDescription": "1. The device cannot be used or disconnected during sequential update.\n2. If enabled, you will need to enter your phone passcode between updates.\n3. The device may restart several times during the update process.\n4. The update process may take longer than usual.",
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/__deprecated__/renderer/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export const { select } = store
export type RootState = RematchRootState<typeof models>
export type Store = typeof store
export type Dispatch = RematchDispatch<RootModel>
export type RejectableThunk = {
abort: () => void
}

// TODO replace `TmpDispatch` with legit `Dispatch`
// AUTO DISABLED - fix me if you like :)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

export enum CheckForUpdateLocalState {
Loading = "loading",
SilentCheckLoading = "silent-check-loading",
Failed = "failed",
Loaded = "loaded",
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
UpdateError,
} from "App/update/constants"
import { OsRelease, ProcessedRelease } from "App/update/dto"
import { RejectableThunk } from "App/__deprecated__/renderer/store"

export interface HarmonyOverviewProps {
readonly lowestSupportedOsVersion: string | undefined
Expand All @@ -36,7 +37,7 @@ export interface HarmonyOverviewProps {
readonly checkForUpdate: (
deviceType: DeviceType,
mode: CheckForUpdateMode
) => void
) => RejectableThunk
readonly setCheckForUpdateState: (state: State) => void
readonly downloadUpdates: (releases: OsRelease[]) => void
readonly clearUpdateState: () => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import { State } from "App/core/constants"
import { DeviceType } from "App/device/constants"
import { Feature, flags } from "App/feature-flags"
import { CheckForUpdateLocalState } from "App/overview/components/overview-screens/constants/overview.enum"
import { HarmonyOverviewProps } from "App/overview/components/overview-screens/harmony-overview/harmony-overview.component.interface"
import OverviewContent from "App/overview/components/overview-screens/harmony-overview/overview-content.component"
import { useUpdateFlowState } from "App/overview/components/overview-screens/helpers/use-update-flow-state.hook"
import { UpdateOsFlow } from "App/overview/components/update-os-flow"
import UpdatingForceModalFlow from "App/overview/components/updating-force-modal-flow/updating-force-modal-flow.component"
import { UpdatingForceModalFlowState } from "App/overview/components/updating-force-modal-flow/updating-force-modal-flow.enum"
import isVersionGreaterOrEqual from "App/overview/helpers/is-version-greater-or-equal"
import {
CheckForUpdateMode,
SilentCheckForUpdateState,
} from "App/update/constants"
import { CheckForUpdateMode } from "App/update/constants"
import { OsRelease } from "App/update/dto"
import { HelpActions } from "App/__deprecated__/common/enums/help-actions.enum"
import logger from "App/__deprecated__/main/utils/logger"
Expand Down Expand Up @@ -50,13 +49,12 @@ export const HarmonyOverview: FunctionComponent<HarmonyOverviewProps> = ({
setCheckForUpdateState,
}) => {
const [osVersionSupported, setOsVersionSupported] = useState(true)

const goToHelp = (): void => {
void ipcRenderer.callMain(HelpActions.OpenWindow)
}

const harmonySilentCheckForUpdate = () =>
checkForUpdate(DeviceType.MuditaHarmony, CheckForUpdateMode.SilentCheck)
const { checkForUpdateLocalState } = useUpdateFlowState({
checkingForUpdateState,
silentCheckForUpdateState,
checkForUpdate: () =>
checkForUpdate(DeviceType.MuditaHarmony, CheckForUpdateMode.SilentCheck),
})

useEffect(() => {
try {
Expand All @@ -68,17 +66,11 @@ export const HarmonyOverview: FunctionComponent<HarmonyOverviewProps> = ({
}
}, [osVersion, lowestSupportedOsVersion])

useEffect(() => {
if (silentCheckForUpdateState === SilentCheckForUpdateState.Initial) {
harmonySilentCheckForUpdate()
}
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [silentCheckForUpdateState])
const goToHelp = (): void => {
void ipcRenderer.callMain(HelpActions.OpenWindow)
}

// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/require-await
const closeUpdatingForceModalFlow = async () => {
const closeUpdatingForceModalFlow = () => {
setUpdateState(State.Initial)
}

Expand Down Expand Up @@ -133,6 +125,7 @@ export const HarmonyOverview: FunctionComponent<HarmonyOverviewProps> = ({
silentCheckForUpdateState={silentCheckForUpdateState}
checkForUpdateState={checkingForUpdateState}
availableReleasesForUpdate={availableReleasesForUpdate}
areAllReleasesDownloaded={areAllReleasesDownloaded}
downloadState={downloadingState}
tryAgainCheckForUpdate={tryAgainHarmonyUpdate}
clearUpdateOsFlow={clearUpdateState}
Expand Down Expand Up @@ -166,18 +159,21 @@ export const HarmonyOverview: FunctionComponent<HarmonyOverviewProps> = ({
disconnectDevice={disconnectDevice}
osVersion={osVersion}
pureOsAvailable={(availableReleasesForUpdate ?? []).length > 0}
checkForUpdateFailed={
checkForUpdateLocalState === CheckForUpdateLocalState.Failed
}
checkForUpdateInProgress={
checkForUpdateLocalState ===
CheckForUpdateLocalState.SilentCheckLoading
}
checkForUpdatePerformed={
silentCheckForUpdateState === SilentCheckForUpdateState.Loaded ||
checkingForUpdateState === State.Loaded
checkForUpdateLocalState === CheckForUpdateLocalState.Loaded
}
pureOsDownloaded={areAllReleasesDownloaded}
onUpdateCheck={checkForHarmonyUpdate}
onUpdateInstall={() => updateReleases()}
onUpdateDownload={openCheckForUpdateModal}
serialNumber={serialNumber}
checkForUpdateInProgress={
silentCheckForUpdateState === SilentCheckForUpdateState.Loading
}
/>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ interface OverviewProps {
readonly osVersion: string
readonly batteryLevel: number
readonly pureOsAvailable: boolean
readonly pureOsDownloaded: boolean | undefined
readonly pureOsDownloaded: boolean
readonly checkForUpdatePerformed: boolean
readonly checkForUpdateFailed: boolean
readonly deviceType: DeviceType
readonly serialNumber: string | undefined
}
Expand All @@ -43,6 +44,7 @@ const OverviewContent: FunctionComponent<OverviewProps> = ({
serialNumber,
checkForUpdateInProgress,
checkForUpdatePerformed,
checkForUpdateFailed,
}) => {
return (
<OverviewWrapper>
Expand All @@ -62,6 +64,7 @@ const OverviewContent: FunctionComponent<OverviewProps> = ({
onUpdate={onUpdateInstall}
checkForUpdateInProgress={checkForUpdateInProgress}
checkForUpdatePerformed={checkForUpdatePerformed}
checkForUpdateFailed={checkForUpdateFailed}
/>
</OverviewWrapper>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { State } from "App/core/constants"
import { CheckForUpdateLocalState } from "App/overview/components/overview-screens/constants/overview.enum"
import { SilentCheckForUpdateState } from "App/update/constants"
import { RejectableThunk } from "App/__deprecated__/renderer/store"
import { useEffect, useState } from "react"

interface Params {
silentCheckForUpdateState: SilentCheckForUpdateState
checkingForUpdateState: State
checkForUpdate: () => RejectableThunk
}

interface Result {
checkForUpdateLocalState: CheckForUpdateLocalState | undefined
}

export const useUpdateFlowState = ({
checkingForUpdateState,
silentCheckForUpdateState,
checkForUpdate,
}: Params): Result => {
const [checkForUpdateLocalState, setCheckForUpdateLocalState] =
useState<CheckForUpdateLocalState>()
const [silentCheckForUpdatePromise, setSilentCheckForUpdatePromise] =
useState<RejectableThunk>()

useEffect(() => {
if (silentCheckForUpdateState === SilentCheckForUpdateState.Initial) {
const actionResult = checkForUpdate()
setSilentCheckForUpdatePromise(actionResult)
}

return () => {
if (
silentCheckForUpdatePromise &&
silentCheckForUpdateState === SilentCheckForUpdateState.Loading
) {
silentCheckForUpdatePromise.abort()
setSilentCheckForUpdatePromise(undefined)
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [silentCheckForUpdateState])

useEffect(() => {
if (
silentCheckForUpdateState === SilentCheckForUpdateState.Failed ||
checkingForUpdateState === State.Failed
) {
setCheckForUpdateLocalState(CheckForUpdateLocalState.Failed)
}

if (silentCheckForUpdateState === SilentCheckForUpdateState.Loading) {
setCheckForUpdateLocalState(CheckForUpdateLocalState.SilentCheckLoading)
}

if (checkingForUpdateState === State.Loading) {
setCheckForUpdateLocalState(CheckForUpdateLocalState.Loading)
}

if (
silentCheckForUpdateState === SilentCheckForUpdateState.Loaded ||
checkingForUpdateState === State.Loaded
) {
setCheckForUpdateLocalState(CheckForUpdateLocalState.Loaded)
}
}, [silentCheckForUpdateState, checkingForUpdateState])
return {
checkForUpdateLocalState,
}
}
Loading