Skip to content

Commit

Permalink
pinned tabs are saved and re-opened
Browse files Browse the repository at this point in the history
  • Loading branch information
hharnisc committed Jan 1, 2017
1 parent 85f3b8e commit e003496
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,26 @@ const closeTabsWithIds = (tabIds) => new Promise((resolve, reject) => {
chrome.tabs.remove(tabIds, () => resolve());
});

const createTabs = (urls) => new Promise((resolve) => {
const createWindow = (urls) => new Promise((resolve) => {
chrome.windows.create({
url: urls,
}, (window) => resolve(window));
});

const createTabs = (tabs) =>
createWindow(tabs.map((tab) => tab.url ? tab.url : tab))
.then(window => tabs.map((tab, i) => {
return new Promise((resolve) => {
if (tab.pinned) {
chrome.tabs.update(window.tabs[i].id, {pinned: true}, () => resolve());
} else {
resolve();
}
});
}))
.then(tabPromises => Promise.all(tabPromises));


const createOpenButton = (id) => {
const openButton = document.createElement('button');
const buttonText = document.createTextNode('open');
Expand Down Expand Up @@ -169,11 +183,14 @@ const handleSaveClick = (e, tabGroups, saveSelected) => {
}
return getAllTabs();
})
.then((tabs) => tabs.map((tab) => tab.url))
.then((urls) => {
.then((tabs) => tabs.map((tab) => ({
url: tab.url,
pinned: tab.pinned,
})))
.then((tabs) => {
addTabGroup({
name: getTabGroupName(),
tabs: urls,
tabs,
},
tabGroups
);
Expand All @@ -182,7 +199,7 @@ const handleSaveClick = (e, tabGroups, saveSelected) => {
hitType: 'event',
eventCategory: 'TabGroup',
eventAction: 'save',
eventValue: urls.length,
eventValue: tabs.length,
});
})
.catch((err) => {
Expand All @@ -206,7 +223,10 @@ const handleSaveAndCloseClick = (e, tabGroups, saveSelected) => {
.then((tabs) => {
addTabGroup({
name: getTabGroupName(),
tabs: tabs.map((tab) => tab.url),
tabs: tabs.map((tab) => ({
url: tab.url,
pinned: tab.pinned,
})),
},
tabGroups
);
Expand Down

0 comments on commit e003496

Please sign in to comment.