@@ -23,6 +23,8 @@ import createRuntimeChecks from './runtime-checks.js'
23
23
import { createContextMenus , findValueForContext , contextMenuCopyAddressAtPublicGw , contextMenuCopyRawCid , contextMenuCopyCanonicalAddress , contextMenuViewOnGateway , contextMenuCopyPermalink , contextMenuCopyCidAddress } from './context-menus.js'
24
24
import { registerSubdomainProxy } from './http-proxy.js'
25
25
import { runPendingOnInstallTasks } from './on-installed.js'
26
+ import { getExtraInfoSpec } from './redirect-handler/blockOrObserve.js'
27
+
26
28
const log = debug ( 'ipfs-companion:main' )
27
29
log . error = debug ( 'ipfs-companion:main:error' )
28
30
@@ -33,7 +35,7 @@ export default async function init (windowedContext = false) {
33
35
// INIT
34
36
// ===================================================================
35
37
let ipfs // ipfs-api instance
36
- /** @type {import('../types.js').CompanionState } */
38
+ /** @type {import('../types/companion .js').CompanionState } */
37
39
let state // avoid redundant API reads by utilizing local cache of various states
38
40
let dnslinkResolver
39
41
let ipfsPathValidator
@@ -54,6 +56,7 @@ export default async function init (windowedContext = false) {
54
56
await migrateOptions ( browser . storage . local , debug )
55
57
const options = await browser . storage . local . get ( optionDefaults )
56
58
runtime = await createRuntimeChecks ( browser )
59
+
57
60
state = initState ( options )
58
61
notify = createNotifier ( getState )
59
62
@@ -65,6 +68,7 @@ export default async function init (windowedContext = false) {
65
68
console . error ( '[ipfs-companion] Failed to init IPFS client' , err )
66
69
notify (
67
70
'notify_startIpfsNodeErrorTitle' ,
71
+
68
72
err . name === 'ValidationError' ? err . details [ 0 ] . message : err . message
69
73
)
70
74
}
@@ -115,9 +119,11 @@ export default async function init (windowedContext = false) {
115
119
// Note: we need this for code ensuring kubo-rpc-client can talk to API without setting CORS
116
120
onBeforeSendInfoSpec . push ( 'extraHeaders' )
117
121
}
118
- browser . webRequest . onBeforeSendHeaders . addListener ( onBeforeSendHeaders , { urls : [ '<all_urls>' ] } , onBeforeSendInfoSpec )
119
- browser . webRequest . onBeforeRequest . addListener ( onBeforeRequest , { urls : [ '<all_urls>' ] } )
120
- browser . webRequest . onHeadersReceived . addListener ( onHeadersReceived , { urls : [ '<all_urls>' ] } , [ 'responseHeaders' ] )
122
+ browser . webRequest . onBeforeSendHeaders . addListener (
123
+
124
+ onBeforeSendHeaders , { urls : [ '<all_urls>' ] } , getExtraInfoSpec ( onBeforeSendInfoSpec ) )
125
+ browser . webRequest . onBeforeRequest . addListener ( onBeforeRequest , { urls : [ '<all_urls>' ] } , getExtraInfoSpec ( ) )
126
+ browser . webRequest . onHeadersReceived . addListener ( onHeadersReceived , { urls : [ '<all_urls>' ] } , getExtraInfoSpec ( [ 'responseHeaders' ] ) )
121
127
browser . webRequest . onErrorOccurred . addListener ( onErrorOccurred , { urls : [ '<all_urls>' ] , types : [ 'main_frame' ] } )
122
128
browser . webRequest . onCompleted . addListener ( onCompleted , { urls : [ '<all_urls>' ] , types : [ 'main_frame' ] } )
123
129
browser . storage . onChanged . addListener ( onStorageChange )
@@ -307,6 +313,7 @@ export default async function init (windowedContext = false) {
307
313
}
308
314
// console.log('onAddFromContext.context', context)
309
315
// console.log('onAddFromContext.fetchOptions', fetchOptions)
316
+
310
317
const response = await fetch ( dataSrc , fetchOptions )
311
318
const blob = await response . blob ( )
312
319
const url = new URL ( response . url )
@@ -315,6 +322,7 @@ export default async function init (windowedContext = false) {
315
322
? url . hostname
316
323
: url . pathname . replace ( / [ \\ / ] + $ / , '' ) . split ( '/' ) . pop ( )
317
324
data = {
325
+
318
326
path : decodeURIComponent ( filename ) ,
319
327
content : blob
320
328
}
@@ -332,6 +340,7 @@ export default async function init (windowedContext = false) {
332
340
}
333
341
} catch ( error ) {
334
342
console . error ( 'Error in import to IPFS context menu' , error )
343
+
335
344
if ( error . message === 'NetworkError when attempting to fetch resource.' ) {
336
345
notify ( 'notify_importErrorTitle' , 'notify_importTrackingProtectionErrorMsg' )
337
346
console . warn ( 'IPFS import often fails because remote file can not be downloaded due to Tracking Protection. See details at: https://github.com/ipfs/ipfs-companion/issues/227' )
@@ -524,6 +533,7 @@ export default async function init (windowedContext = false) {
524
533
// Chromium does not support SVG [ticket below is 8 years old, I can't even..]
525
534
// https://bugs.chromium.org/p/chromium/issues/detail?id=29683
526
535
// Still, we want icon, so we precompute rasters of popular sizes and use them instead
536
+
527
537
iconDefinition = await rasterIconDefinition ( iconPath )
528
538
await browser . action . setIcon ( iconDefinition )
529
539
}
@@ -537,6 +547,7 @@ export default async function init (windowedContext = false) {
537
547
if ( state . automaticMode && state . localGwAvailable ) {
538
548
if ( oldPeerCount === offlinePeerCount && newPeerCount > offlinePeerCount && ! state . redirect ) {
539
549
await browser . storage . local . set ( { useCustomGateway : true } )
550
+
540
551
reloadIpfsClientOfflinePages ( browser , ipfs , state )
541
552
} else if ( newPeerCount === offlinePeerCount && state . redirect ) {
542
553
await browser . storage . local . set ( { useCustomGateway : false } )
@@ -634,6 +645,7 @@ export default async function init (windowedContext = false) {
634
645
await destroyIpfsClient ( browser )
635
646
} catch ( err ) {
636
647
console . error ( '[ipfs-companion] Failed to destroy IPFS client' , err )
648
+
637
649
notify ( 'notify_stopIpfsNodeErrorTitle' , err . message )
638
650
} finally {
639
651
ipfs = null
@@ -648,6 +660,7 @@ export default async function init (windowedContext = false) {
648
660
console . error ( '[ipfs-companion] Failed to init IPFS client' , err )
649
661
notify (
650
662
'notify_startIpfsNodeErrorTitle' ,
663
+
651
664
err . name === 'ValidationError' ? err . details [ 0 ] . message : err . message
652
665
)
653
666
}
@@ -718,6 +731,7 @@ export default async function init (windowedContext = false) {
718
731
const rasterIconDefinition = pMemoize ( ( svgPath ) => {
719
732
const pngPath = ( size ) => {
720
733
// point at precomputed PNG file
734
+
721
735
const baseName = / \/ i c o n s \/ ( .+ ) \. s v g / . exec ( svgPath ) [ 1 ]
722
736
return `/icons/png/${ baseName } _${ size } .png`
723
737
}
0 commit comments