Skip to content

Commit

Permalink
Fix for #44
Browse files Browse the repository at this point in the history
  • Loading branch information
mastef committed Apr 16, 2020
1 parent d85106e commit 9d27d12
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions lib/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,40 @@
var browser = browser || chrome;

async function createWindowWithTabs(tabs, isIncognito) {
var first = tabs.shift();

var pinnedIndex = 0;
var firstTab = tabs.shift();
var t = [];
for (var i = 0; i < tabs.length; i++) {
t.push(tabs[i].id);
};
var w = await browser.windows.create({ tabId: first.id, incognito: !!isIncognito });
await browser.tabs.update(first.id, { pinned: first.pinned });

var firstPinned = firstTab.pinned;
var w = await browser.windows.create({ tabId: firstTab.id, incognito: !!isIncognito });
if(firstPinned) {
await browser.tabs.update(w.tabs[0].id, { pinned: firstPinned });
pinnedIndex++;
}

if (t.length > 0) {
var tab = await browser.tabs.move(t, { windowId: w.id, index: -1 });
await browser.tabs.update(tab.id, { pinned: tab.pinned });
var i = 0;
for (var oldTabId of t) {
i++;
var oldTab = await browser.tabs.get(oldTabId);
var tabPinned = oldTab.pinned;
var movedTabs = [];
if(!tabPinned) {
movedTabs = await browser.tabs.move(oldTabId, { windowId: w.id, index: -1 });
}else{
movedTabs = await browser.tabs.move(oldTabId, { windowId: w.id, index: pinnedIndex++ });
}
if(movedTabs.length > 0) {
var newTab = movedTabs[0];
if(tabPinned) {
await browser.tabs.update(newTab.id, { pinned: tabPinned });
}
}
};
}
await browser.windows.update(w.id, { focused: true });
}
Expand Down

0 comments on commit 9d27d12

Please sign in to comment.