Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion src/bg/background.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InstanceType } from 'src/types'
import { Containers, InstanceType } from 'src/types'
import { NOID } from 'src/defaults'
import * as IPC from 'src/services/ipc'
import * as Logs from 'src/services/logs'
Expand Down Expand Up @@ -119,6 +119,66 @@ void (async function main() {
if (newVersion <= currentVersion) browser.runtime.reload()
})

browser.omnibox.setDefaultSuggestion({ description: 'Type the name of the container you want for this tab…' })

function matchContainers(input: string): Container[] {
// TODO: order by score of some sort?
// TODO: At the very least, put an exact match first.
// TODO: Validate we want Sidebery records, not Firefox records.
return Object.values(Containers.reactive.byId).filter(container =>
container.name.toLowerCase().includes(input.toLowerCase())
)
}

browser.omnibox.onInputChanged.addListener(async (input, suggest) => {
const suggestions = matchContainers(input).map(ctx => ({
content: ctx.name,
description: ctx.name,
deletable: false,
}))
suggest(suggestions)
})

browser.omnibox.onInputEntered.addListener(async (input, _disposition) => {
// NOTE: We're semantically _re-opening_ tabs, which conflicts with a disposition. Ignore it.

if (!Windows.lastFocusedWinId) {
Logs.err('omnibox: no last focused window ID found')
return
}

const matchingContainers = matchContainers(input)
if (matchingContainers.length <= 0) {
Logs.warn('omnibox: no matching containers found')
return
}
const firstMatchingContainer = matchingContainers[0]

const sidebarTabs = await Tabs.getSidebarTabs(Windows.lastFocusedWinId)
if (!sidebarTabs) {
Logs.err('omnibox: no sidebar tabs found for last focused window ID')
return
}

const con = IPC.getConnection(InstanceType.sidebar, Windows.lastFocusedWinId)
if ((con?.localPort && con.localPort.error) || (con?.remotePort && con.remotePort.error)) {
Logs.err('need to fall back to creating tabs by hand')
return
}

const activeTabs = sidebarTabs.filter(tab => tab.active)
try {
await IPC.sidebar(
Windows.lastFocusedWinId,
'reopenInContainer',
activeTabs.map(tab => tab.id),
firstMatchingContainer.id
)
} catch {
console.warn('failed to re-open tabs', activeTabs, 'in container', firstMatchingContainer)
}
})

Logs.info(`Init end: ${performance.now() - ts}ms`)
})()

Expand Down
3 changes: 3 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,5 +492,8 @@
},
"background": {
"page": "bg/background.html"
},
"omnibox": {
"keyword": "sb"
}
}
1 change: 1 addition & 0 deletions src/sidebar/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async function main(): Promise<void> {
getTabsTreeData: Tabs.getTabsTreeData,
moveTabsToThisWin: Tabs.moveToThisWin,
openTabs: Tabs.open,
reopenInContainer: Tabs.reopenInContainer,
handleReopening: Tabs.handleReopening,
getActivePanelConfig: Sidebar.getActivePanelConfig,
stopDrag: DnD.onExternalStop,
Expand Down
1 change: 1 addition & 0 deletions src/types/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export type SidebarActions = {

moveTabsToThisWin: (tabs: Tab[], dst?: DstPlaceInfo) => Promise<boolean>
openTabs: (items: ItemInfo[], dst: DstPlaceInfo) => Promise<boolean>
reopenInContainer: (ids: ID[], containerId: string) => Promise<void>

notify: (config: Notification, timeout?: number) => void
notifyAboutNewSnapshot: () => void
Expand Down