@@ -12,9 +12,11 @@ import _ from 'lodash';
1212import { checkMasterPassword , showQuickSearch } from '../../../static/js/Dialogs/index' ;
1313import { pgHandleItemError } from '../../../static/js/utils' ;
1414import { send_heartbeat , stop_heartbeat } from './heartbeat' ;
15- import getApiInstance from '../../../static/js/api_instance' ;
15+ import getApiInstance , { parseApiError } from '../../../static/js/api_instance' ;
1616import usePreferences , { setupPreferenceBroadcast } from '../../../preferences/static/js/store' ;
1717import checkNodeVisibility from '../../../static/js/check_node_visibility' ;
18+ import * as showQueryTool from '../../../tools/sqleditor/static/js/show_query_tool' ;
19+ import { getRandomInt } from 'sources/utils' ;
1820
1921define ( 'pgadmin.browser' , [
2022 'sources/gettext' , 'sources/url_for' , 'sources/pgadmin' ,
@@ -206,6 +208,12 @@ define('pgadmin.browser', [
206208 uiloaded : function ( ) {
207209 this . set_master_password ( '' ) ;
208210 this . check_version_update ( ) ;
211+ const prefStore = usePreferences . getState ( ) ;
212+ let save_the_workspace = prefStore . getPreferencesForModule ( 'misc' ) . save_app_state ;
213+ if ( save_the_workspace ) {
214+ this . restore_pgadmin_state ( ) ;
215+ pgBrowser . docker . default_workspace . focus ( ) ;
216+ }
209217 } ,
210218 check_corrupted_db_file : function ( ) {
211219 getApiInstance ( ) . get (
@@ -291,6 +299,42 @@ define('pgadmin.browser', [
291299 } ) ;
292300 } ,
293301
302+ restore_pgadmin_state : function ( ) {
303+ getApiInstance ( { 'Content-Encoding' : 'gzip' } ) . get (
304+ url_for ( 'settings.get_application_state' )
305+ ) . then ( ( res ) => {
306+ if ( res . data . success && res . data . data . result . length > 0 ) {
307+ _ . each ( res . data . data . result , function ( toolState ) {
308+ let toolNme = toolState . tool_name ;
309+ let toolDataId = `${ toolNme } -${ getRandomInt ( 1 , 9999999 ) } ` ;
310+ let connectionInfo = toolState . connection_info ;
311+ localStorage . setItem ( toolDataId , toolState . tool_data ) ;
312+
313+ if ( toolNme == 'sqleditor' ) {
314+ showQueryTool . relaunchSqlTool ( connectionInfo , toolDataId ) ;
315+ } else if ( toolNme == 'psql' ) {
316+ pgAdmin . Tools . Psql . openPsqlTool ( null , null , connectionInfo ) ;
317+ } else if ( toolNme == 'ERD' ) {
318+ pgAdmin . Tools . ERD . showErdTool ( null , null , false , connectionInfo , toolDataId ) ;
319+ } else if ( toolNme == 'schema_diff' ) {
320+ pgAdmin . Tools . SchemaDiff . launchSchemaDiff ( toolDataId ) ;
321+ }
322+ } ) ;
323+
324+ // call clear application state data.
325+ try {
326+ getApiInstance ( ) . delete ( url_for ( 'settings.delete_application_state' ) , { } ) ;
327+ } catch ( error ) {
328+ console . error ( error ) ;
329+ pgAdmin . Browser . notifier . error ( gettext ( 'Failed to remove query data.' ) + parseApiError ( error ) ) ;
330+ }
331+ }
332+ } ) . catch ( function ( error ) {
333+ pgAdmin . Browser . notifier . pgRespErrorNotify ( error ) ;
334+ getApiInstance ( ) . delete ( url_for ( 'settings.delete_application_state' ) , { } ) ;
335+ } ) ;
336+ } ,
337+
294338 bind_beforeunload : function ( ) {
295339 window . addEventListener ( 'beforeunload' , function ( e ) {
296340 /* Can open you in new tab */
0 commit comments