@@ -94,36 +94,48 @@ user.on('change:language', function(md, lang) {
9494app . serverConfigs = new ServerConfigsCl ( ) ;
9595app . serverConfigs . fetch ( ) . done ( ( ) => {
9696 var oldConfig ,
97- defaultConfig ;
97+ defaultConfig ,
98+ defaultConfigFlat ;
9899
99100 if ( ! app . serverConfigs . getActive ( ) ) {
100101 defaultConfig = app . serverConfigs . create ( {
101102 name : polyglot . t ( 'serverConnectModal.defaultServerName' ) ,
102103 default : true
103- } )
104+ } ) ;
105+ defaultConfigFlat = defaultConfig . toJSON ( ) ;
104106
105107 // migrate any existing connection from the
106108 // old single config set-up (_serverConfig-1)
107109 if ( oldConfig = localStorage [ '_serverConfig-1' ] ) {
108110 oldConfig = JSON . parse ( oldConfig ) ;
109111
110- app . serverConfigs . setActive (
111- app . serverConfigs . create (
112- __ . extend (
113- { } ,
114- __ . omit ( oldConfig , [ 'local_username' , 'local_password' , 'id' ] ) ,
115- { name : polyglot . t ( 'serverConnectModal.portedConnectionName' ) }
116- )
117- ) . id
118- ) ;
119-
120- if ( oldConfig . local_username && oldConfig . local_password ) {
121- defaultConfig . save ( {
122- local_username : oldConfig . local_username ,
123- local_password : oldConfig . local_password
124- } ) ;
112+ // don't create a ported connection if it's the same as the default one
113+ if (
114+ oldConfig . server_ip +
115+ oldConfig . rest_api_port +
116+ oldConfig . api_socket_port +
117+ oldConfig . SSL !==
118+ defaultConfig . get ( 'server_ip' ) +
119+ defaultConfig . get ( 'rest_api_port' ) +
120+ defaultConfig . get ( 'api_socket_port' ) +
121+ defaultConfig . get ( 'SSL' )
122+ ) {
123+ app . serverConfigs . setActive (
124+ app . serverConfigs . create (
125+ __ . extend (
126+ { } ,
127+ __ . omit ( oldConfig , [ 'local_username' , 'local_password' , 'id' ] ) ,
128+ { name : polyglot . t ( 'serverConnectModal.portedConnectionName' ) }
129+ )
130+ ) . id
131+ ) ;
125132 }
126133
134+ defaultConfig . save ( {
135+ username : oldConfig . username ,
136+ password : oldConfig . password
137+ } ) ;
138+
127139 localStorage . removeItem ( '_serverConfig-1' ) ;
128140 } else {
129141 app . serverConfigs . setActive ( defaultConfig . id ) ;
@@ -455,7 +467,7 @@ app.connectHeartbeatSocket();
455467app . serverConnectModal = new ServerConnectModal ( ) . render ( ) ;
456468app . serverConnectModal . on ( 'connected' , ( ) => {
457469 if ( profileLoaded ) {
458- // If we've already loaded called loadProfile() and then, we connect
470+ // If we've already called loadProfile() and then, we connect
459471 // to a new server (or reconnect to the same server) we'll reload the
460472 // app since some of the "global" components (Router, PageNav,
461473 // SocketView...) were not designed to handle a new connection.
0 commit comments