77 :showMaximiseIcon =" false"
88 :state.sync =" layoutState"
99 @state =" updateLayoutState"
10- @creation-error =" reset "
10+ @creation-error =" creationError "
1111 :headerHeight =" 18"
12+ :key =" triggerUiRestart"
1213 >
1314 <gl-col >
1415 <gl-row >
@@ -97,7 +98,9 @@ import Search from "@/components/Search";
9798
9899import getNextName from " @/application/utils/get-next-name" ;
99100import constants from " @/application/constants" ;
101+
100102import * as GoldenLayout from " golden-layout" ;
103+ import { ipcRenderer } from " electron" ;
101104
102105export default {
103106 name: " app" ,
@@ -127,7 +130,8 @@ export default {
127130
128131 showUi: true ,
129132 mouseTimer: null ,
130- cursor: " none"
133+ cursor: " none" ,
134+ triggerUiRestart: 0
131135 };
132136 },
133137
@@ -153,21 +157,19 @@ export default {
153157 },
154158
155159 created () {
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-
167160 const layoutState = window .localStorage .getItem (constants .LAYOUT_STATE_KEY );
168161 if (layoutState) {
169- this .layoutState = JSON .parse (layoutState);
162+ try {
163+ this .layoutState = JSON .parse (layoutState);
164+ } catch (e) {
165+ this .creationError ();
166+ }
170167 }
168+
169+ ipcRenderer .on (" reset-layout" , () => {
170+ this .resetGoldenLayoutState ();
171+ this .restartLayout ();
172+ });
171173 },
172174
173175 async mounted () {
@@ -328,8 +330,7 @@ export default {
328330 );
329331 },
330332
331- async reset () {
332- console .log (" golden layout creation error" );
333+ async creationError () {
333334 const localStorageKeys = Object .keys (window .localStorage );
334335
335336 const nextKey = await getNextName (
@@ -338,14 +339,27 @@ export default {
338339 );
339340 window .localStorage .setItem (nextKey, JSON .stringify (this .layoutState ));
340341
341- window .localStorage .removeItem (constants .LAYOUT_STATE_KEY );
342-
343- window .localStorage .setItem (
344- constants .LAYOUT_LOAD_ERROR_KEY ,
345- JSON .stringify (true )
342+ console .warn (
343+ " Layout could not be restored. Default layout loaded and old layout was saved to a backup local storage key"
346344 );
347345
348- window .location .reload ();
346+ this .resetGoldenLayoutState ();
347+ this .restartLayout ();
348+ },
349+
350+ resetGoldenLayoutState () {
351+ window .localStorage .removeItem (constants .LAYOUT_STATE_KEY );
352+ this .layoutState = undefined ;
353+ },
354+
355+ /**
356+ * @description Restarts Golden Layout.
357+ * We increment a variable which is assigned to the key of the root Golden Layout element.
358+ * If the key is updated, the element is forced to dismount and mount again.
359+ */
360+ restartLayout () {
361+ this .resetGoldenLayoutState ();
362+ this .triggerUiRestart ++ ;
349363 }
350364 },
351365
0 commit comments