Skip to content

Commit 9f4981c

Browse files
authored
fix (quick-import): Duplicate behaviour in MV3 (#1215)
* feat(mv3): ✨ ContextMenus MV3 Style * feat(mv3): 🧪 Adding tests * fix: test case * fix(mv3): 🐛 Quick Import
1 parent 554e69f commit 9f4981c

File tree

3 files changed

+53
-36
lines changed

3 files changed

+53
-36
lines changed

add-on/src/lib/ipfs-client/index.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44

55
import debug from 'debug'
66

7-
import * as external from './external.js'
8-
import * as embedded from './embedded.js'
9-
import * as brave from './brave.js'
107
import { precache } from '../precache.js'
8+
import * as brave from './brave.js'
9+
import * as embedded from './embedded.js'
10+
import * as external from './external.js'
1111
import {
12-
prepareReloadExtensions, WebUiReloader, LocalGatewayReloader, InternalTabReloader
12+
InternalTabReloader,
13+
LocalGatewayReloader,
14+
WebUiReloader,
15+
prepareReloadExtensions
1316
} from './reloaders/index.js'
1417
const log = debug('ipfs-companion:client')
1518
log.error = debug('ipfs-companion:client:error')
1619

1720
// ensure single client at all times, and no overlap between init and destroy
1821
let client
1922

20-
export async function initIpfsClient (browser, opts) {
23+
export async function initIpfsClient (browser, opts, inQuickImport) {
2124
log('init ipfs client')
2225
if (client) return // await destroyIpfsClient()
2326
let backend
@@ -48,7 +51,9 @@ export async function initIpfsClient (browser, opts) {
4851
throw new Error(`Unsupported ipfsNodeType: ${opts.ipfsNodeType}`)
4952
}
5053
const instance = await backend.init(browser, opts)
51-
_reloadIpfsClientDependents(browser, instance, opts) // async (API is present)
54+
if (!inQuickImport) {
55+
_reloadIpfsClientDependents(browser, instance, opts) // async (API is present)
56+
}
5257
client = backend
5358
return instance
5459
}

add-on/src/lib/ipfs-companion.js

+40-28
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33

44
import debug from 'debug'
55

6-
import browser from 'webextension-polyfill'
7-
import toMultiaddr from 'uri-to-multiaddr'
8-
import pMemoize from 'p-memoize'
9-
import LRU from 'lru-cache'
106
import all from 'it-all'
11-
import { optionDefaults, storeMissingOptions, migrateOptions, guiURLString, safeURL } from './options.js'
12-
import { initState, offlinePeerCount } from './state.js'
13-
import { createIpfsPathValidator, dropSlash, sameGateway, safeHostname } from './ipfs-path.js'
7+
import LRU from 'lru-cache'
8+
import pMemoize from 'p-memoize'
9+
import toMultiaddr from 'uri-to-multiaddr'
10+
import browser from 'webextension-polyfill'
11+
import { contextMenuCopyAddressAtPublicGw, contextMenuCopyCanonicalAddress, contextMenuCopyCidAddress, contextMenuCopyPermalink, contextMenuCopyRawCid, contextMenuViewOnGateway, createContextMenus, findValueForContext } from './context-menus.js'
12+
import createCopier from './copier.js'
1413
import createDnslinkResolver from './dnslink.js'
14+
import { registerSubdomainProxy } from './http-proxy.js'
15+
import createInspector from './inspector.js'
16+
import { braveNodeType, releaseBraveEndpoint, useBraveEndpoint } from './ipfs-client/brave.js'
17+
import { destroyIpfsClient, initIpfsClient, reloadIpfsClientOfflinePages } from './ipfs-client/index.js'
18+
import { browserActionFilesCpImportCurrentTab, createIpfsImportHandler, formatImportDirectory } from './ipfs-import.js'
19+
import { createIpfsPathValidator, dropSlash, safeHostname, sameGateway } from './ipfs-path.js'
1520
import { createRequestModifier } from './ipfs-request.js'
16-
import { initIpfsClient, destroyIpfsClient, reloadIpfsClientOfflinePages } from './ipfs-client/index.js'
17-
import { braveNodeType, useBraveEndpoint, releaseBraveEndpoint } from './ipfs-client/brave.js'
18-
import { createIpfsImportHandler, formatImportDirectory, browserActionFilesCpImportCurrentTab } from './ipfs-import.js'
1921
import createNotifier from './notifier.js'
20-
import createCopier from './copier.js'
21-
import createInspector from './inspector.js'
22-
import createRuntimeChecks from './runtime-checks.js'
23-
import { createContextMenus, findValueForContext, contextMenuCopyAddressAtPublicGw, contextMenuCopyRawCid, contextMenuCopyCanonicalAddress, contextMenuViewOnGateway, contextMenuCopyPermalink, contextMenuCopyCidAddress } from './context-menus.js'
24-
import { registerSubdomainProxy } from './http-proxy.js'
2522
import { runPendingOnInstallTasks } from './on-installed.js'
23+
import { guiURLString, migrateOptions, optionDefaults, safeURL, storeMissingOptions } from './options.js'
2624
import { getExtraInfoSpec } from './redirect-handler/blockOrObserve.js'
25+
import createRuntimeChecks from './runtime-checks.js'
26+
import { initState, offlinePeerCount } from './state.js'
2727

2828
// this won't work in webworker context. Needs to be enabled manually
2929
// https://github.com/debug-js/debug/issues/916
@@ -33,7 +33,7 @@ log.error = debug('ipfs-companion:main:error')
3333
let browserActionPort // reuse instance for status updates between on/off toggles
3434

3535
// init happens on addon load in background/background.js
36-
export default async function init () {
36+
export default async function init (inQuickImport = false) {
3737
// INIT
3838
// ===================================================================
3939
let ipfs // ipfs-api instance
@@ -65,7 +65,7 @@ export default async function init () {
6565
if (state.active) {
6666
// It's ok for this to fail, node might be unavailable or mis-configured
6767
try {
68-
ipfs = await initIpfsClient(browser, state)
68+
ipfs = await initIpfsClient(browser, state, inQuickImport)
6969
} catch (err) {
7070
console.error('[ipfs-companion] Failed to init IPFS client', err)
7171
notify(
@@ -81,12 +81,14 @@ export default async function init () {
8181
copier = createCopier(notify, ipfsPathValidator)
8282
ipfsImportHandler = createIpfsImportHandler(getState, getIpfs, ipfsPathValidator, runtime, copier)
8383
inspector = createInspector(notify, ipfsPathValidator, getState)
84-
contextMenus = createContextMenus(getState, runtime, ipfsPathValidator, {
85-
onAddFromContext,
86-
onCopyCanonicalAddress: copier.copyCanonicalAddress,
87-
onCopyRawCid: copier.copyRawCid,
88-
onCopyAddressAtPublicGw: copier.copyAddressAtPublicGw
89-
})
84+
if (!inQuickImport) {
85+
contextMenus = createContextMenus(getState, runtime, ipfsPathValidator, {
86+
onAddFromContext,
87+
onCopyCanonicalAddress: copier.copyCanonicalAddress,
88+
onCopyRawCid: copier.copyRawCid,
89+
onCopyAddressAtPublicGw: copier.copyAddressAtPublicGw
90+
})
91+
}
9092
modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime)
9193
log('register all listeners')
9294
registerListeners()
@@ -358,16 +360,22 @@ export default async function init () {
358360
// immediately preceding a switch from one browser window to another.
359361
if (windowId !== browser.windows.WINDOW_ID_NONE) {
360362
const currentTab = await browser.tabs.query({ active: true, windowId }).then(tabs => tabs[0])
361-
await contextMenus.update(currentTab.id)
363+
if (!inQuickImport) {
364+
await contextMenus.update(currentTab.id)
365+
}
362366
}
363367
}
364368

365369
async function onActivatedTab (activeInfo) {
366-
await contextMenus.update(activeInfo.tabId)
370+
if (!inQuickImport) {
371+
await contextMenus.update(activeInfo.tabId)
372+
}
367373
}
368374

369375
async function onNavigationCommitted (details) {
370-
await contextMenus.update(details.tabId)
376+
if (!inQuickImport) {
377+
await contextMenus.update(details.tabId)
378+
}
371379
await updatePageActionIndicator(details.tabId, details.url)
372380
}
373381

@@ -437,8 +445,12 @@ export default async function init () {
437445
await Promise.all([
438446
updateAutomaticModeRedirectState(oldPeerCount, state.peerCount),
439447
updateBrowserActionBadge(),
440-
contextMenus.update(),
441-
sendStatusUpdateToBrowserAction()
448+
sendStatusUpdateToBrowserAction(),
449+
() => {
450+
if (!inQuickImport) {
451+
contextMenus.update()
452+
}
453+
}
442454
])
443455
}
444456

add-on/src/popup/quick-import.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async function processFiles (state, emitter, files) {
122122

123123
let ipfs
124124
if (httpStreaming) {
125-
// We create separate instance of http client running in thie same page to
125+
// We create separate instance of http client running in the same page to
126126
// avoid serialization issues in Chromium
127127
// (https://bugs.chromium.org/p/chromium/issues/detail?id=112163) when
128128
// crossing process boundary, which enables streaming upload of big files
@@ -151,7 +151,7 @@ async function processFiles (state, emitter, files) {
151151
if (state.userChangedImportDir) {
152152
emitter.emit('optionChange', { key: 'importDir', value: state.importDir })
153153
}
154-
// present result to the user using the beast available way
154+
// present result to the user using the best available way
155155
if (!state.openViaWebUI || state.ipfsNodeType.startsWith('embedded')) {
156156
await openFilesAtGateway(importDir)
157157
} else {

0 commit comments

Comments
 (0)