@@ -33,7 +33,11 @@ async function migrateFromOldOrigin() {
3333 webgl : false ,
3434 } ,
3535 } ) ;
36- ipcMain . on ( 'origin_migration_complete' , ( e , success , sentSummary , storedSummary ) => {
36+ const onOriginMigrationComplete = ( e , success , sentSummary , storedSummary ) => {
37+ // we use once but we'll only get one of these events,
38+ // so remove the listener for the other one
39+ ipcMain . removeListener ( 'origin_migration_nodata' , onOriginMigrationNoData ) ;
40+
3741 if ( success ) {
3842 console . log ( "Origin migration completed successfully!" ) ;
3943 } else {
@@ -43,12 +47,18 @@ async function migrateFromOldOrigin() {
4347 console . error ( "Data stored" , storedSummary ) ;
4448 migrateWindow . close ( ) ;
4549 resolve ( ) ;
46- } ) ;
47- ipcMain . on ( 'origin_migration_nodata' , ( e ) => {
50+ } ;
51+ const onOriginMigrationNoData = ( e , success , sentSummary , storedSummary ) => {
52+ ipcMain . removeListener ( 'origin_migration_complete' , onOriginMigrationComplete ) ;
53+
4854 console . log ( "No session to migrate from old origin" ) ;
4955 migrateWindow . close ( ) ;
5056 resolve ( ) ;
51- } ) ;
57+ } ;
58+
59+ ipcMain . once ( 'origin_migration_complete' , onOriginMigrationComplete ) ;
60+ ipcMain . once ( 'origin_migration_nodata' , onOriginMigrationNoData ) ;
61+
5262 // Normalise the path because in the distribution, __dirname will be inside the
5363 // electron asar.
5464 const sourcePagePath = path . normalize ( __dirname + '/../../origin_migrator/source.html' ) ;
0 commit comments