From 6464bfe850c83a2c402434bfe411011fafa6806f Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 19 Sep 2019 17:41:08 +0100 Subject: [PATCH] Remove the other listener when one fires --- electron_app/src/originMigrator.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/electron_app/src/originMigrator.js b/electron_app/src/originMigrator.js index bc6acfab..0344ede7 100644 --- a/electron_app/src/originMigrator.js +++ b/electron_app/src/originMigrator.js @@ -33,7 +33,11 @@ async function migrateFromOldOrigin() { webgl: false, }, }); - ipcMain.once('origin_migration_complete', (e, success, sentSummary, storedSummary) => { + const onOriginMigrationComplete = (e, success, sentSummary, storedSummary) => { + // we use once but we'll only get once of these events, + // so remove the listener for the other one + ipcMain.removeListener('origin_migration_nodata', onOriginMigrationNoData); + if (success) { console.log("Origin migration completed successfully!"); } else { @@ -43,12 +47,18 @@ async function migrateFromOldOrigin() { console.error("Data stored", storedSummary); migrateWindow.close(); resolve(); - }); - ipcMain.once('origin_migration_nodata', (e) => { + }; + const onOriginMigrationNoData = (e, success, sentSummary, storedSummary) => { + ipcMain.removeListener('origin_migration_complete', onOriginMigrationComplete); + console.log("No session to migrate from old origin"); migrateWindow.close(); resolve(); - }); + }; + + ipcMain.once('origin_migration_complete', onOriginMigrationComplete); + ipcMain.once('origin_migration_nodata', onOriginMigrationNoData); + // Normalise the path because in the distribution, __dirname will be inside the // electron asar. const sourcePagePath = path.normalize(__dirname + '/../../origin_migrator/source.html');