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-1996] [FIX] [Backup] Backup in progress + device change, results with (incorrect) force update modal #1428

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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 { 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 }) => {

Check warning on line 17 in packages/app/src/update/actions/handle-device-detached/handle-device-detached.action.ts

View check run for this annotation

Codecov / codecov/patch

packages/app/src/update/actions/handle-device-detached/handle-device-detached.action.ts#L17

Added line #L17 was not covered by tests
const { update } = getState()

dispatch(setDeviceData(null))

Check warning on line 20 in packages/app/src/update/actions/handle-device-detached/handle-device-detached.action.ts

View check run for this annotation

Codecov / codecov/patch

packages/app/src/update/actions/handle-device-detached/handle-device-detached.action.ts#L20

Added line #L20 was not covered by tests

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