Commit e5423b4c authored by Kevin Wu's avatar Kevin Wu

Fix bug where New Tabs (chrome://newtab) at branch tail would duplicate when...

Fix bug where New Tabs (chrome://newtab) at branch tail would duplicate when (re)loading the workspace
parent f2f2753a
......@@ -8,7 +8,14 @@ const DOMAIN = require("../../../secrets.json")["domain"];
//idMap[chrome tab id] = continuum branch id
const idMap = [];
// flag used to temporarily disable tab creation listeners while workspace loading is in progress
let restoring = false;
chrome.tabs.onCreated.addListener(async tab => {
if (restoring) {
return;
}
if (tab.url === "chrome://history/") {
return;
}
......@@ -49,11 +56,13 @@ chrome.runtime.onMessage.addListener(async ({ message, ...payload }) => {
case MESSAGES.SELECT_WORKSPACE:
const tabs = await ext.selectWorkspace(payload);
restoring = true;
idMap.splice(0, idMap.length); // empty idMap without reassignment
await Promise.all(
tabs
.sort(({ timestamp: a, timestamp: b }) => b - a)
.reverse()
.map(
({ branchId, url }) =>
new Promise(resolve => {
......@@ -87,8 +96,12 @@ chrome.runtime.onMessage.addListener(async ({ message, ...payload }) => {
if (tabs.length === 0) {
chrome.windows.create({
url: DOMAIN,
top: 0,
left: 0,
});
}
restoring = false;
break;
default:
throw new Error("Invalid message: " + message);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment