Skip to content

Commit

Permalink
fix: don't crash when backup user config does not exists (#1241)
Browse files Browse the repository at this point in the history
* fix: don't crash when backup user config does not exists

* feat: save-configuration-payload.ts

* fix: navigation after restoring config

* refactoring: remove unnecessary modifications
  • Loading branch information
ert78gb authored May 7, 2020
1 parent 53d54b0 commit dddfc10
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/uhk-web/src/app/store/effects/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class DeviceEffects {
mergeMap(() => {
const actions = [new HideSaveToKeyboardButton()];

if (state.device.hasBackupUserConfiguration) {
if (state.device.restoreUserConfiguration) {
actions.push(new RestoreUserConfigurationFromBackupSuccessAction());
this.router.navigate(['/']);
}
Expand Down
11 changes: 7 additions & 4 deletions packages/uhk-web/src/app/store/effects/user-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ export class UserConfigEffects {

} catch (err) {
this.logService.error('Eeprom user-config parse error:', err);
const userConfig = new UserConfiguration().fromJsonObject(data.backupConfiguration);

result.push(new HasBackupUserConfigurationAction(!!data.backupConfiguration));
result.push(new LoadUserConfigSuccessAction(userConfig));
if (data.backupConfiguration) {
const userConfig = new UserConfiguration().fromJsonObject(data.backupConfiguration);
result.push(new HasBackupUserConfigurationAction(true));
result.push(new LoadUserConfigSuccessAction(userConfig));
} else {
result.push(new HasBackupUserConfigurationAction(false));
}

newPageDestination = ['/device/restore-user-configuration'];
}
Expand Down
6 changes: 5 additions & 1 deletion packages/uhk-web/src/app/store/reducers/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface State {
log: Array<XtermLog>;
restoringUserConfiguration: boolean;
hasBackupUserConfiguration: boolean;
restoreUserConfiguration: boolean;
halvesInfo: HalvesInfo;
readingConfigSizes: boolean;
configSizes: ConfigSizesInfo;
Expand Down Expand Up @@ -52,6 +53,7 @@ export const initialState: State = {
log: [{ message: '', cssClass: XtermCssClass.standard }],
restoringUserConfiguration: false,
hasBackupUserConfiguration: false,
restoreUserConfiguration: false,
halvesInfo: { isLeftHalfConnected: true, areHalvesMerged: false },
readingConfigSizes: false,
configSizes: { userConfig: 32704, hardwareConfig: 64 }
Expand Down Expand Up @@ -206,12 +208,14 @@ export function reducer(state = initialState, action: Action): State {
case Device.ActionTypes.HasBackupUserConfiguration:
return {
...state,
restoreUserConfiguration: true,
hasBackupUserConfiguration: (action as Device.HasBackupUserConfigurationAction).payload
};

case Device.ActionTypes.RestoreConfigurationFromBackupSuccess:
return {
...state,
restoreUserConfiguration: false,
hasBackupUserConfiguration: false
};

Expand Down Expand Up @@ -260,7 +264,7 @@ export const getMissingDeviceState = (state: State): MissingDeviceState => {
export const getSaveToKeyboardState = (state: State) => state.saveToKeyboard;
export const xtermLog = (state: State) => state.log;
export const getHardwareModules = (state: State) => state.modules;
export const getHasBackupUserConfiguration = (state: State) => state.hasBackupUserConfiguration;
export const getHasBackupUserConfiguration = (state: State) => state.hasBackupUserConfiguration || state.restoreUserConfiguration;
export const getBackupUserConfigurationState = (state: State): RestoreConfigurationState => {
return {
restoringUserConfiguration: state.restoringUserConfiguration,
Expand Down

0 comments on commit dddfc10

Please sign in to comment.