Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbnuqw committed Dec 30, 2019
2 parents b625a37 + 2e35b5a commit 904f251
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
11 changes: 9 additions & 2 deletions addon/actions/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Actions from '../actions.js'
import { TABS_PANEL } from '../defaults.js'
import { DEFAULT_TABS_PANEL } from '../defaults.js'
import { DEFAULT_CTX } from '../defaults.js'
import { DEFAULT_CTX_ID } from '../defaults.js'

const MIN_SNAP_INTERVAL = 5000

Expand Down Expand Up @@ -138,12 +139,18 @@ async function openSnapshotWindow(snapshot, winId) {
if (!winInfo) return

let containers = snapshot.containersById
let pinnedTabs = []
let tabs = []

for (let panel of winInfo.panels) {
tabs = tabs.concat(panel.tabs)
for (let tab of panel.tabs) {
if (tab.pinned) pinnedTabs.push(tab)
else tabs.push(tab)
}
}

tabs = pinnedTabs.concat(tabs)

let tabsInfo = []
for (let tab of tabs) {
tabsInfo.push({ lvl: tab.lvl, panelId: tab.panel })
Expand All @@ -169,7 +176,7 @@ async function openSnapshotWindow(snapshot, winId) {
cookieStoreId: ctrId,
}

if (!tab.pinned && (!ctrId || ctrId.endsWith('-default'))) {
if (!tab.pinned && ctrId === DEFAULT_CTX_ID && !tab.url.startsWith('about')) {
conf.discarded = true
conf.title = tab.title
}
Expand Down
2 changes: 1 addition & 1 deletion addon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"author": "mbnuqw",
"name": "__MSG_ExtName__",
"version": "4.0.0",
"version": "4.0.1",
"default_locale": "en",
"description": "__MSG_ExtDesc__",
"homepage_url": "https://github.com/mbnuqw/sidebery",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sidebery",
"version": "4.0.0",
"version": "4.0.1",
"description": "Manage your tabs and bookmarks in sidebar",
"main": "index.js",
"scripts": {
Expand Down
62 changes: 34 additions & 28 deletions src/sidebar/actions/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ async function loadTabsFromGlobalStorage() {
if (old.tabsTrees) return await this.actions._old_loadTabs(tabs)
}

if (tabs[0].url.startsWith('about:blank#tabsdata')) {
return await this.actions.loadTabsFromInlineData(tabs)
let dataTabIndex = tabs.findIndex(t => t.url.startsWith('about:blank#tabsdata'))
if (dataTabIndex !== -1) {
return await this.actions.loadTabsFromInlineData(tabs, dataTabIndex)
}

let activePanel = this.state.panels[this.state.panelIndex] || this.state.panels[1]
Expand All @@ -45,7 +46,6 @@ async function loadTabsFromGlobalStorage() {
b.isOpen = true
}
}
if (t.pinned && !this.state.panelsMap[t.panelId]) t.panelId = DEFAULT_CTX_ID
this.state.tabsMap[t.id] = t
if (t.active) activeTab = t
if (t.active) this.state.activeTabId = t.id
Expand Down Expand Up @@ -109,6 +109,8 @@ async function loadTabsFromGlobalStorage() {
tab.folded = tabData.folded
idsMap[tabData.id] = tab.id
prevTab = tab

if (tab.pinned && !this.state.panelsMap[tab.panelId]) tab.panelId = DEFAULT_CTX_ID
}

this.state.tabs = tabs
Expand Down Expand Up @@ -142,9 +144,12 @@ async function loadTabsFromSessionStorage() {
browser.tabs.query({ windowId }),
browser.sessions.getWindowValue(this.state.windowId, 'groups'),
])
if (tabs[0].url.startsWith('about:blank#tabsdata')) {
return await this.actions.loadTabsFromInlineData(tabs)

let dataTabIndex = tabs.findIndex(t => t.url.startsWith('about:blank#tabsdata'))
if (dataTabIndex !== -1) {
return await this.actions.loadTabsFromInlineData(tabs, dataTabIndex)
}

if (!groups) groups = {}
let tabsData = await Promise.all(
tabs.map(t => {
Expand Down Expand Up @@ -175,8 +180,6 @@ async function loadTabsFromSessionStorage() {
}
}

if (t.pinned && !this.state.panelsMap[t.panelId]) t.panelId = DEFAULT_CTX_ID

if (dt) {
panel = this.state.panelsMap[dt.panelId]

Expand Down Expand Up @@ -236,6 +239,8 @@ async function loadTabsFromSessionStorage() {
activeTab = t
this.state.activeTabId = t.id
}

if (t.pinned && !this.state.panelsMap[t.panelId]) t.panelId = DEFAULT_CTX_ID
}

this.state.tabs = tabs
Expand Down Expand Up @@ -265,9 +270,12 @@ async function loadTabsFromSessionStorage() {
/**
* Load tabs using info from the first tab (e.g. for snapshots)
*/
async function loadTabsFromInlineData(tabs) {
let firstTab = tabs[0]
let tabsInfoStr = firstTab.url.slice(20)
async function loadTabsFromInlineData(tabs, dataTabIndex) {
// let firstTab = tabs[0]
let dataTab = tabs[dataTabIndex]
if (!dataTab) return this.actions.updatePanelsTabs()

let tabsInfoStr = dataTab.url.slice(20)
let tabsInfo = JSON.parse(decodeURIComponent(tabsInfoStr))
let activePanel = this.state.panels[this.state.panelIndex] || this.state.panels[1]

Expand All @@ -290,23 +298,23 @@ async function loadTabsFromInlineData(tabs) {
})
}

let secondTab = tabs[1]
let secondTab = tabs[dataTabIndex + 1]
if (!secondTab) return this.actions.updatePanelsTabs()

await browser.tabs.update(secondTab.id, { active: true })
secondTab.active = true
secondTab.discarded = false
await browser.tabs.remove(firstTab.id)
tabs.shift()

Utils.normalizeTab(firstTab, DEFAULT_CTX_ID)
await browser.tabs.remove(dataTab.id)
tabs.splice(dataTabIndex, 1)

let parents = []
let activeTab
for (let prevTab, tab, info, i = 0; i < tabsInfo.length; i++) {
info = tabsInfo[i]
prevTab = tabs[i - 1]
tab = tabs[i]
if (!tab) return this.actions.updatePanelsTabs()

tab.index = i
tab.loading = false

Expand Down Expand Up @@ -2295,29 +2303,27 @@ async function _old_loadTabs(tabs) {
b.isOpen = true
}
}

let p = this.state.panels.find(p => p.moveTabCtx === t.cookieStoreId)
t.panelId = p ? p.id : DEFAULT_CTX_ID

this.state.tabsMap[t.id] = t
if (t.active) activeTab = t
}
this.state.tabs = tabs

// Restore tree levels
if (this.state.tabsTree) {
await this.actions._old_restoreTabsTree()
}
if (this.state.tabsTree) await this.actions._old_restoreTabsTree()

for (let tab of tabs) {
let p = this.state.panels.find(p => p.moveTabCtx === tab.cookieStoreId)
tab.panelId = p ? p.id : DEFAULT_CTX_ID
}
// Update panels
this.actions.updatePanelsTabs()
if (this.state.tabsTree) this.actions.updateTabsTree()

// Update succession
if (this.state.activateAfterClosing !== 'none' && activeTab) {
const target = Utils.findSuccessorTab(this.state, activeTab)
if (target) browser.tabs.moveInSuccession([activeTab.id], target.id)
}

// Update panels
this.actions.updatePanelsTabs()
}

/**
Expand Down Expand Up @@ -2354,7 +2360,7 @@ function _old_findBranchStartIndex(array, subArray, startIndex) {
/**
* Create new group tab with provided props
*/
async function _old_restoreGroupTab(tabInfo, index, parents) {
async function _old_restoreGroupTab(tabInfo, index, parents, panelId) {
let groupId = Utils.getGroupId(tabInfo.url)
let url = browser.runtime.getURL('group/group.html') + `#${groupId}`
let restoredTab = await browser.tabs.create({
Expand All @@ -2366,6 +2372,7 @@ async function _old_restoreGroupTab(tabInfo, index, parents) {
})

restoredTab.url = url
restoredTab.panelId = panelId
if (tabInfo.isParent) parents[tabInfo.id] = restoredTab.id
restoredTab.isParent = tabInfo.isParent
restoredTab.parentId = parents[tabInfo.parentId] || -1
Expand Down Expand Up @@ -2430,14 +2437,13 @@ async function _old_restoreTabsTree() {
tab.parentId = parents[treeTab.parentId] || -1
tab.folded = treeTab.folded
} else {
await this.actions._old_restoreGroupTab(treeTab, tabIndex, parents)
await this.actions._old_restoreGroupTab(treeTab, tabIndex, parents, tab.panelId)
}
tabIndex++
}
}
break
}
this.actions.updateTabsTree()
}

//
Expand Down

0 comments on commit 904f251

Please sign in to comment.