Cleanup configuration loading a bit

- Move configuration hash clearing to RESET
- Dispatch STOP_UPDATES and RESET actions from LOAD_CONFIGURATION action
- Make exception handling simpler
This commit is contained in:
James Lyne 2021-09-08 14:35:44 +01:00
parent 80a60010a3
commit 1b9a3e4f1a
4 changed files with 13 additions and 29 deletions

View File

@ -74,8 +74,6 @@ export default defineComponent({
showSplash(!loadingAttempts.value); showSplash(!loadingAttempts.value);
loading.value = true; loading.value = true;
await store.dispatch(ActionTypes.STOP_UPDATES, undefined);
store.commit(MutationTypes.RESET, undefined);
await store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined); await store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined);
await store.dispatch(ActionTypes.START_UPDATES, undefined); await store.dispatch(ActionTypes.START_UPDATES, undefined);
@ -89,23 +87,15 @@ export default defineComponent({
} }
}); });
} catch(e: any) { } catch(e: any) {
//Request was aborted, probably because another server was selected before the request finished. Don't retry // Don't retry if request was aborted or logging in is required
if(e instanceof DOMException && e.name === 'AbortError') { if(!(e instanceof DOMException && e.name === 'AbortError') && !loginRequired.value) {
return;
}
//Logging in is required
if(loginRequired.value) {
return;
}
//Any other errors
const error = `Failed to load server configuration for '${store.state.currentServer!.id}'`; const error = `Failed to load server configuration for '${store.state.currentServer!.id}'`;
console.error(`${error}:`, e); console.error(`${error}:`, e);
showSplashError(`${error}\n${e}`, false, ++loadingAttempts.value); showSplashError(`${error}\n${e}`, false, ++loadingAttempts.value);
clearTimeout(loadingTimeout); clearTimeout(loadingTimeout);
loadingTimeout = setTimeout(() => loadConfiguration(), 1000); loadingTimeout = setTimeout(() => loadConfiguration(), 1000);
}
} finally { } finally {
loading.value = false; loading.value = false;
} }
@ -212,7 +202,7 @@ export default defineComponent({
} else { } else {
store.commit(MutationTypes.HIDE_UI_MODAL, 'login'); store.commit(MutationTypes.HIDE_UI_MODAL, 'login');
} }
}) });
onMounted(() => loadConfiguration()); onMounted(() => loadConfiguration());
onBeforeUnmount(() => { onBeforeUnmount(() => {

View File

@ -85,9 +85,9 @@ export interface Actions {
} }
export const actions: ActionTree<State, State> & Actions = { export const actions: ActionTree<State, State> & Actions = {
async [ActionTypes.LOAD_CONFIGURATION]({commit, state}): Promise<void> { async [ActionTypes.LOAD_CONFIGURATION]({commit, state, dispatch}): Promise<void> {
//Clear any existing has to avoid triggering a second config load, after this load changes the hash await dispatch(ActionTypes.STOP_UPDATES, undefined);
commit(MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH, undefined); commit(MutationTypes.RESET, undefined);
if(!state.currentServer) { if(!state.currentServer) {
console.warn('No current server'); console.warn('No current server');

View File

@ -19,7 +19,6 @@ export enum MutationTypes {
SET_SERVER_CONFIGURATION = 'setServerConfiguration', SET_SERVER_CONFIGURATION = 'setServerConfiguration',
SET_SERVER_CONFIGURATION_HASH = 'setServerConfigurationHash', SET_SERVER_CONFIGURATION_HASH = 'setServerConfigurationHash',
CLEAR_SERVER_CONFIGURATION_HASH = 'clearServerConfigurationHash',
SET_SERVER_MESSAGES = 'setServerMessages', SET_SERVER_MESSAGES = 'setServerMessages',
SET_WORLDS = 'setWorlds', SET_WORLDS = 'setWorlds',
SET_COMPONENTS = 'setComponents', SET_COMPONENTS = 'setComponents',

View File

@ -53,7 +53,6 @@ export type Mutations<S = State> = {
[MutationTypes.INIT](state: S, config: LiveAtlasGlobalConfig): void [MutationTypes.INIT](state: S, config: LiveAtlasGlobalConfig): void
[MutationTypes.SET_SERVER_CONFIGURATION](state: S, config: LiveAtlasServerConfig): void [MutationTypes.SET_SERVER_CONFIGURATION](state: S, config: LiveAtlasServerConfig): void
[MutationTypes.SET_SERVER_CONFIGURATION_HASH](state: S, hash: number): void [MutationTypes.SET_SERVER_CONFIGURATION_HASH](state: S, hash: number): void
[MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH](state: S): void
[MutationTypes.SET_SERVER_MESSAGES](state: S, messages: LiveAtlasServerMessageConfig): void [MutationTypes.SET_SERVER_MESSAGES](state: S, messages: LiveAtlasServerMessageConfig): void
[MutationTypes.SET_WORLDS](state: S, worlds: Array<LiveAtlasWorldDefinition>): void [MutationTypes.SET_WORLDS](state: S, worlds: Array<LiveAtlasWorldDefinition>): void
[MutationTypes.SET_COMPONENTS](state: S, components: LiveAtlasPartialComponentConfig | LiveAtlasComponentConfig): void [MutationTypes.SET_COMPONENTS](state: S, components: LiveAtlasPartialComponentConfig | LiveAtlasComponentConfig): void
@ -188,11 +187,6 @@ export const mutations: MutationTree<State> & Mutations = {
state.configurationHash = hash; state.configurationHash = hash;
}, },
// Sets configuration hash
[MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH](state: State) {
state.configurationHash = undefined;
},
// Sets messages from the initial config fetch // Sets messages from the initial config fetch
[MutationTypes.SET_SERVER_MESSAGES](state: State, messages: LiveAtlasServerMessageConfig) { [MutationTypes.SET_SERVER_MESSAGES](state: State, messages: LiveAtlasServerMessageConfig) {
state.messages = Object.assign(state.messages, messages); state.messages = Object.assign(state.messages, messages);
@ -650,6 +644,7 @@ export const mutations: MutationTree<State> & Mutations = {
state.currentWorldState.raining = false; state.currentWorldState.raining = false;
state.currentWorldState.thundering = false; state.currentWorldState.thundering = false;
state.configurationHash = undefined;
state.configuration.title = ''; state.configuration.title = '';
state.components.markers.showLabels= false; state.components.markers.showLabels= false;