3
3
4
4
import debug from 'debug'
5
5
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'
10
6
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'
14
13
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'
15
20
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'
19
21
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'
25
22
import { runPendingOnInstallTasks } from './on-installed.js'
23
+ import { guiURLString , migrateOptions , optionDefaults , safeURL , storeMissingOptions } from './options.js'
26
24
import { getExtraInfoSpec } from './redirect-handler/blockOrObserve.js'
25
+ import createRuntimeChecks from './runtime-checks.js'
26
+ import { initState , offlinePeerCount } from './state.js'
27
27
28
28
// this won't work in webworker context. Needs to be enabled manually
29
29
// https://github.com/debug-js/debug/issues/916
@@ -33,7 +33,7 @@ log.error = debug('ipfs-companion:main:error')
33
33
let browserActionPort // reuse instance for status updates between on/off toggles
34
34
35
35
// init happens on addon load in background/background.js
36
- export default async function init ( ) {
36
+ export default async function init ( inQuickImport = false ) {
37
37
// INIT
38
38
// ===================================================================
39
39
let ipfs // ipfs-api instance
@@ -65,7 +65,7 @@ export default async function init () {
65
65
if ( state . active ) {
66
66
// It's ok for this to fail, node might be unavailable or mis-configured
67
67
try {
68
- ipfs = await initIpfsClient ( browser , state )
68
+ ipfs = await initIpfsClient ( browser , state , inQuickImport )
69
69
} catch ( err ) {
70
70
console . error ( '[ipfs-companion] Failed to init IPFS client' , err )
71
71
notify (
@@ -81,12 +81,14 @@ export default async function init () {
81
81
copier = createCopier ( notify , ipfsPathValidator )
82
82
ipfsImportHandler = createIpfsImportHandler ( getState , getIpfs , ipfsPathValidator , runtime , copier )
83
83
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
+ }
90
92
modifyRequest = createRequestModifier ( getState , dnslinkResolver , ipfsPathValidator , runtime )
91
93
log ( 'register all listeners' )
92
94
registerListeners ( )
@@ -358,16 +360,22 @@ export default async function init () {
358
360
// immediately preceding a switch from one browser window to another.
359
361
if ( windowId !== browser . windows . WINDOW_ID_NONE ) {
360
362
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
+ }
362
366
}
363
367
}
364
368
365
369
async function onActivatedTab ( activeInfo ) {
366
- await contextMenus . update ( activeInfo . tabId )
370
+ if ( ! inQuickImport ) {
371
+ await contextMenus . update ( activeInfo . tabId )
372
+ }
367
373
}
368
374
369
375
async function onNavigationCommitted ( details ) {
370
- await contextMenus . update ( details . tabId )
376
+ if ( ! inQuickImport ) {
377
+ await contextMenus . update ( details . tabId )
378
+ }
371
379
await updatePageActionIndicator ( details . tabId , details . url )
372
380
}
373
381
@@ -437,8 +445,12 @@ export default async function init () {
437
445
await Promise . all ( [
438
446
updateAutomaticModeRedirectState ( oldPeerCount , state . peerCount ) ,
439
447
updateBrowserActionBadge ( ) ,
440
- contextMenus . update ( ) ,
441
- sendStatusUpdateToBrowserAction ( )
448
+ sendStatusUpdateToBrowserAction ( ) ,
449
+ ( ) => {
450
+ if ( ! inQuickImport ) {
451
+ contextMenus . update ( )
452
+ }
453
+ }
442
454
] )
443
455
}
444
456
0 commit comments