77 :showMaximiseIcon =" false"
88 :state.sync =" layoutState"
99 @state =" updateLayoutState"
10+ @creation-error =" reset"
1011 :headerHeight =" 18"
1112 >
1213 <gl-col >
7071 <gl-component title =" Preview" :closable =" false" >
7172 <Preview />
7273 </gl-component >
73-
74- <gl-component title =" Swap" :closable =" false" >
75- <ABSwap />
76- </gl-component >
7774 </gl-stack >
7875 </gl-row >
7976 </gl-col >
8683
8784<script >
8885import Preview from " @/components/Preview" ;
89- import ABSwap from " @/components/ABSwap" ;
9086import Groups from " @/components/Groups" ;
9187import Gallery from " @/components/Gallery" ;
9288import InputConfig from " @/components/InputConfig" ;
@@ -99,14 +95,15 @@ import ModuleInspector from "@/components/ModuleInspector";
9995import InfoView from " @/components/InfoView" ;
10096import Search from " @/components/Search" ;
10197
98+ import getNextName from " @/application/utils/get-next-name" ;
99+ import constants from " @/application/constants" ;
102100import * as GoldenLayout from " golden-layout" ;
103101
104102export default {
105103 name: " app" ,
106104
107105 components: {
108106 Preview,
109- ABSwap,
110107 Groups,
111108 Gallery,
112109 InputConfig,
@@ -156,7 +153,18 @@ export default {
156153 },
157154
158155 created () {
159- const layoutState = window .localStorage .getItem (" layoutState" );
156+ const layoutErroredLastLoad = window .localStorage .getItem (
157+ constants .LAYOUT_LOAD_ERROR_KEY
158+ );
159+
160+ if (layoutErroredLastLoad) {
161+ console .warn (
162+ " Layout could not be restored. Default layout loaded and old layout was saved to a backup local storage key"
163+ );
164+ window .localStorage .removeItem (constants .LAYOUT_LOAD_ERROR_KEY );
165+ }
166+
167+ const layoutState = window .localStorage .getItem (constants .LAYOUT_STATE_KEY );
160168 if (layoutState) {
161169 this .layoutState = JSON .parse (layoutState);
162170 }
@@ -306,7 +314,7 @@ export default {
306314 /**
307315 * @description Called when <golden-layout /> updates its state.
308316 * Unminifies config, purges dynamically added panels, minifies and saves to
309- * localStorage key "layoutState" .
317+ * localStorage key `constants.LAYOUT_STATE_KEY` .
310318 *
311319 * @param {GoldenLayout config} value
312320 */
@@ -315,9 +323,29 @@ export default {
315323 const cleanedConfig = this .purgeDynamicPanels (config);
316324
317325 window .localStorage .setItem (
318- " layoutState " ,
326+ constants . LAYOUT_STATE_KEY ,
319327 JSON .stringify (GoldenLayout .minifyConfig (cleanedConfig))
320328 );
329+ },
330+
331+ async reset () {
332+ console .log (" golden layout creation error" );
333+ const localStorageKeys = Object .keys (window .localStorage );
334+
335+ const nextKey = await getNextName (
336+ constants .LAYOUT_STATE_KEY ,
337+ localStorageKeys
338+ );
339+ window .localStorage .setItem (nextKey, JSON .stringify (this .layoutState ));
340+
341+ window .localStorage .removeItem (constants .LAYOUT_STATE_KEY );
342+
343+ window .localStorage .setItem (
344+ constants .LAYOUT_LOAD_ERROR_KEY ,
345+ JSON .stringify (true )
346+ );
347+
348+ window .location .reload ();
321349 }
322350 },
323351
0 commit comments