Skip to content

Commit

Permalink
[CP-1996] [FIX] [Backup] Backup in progress + device change, results …
Browse files Browse the repository at this point in the history
…with (incorrect) force update modal (#1428)
  • Loading branch information
patryk-sierzega authored Oct 10, 2023
1 parent 3b470b8 commit edaa580
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
6 changes: 3 additions & 3 deletions packages/app/src/device/actions/base.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
import { DeviceEvent } from "App/device/constants"
import { GetPhoneLockTimeResponseBody } from "App/device/types/mudita-os"

export const setDeviceData = createAction<
Partial<PureDeviceData | HarmonyDeviceData>
>(DeviceEvent.SetData)
export const setDeviceData = createAction<Partial<
PureDeviceData | HarmonyDeviceData
> | null>(DeviceEvent.SetData)

export const setLockTime = createAction<
GetPhoneLockTimeResponseBody | undefined
Expand Down
29 changes: 23 additions & 6 deletions packages/app/src/device/reducers/device.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const deviceReducer = createReducer<DeviceState>(
initialState,
(builder) => {
builder

// SetInitState functionality
.addCase(DeviceEvent.SetInitState, () => {
return {
Expand All @@ -76,6 +77,7 @@ export const deviceReducer = createReducer<DeviceState>(
externalUsageDevice: null,
}
})

.addCase(
fulfilledAction(DeviceEvent.Connected),
(state, action: ConnectedFulfilledAction) => {
Expand All @@ -91,6 +93,7 @@ export const deviceReducer = createReducer<DeviceState>(
}
}
)

.addCase(
rejectedAction(DeviceEvent.Connected),
(state, action: ConnectedRejectedAction) => {
Expand All @@ -106,6 +109,7 @@ export const deviceReducer = createReducer<DeviceState>(
}
}
)

.addCase(pendingAction(DeviceEvent.Disconnected), (state) => {
return {
...state,
Expand All @@ -114,13 +118,15 @@ export const deviceReducer = createReducer<DeviceState>(
externalUsageDevice: null,
}
})

.addCase(fulfilledAction(DeviceEvent.Disconnected), (state) => {
return {
...state,
state: ConnectionState.Empty,
error: null,
}
})

.addCase(
fulfilledAction(DeviceEvent.SetConnectionState),
(state, action: SetConnectionStateAction) => {
Expand All @@ -147,6 +153,7 @@ export const deviceReducer = createReducer<DeviceState>(
},
}
})

.addCase(unlockedDevice, (state) => {
return {
...state,
Expand All @@ -157,6 +164,7 @@ export const deviceReducer = createReducer<DeviceState>(
error: null,
}
})

.addCase(
DeviceEvent.SetLockTime,
(state, action: SetPhoneLockTimeAction) => {
Expand All @@ -173,12 +181,17 @@ export const deviceReducer = createReducer<DeviceState>(

// Passing data from the connecting device to state
.addCase(DeviceEvent.SetData, (state, action: SetDeviceDataAction) => {
const newData =
action.payload === null
? null
: {
...(state.data ?? {}),
...action.payload,
}

return {
...state,
data: {
...(state.data ?? {}),
...action.payload,
},
data: newData,
error: null,
}
})
Expand Down Expand Up @@ -228,13 +241,15 @@ export const deviceReducer = createReducer<DeviceState>(
}
}
)

// Updates loading data state
.addCase(pendingAction(DeviceEvent.Loading), (state) => {
return {
...state,
state: ConnectionState.Loading,
}
})

.addCase(fulfilledAction(DeviceEvent.Loading), (state) => {
return {
...state,
Expand All @@ -246,6 +261,7 @@ export const deviceReducer = createReducer<DeviceState>(
error: null,
}
})

.addCase(
rejectedAction(DeviceEvent.Loading),
(state, action: LoadDataRejectAction) => {
Expand Down Expand Up @@ -274,6 +290,7 @@ export const deviceReducer = createReducer<DeviceState>(
}
}
)

.addCase(
rejectedAction(DeviceEvent.LoadStorageInfo),
(state, action: LoadStorageInfoRejectedAction) => {
Expand All @@ -284,17 +301,17 @@ export const deviceReducer = createReducer<DeviceState>(
}
}
)

.addCase(setOnboardingStatus, (state, action) => {
state.status.onboardingFinished = action.payload
})

.addCase(setCriticalBatteryLevel, (state, action) => {
state.status.criticalBatteryLevel = action.payload
})

.addCase(setExternalUsageDevice, (state, action) => {
state.externalUsageDevice = action.payload
})

.addCase(setRestarting, (state, action) => {
state.status.restarting = action.payload
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { checkForUpdate } from "App/update/actions/check-for-update/check-for-up
import { CheckForUpdateMode, UpdateOsEvent } from "App/update/constants"
import { versionFormatter } from "App/update/helpers"
import { ReduxRootState, RootState } from "App/__deprecated__/renderer/store"
import { ConnectionState } from "App/device/constants"

export const checkForForceUpdateNeed = createAsyncThunk<boolean, void>(
UpdateOsEvent.CheckForForceUpdate,
Expand All @@ -21,10 +20,6 @@ export const checkForForceUpdateNeed = createAsyncThunk<boolean, void>(

const { device, settings } = getState() as RootState & ReduxRootState

if (device.state === ConnectionState.Loading) {
return false
}

const osVersion = versionFormatter(device.data?.osVersion ?? "")
const lowestSupportedProductVersion =
settings.lowestSupportedVersions?.lowestSupportedProductVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
osUpdateAlreadyDownloadedCheck,
} from "App/update/requests"
import { ReduxRootState, RootState } from "App/__deprecated__/renderer/store"
import { ConnectionState } from "App/device/constants"

interface Params {
deviceType: DeviceType
Expand Down Expand Up @@ -50,12 +49,6 @@ export const checkForUpdate = createAsyncThunk<Result, Params>(
async ({ deviceType }, { rejectWithValue, getState }) => {
const state = getState() as RootState & ReduxRootState

if (state.device.state === ConnectionState.Loading) {
return {
allReleases: [],
availableReleasesForUpdate: [],
}
}
const osVersion = versionFormatter(state.device.data?.osVersion || "")

const product =
Expand Down Expand Up @@ -112,7 +105,6 @@ export const checkForUpdate = createAsyncThunk<Result, Params>(
const mandatoryReleasesToInstall = await getReleasesByVersions({
product,
versions: mandatoryVersionsToInstall,
deviceSerialNumber: state.device.data?.serialNumber,
})

if (!mandatoryReleasesToInstall.ok || !mandatoryReleasesToInstall.data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import { setExternalUsageDeviceRequest } from "App/analytic-data-tracker/request
import { DownloadState, UpdateOsEvent } from "App/update/constants"
import { cancelOsDownload } from "App/update/requests"
import { ReduxRootState } from "App/__deprecated__/renderer/store"
import { setDeviceData } from "App/device/actions/base.action"

export const handleDeviceDetached = createAsyncThunk<
void,
void,
{ state: ReduxRootState }
>(UpdateOsEvent.HandleDeviceDetached, async (_, { getState }) => {
>(UpdateOsEvent.HandleDeviceDetached, async (_, { dispatch, getState }) => {
const { update } = getState()

dispatch(setDeviceData(null))

if (update.downloadState === DownloadState.Loading) {
cancelOsDownload(true)
}
Expand Down

0 comments on commit edaa580

Please sign in to comment.