Skip to content

Commit

Permalink
feat(loopbackRpcIssuer): localStorage integration for configs
Browse files Browse the repository at this point in the history
Closes #103

Signed-off-by: Lukas Mertens <git@lukas-mertens.de>

commit-id:110f685c
  • Loading branch information
lukas-mertens committed Apr 24, 2024
1 parent 0ceae2c commit 047b10f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/modules/evbc/rpc/loopbackRpcIssuer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2024 Pionix GmbH and Contributors to EVerest
import {LOOPBACK_WAIT_MS} from "@/modules/evbc/connection";
import {EverestConfigList, EverestInterfaceDefinitionList, EverestModuleDefinitionList} from "@/modules/evbc";
import {
EverestConfig,
EverestConfigList,
EverestInterfaceDefinitionList,
EverestModuleDefinitionList
} from "@/modules/evbc";
import SampleManifestList from "@/modules/evbc/sample_module_info";
import SampleInterfaceList from "@/modules/evbc/sample_interfaces_list";
import SampleConfigList from "@/modules/evbc/sample_config_list";
Expand Down Expand Up @@ -34,10 +39,23 @@ export class LoopbackRpcIssuer extends RpcIssuer {
}

public async get_configs(): Promise<EverestConfigList> {
return this.random_wait_resolve<EverestConfigList>(SampleConfigList);
const configs = LoopbackRpcIssuer.getConfigsFromLocalStorageOrDefault();
return this.random_wait_resolve<EverestConfigList>(configs);
}

public async save_config(): Promise<void> {
private static getConfigsFromLocalStorageOrDefault() {
const configsString = localStorage.getItem("configs");
if (configsString) {
return Object.assign({}, SampleConfigList, JSON.parse(configsString));
} else {
return SampleConfigList;
}
}

public async save_config(params: {name: string, config: EverestConfig}): Promise<void> {
const configs = LoopbackRpcIssuer.getConfigsFromLocalStorageOrDefault();
configs[params.name] = params.config;
localStorage.setItem("configs", JSON.stringify(configs));
return this.random_wait_resolve();
}

Expand Down

0 comments on commit 047b10f

Please sign in to comment.