Skip to content

Commit c70b2db

Browse files
committed
Fix session import bug from json
1 parent 2f20f16 commit c70b2db

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

js/background.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,7 @@ var spaces = (() => {
701701
const sessions = spacesService.getAllSessions();
702702
const allSpaces = sessions
703703
.map(session => {
704-
return {
705-
sessionId: session.id,
706-
windowId: session.windowId,
707-
name: session.name,
708-
tabs: session.tabs,
709-
history: session.history,
710-
lastAccess: session.lastAccess,
711-
};
704+
return { sessionId: session.id, ...session };
712705
})
713706
.filter(session => {
714707
return session && session.tabs && session.tabs.length > 0;
@@ -854,12 +847,14 @@ var spaces = (() => {
854847
function handleRestoreFromBackup(_spaces, callback) {
855848
let existingSession;
856849
let performSave;
857-
let triggerCallback;
858850

859-
_spaces.forEach((space, index, spacesArray) => {
860-
existingSession = spacesService.getSessionByName(space.name);
851+
const promises = [];
852+
for (let i = 0; i < _spaces.length; i += 1) {
853+
const space = _spaces[i];
854+
existingSession = space.name
855+
? spacesService.getSessionByName(space.name)
856+
: false;
861857
performSave = true;
862-
triggerCallback = index === spacesArray.length - 1;
863858

864859
// if session with same name already exist, then prompt to override the existing session
865860
if (existingSession) {
@@ -873,18 +868,19 @@ var spaces = (() => {
873868
}
874869

875870
if (performSave) {
876-
spacesService.saveNewSession(
877-
space.name,
878-
space.tabs,
879-
false,
880-
() => {
881-
if (triggerCallback) callback(null);
882-
}
871+
promises.push(
872+
new Promise(resolve => {
873+
spacesService.saveNewSession(
874+
space.name,
875+
space.tabs,
876+
false,
877+
resolve
878+
);
879+
})
883880
);
884-
} else if (triggerCallback) {
885-
callback(null);
886881
}
887-
});
882+
}
883+
Promise.all(promises).then(callback);
888884
}
889885

890886
function handleImportNewSession(urlList, callback) {

0 commit comments

Comments
 (0)