Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbnuqw committed Jan 4, 2020
2 parents 314e3f9 + 97fb179 commit 914f165
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 275 deletions.
27 changes: 0 additions & 27 deletions addon/actions/msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function initMessaging() {
// Setup message handling
let info = JSON.parse(port.name)
if (info.instanceType === 'sidebar') {
if (!this.windows[info.windowId]) return
connectedSidebars[info.windowId] = port
port.onMessage.addListener(onSidebarMsg)

Expand Down Expand Up @@ -71,31 +70,6 @@ function onFirstSidebarInit(handler) {
firstSidebarInitHandlers.push(handler)
}

/**
* Wait for connecting sidebery instance of
* target window.
*/
async function waitForSidebarConnect(winId, limit = 1000) {
let waitingId = String(Math.random())
let waiting = new Promise(res => {
if (connectedSidebars[winId]) return res(true)

connectPending.push({
id: waitingId,
winId,
resolve: res,
})

setTimeout(() => {
let index = connectPending.findIndex(w => w.id === waitingId)
if (index > -1) connectPending.splice(index, 1)
res(false)
}, limit)
})

return waiting
}

/**
* Handle message from sidebar
*/
Expand All @@ -113,5 +87,4 @@ export default {
initMessaging,
onSidebarMsg,
onFirstSidebarInit,
waitForSidebarConnect,
}
37 changes: 0 additions & 37 deletions addon/actions/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,42 +216,6 @@ async function updateTabsTree() {
}
}

/**
* Move provided tabs to window
*/
async function moveTabsToWin(winId, tabs, fromPrivate, rmTabId) {
let sidebarIsOpen = await browser.sidebarAction.isOpen({ windowId: winId })
let isConnected = false

if (sidebarIsOpen) {
isConnected = await this.actions.waitForSidebarConnect(winId, 7000)
if (isConnected) {
await browser.runtime.sendMessage({
instanceType: 'sidebar',
windowId: winId,
action: 'moveTabsToThisWin',
args: [tabs, fromPrivate],
})
}
}

if (!isConnected) {
let win = this.windows[winId]
if (win.incognito === fromPrivate) {
for (let tab of tabs) {
await browser.tabs.move(tab.id, { windowId: winId, index: -1 })
}
} else {
for (let tab of tabs) {
await browser.tabs.create({ url: tab.url, windowId: winId })
browser.tabs.remove(tab.id)
}
}
}

if (rmTabId > -1) await browser.tabs.remove(rmTabId)
}

function setupTabsListeners() {
browser.tabs.onCreated.addListener(this.actions.onTabCreated)
browser.tabs.onRemoved.addListener(this.actions.onTabRemoved)
Expand Down Expand Up @@ -282,7 +246,6 @@ export default {
updateTabsTree,
backupTabsData,
saveTabsData,
moveTabsToWin,

setupTabsListeners,
}
8 changes: 4 additions & 4 deletions addon/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ void (async function main() {
Actions.initGlobalMessaging()
Actions.initMessaging()

// Load containers
Actions.setupContainersListeners()
await Actions.loadContainers()

// Load windows
state.windows = await Actions.getWindows()
Actions.setupWindowsListeners()

// Load containers
Actions.setupContainersListeners()
await Actions.loadContainers()

// Load settings
let { settings } = await browser.storage.local.get({ settings: null })
state.settings = settings ? settings : {}
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.4",
"version": "4.0.5",
"default_locale": "en",
"description": "__MSG_ExtDesc__",
"homepage_url": "https://github.com/mbnuqw/sidebery",
Expand Down
5 changes: 2 additions & 3 deletions addon/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,14 @@ function findDataForTabs(tabs, data) {

// Saved tab is a group and its missing
if (isGroupUrl(tabData.url) && tabData.url !== tab.url) {
tabData.index = k + gOffset
tabData.isMissedGroup = true
k--
gOffset++
continue
}

// Match
if (tabData.url === tab.url || (tab.active && tab.url === 'about:blank')) {
let blindspot = tab.status === 'loading' && tab.url === 'about:blank'
if (tabData.url === tab.url || blindspot) {
tabData.index = k + gOffset
equalityCounter++
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sidebery",
"version": "4.0.4",
"version": "4.0.5",
"description": "Manage your tabs and bookmarks in sidebar",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -91,6 +91,7 @@
"./test/env-setup.js"
],
"testMatch": [
"**/addon/**/__tests__/*.test.js",
"**/src/**/__tests__/*.test.js"
]
}
Expand Down
10 changes: 10 additions & 0 deletions src/sidebar/actions/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ async function sortBookmarks(type, nodeIds) {
}
}

function highlightBookmarks(url) {
if (!this.state.highlightOpenBookmarks || !this.state.bookmarksUrlMap) return
if (!this.state.bookmarksUrlMap[url]) return

for (let b of this.state.bookmarksUrlMap[url]) {
b.isOpen = true
}
}

export default {
loadBookmarks,
saveBookmarksTree,
Expand All @@ -634,4 +643,5 @@ export default {
collapseAllBookmarks,
updateBookmarksCounter,
sortBookmarks,
highlightBookmarks,
}
6 changes: 0 additions & 6 deletions src/sidebar/actions/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ function updateSettings(settings) {
parentId: tab.parentId,
folded: tab.folded,
})
if (Utils.isGroupUrl(tab.url)) {
if (!this.state.groupTabs) this.state.groupTabs = {}
this.state.groupTabs[tab.id] = true
} else if (this.state.groupTabs[tab.id]) {
this.state.groupTabs[tab.id] = false
}
}
this.actions.saveGroups()
}
Expand Down
Loading

0 comments on commit 914f165

Please sign in to comment.