Skip to content

Commit 690ad80

Browse files
committed
feat: add deprecation warning to window.ipfs.<cmd>
1 parent b633eb4 commit 690ad80

File tree

1 file changed

+14
-2
lines changed
  • add-on/src/contentScripts/ipfs-proxy

1 file changed

+14
-2
lines changed

add-on/src/contentScripts/ipfs-proxy/page.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ const { createProxyClient } = require('ipfs-postmsg-proxy')
1010
function createEnableCommand (proxyClient) {
1111
return {
1212
enable: async (opts) => {
13-
// (This should be a lazy-load)
1413
// Send message to proxy server for additional validation
1514
// eg. trigger user prompt if a list of requested capabilities is not empty
1615
// or fail fast and throw if IPFS Proxy is disabled globally
1716
await require('postmsg-rpc').call('proxy.enable', opts)
17+
// Create client
18+
const proxyClient = createProxyClient()
1819
// Additional client-side features
1920
if (opts && opts.experiments) {
2021
if (opts.experiments.ipfsx) {
@@ -29,8 +30,19 @@ function createEnableCommand (proxyClient) {
2930

3031
function createWindowIpfs () {
3132
const proxyClient = createProxyClient()
32-
assign(proxyClient, createEnableCommand(proxyClient))
33+
34+
// Add deprecation warning to window.ipfs.<cmd>
35+
for (let cmd in proxyClient) {
36+
let fn = proxyClient[cmd]
37+
proxyClient[cmd] = function () {
38+
console.warn('Calling commands directly on window.ipfs is deprecated and will be removed on 2019-04-01. Use API instance returned by window.ipfs.enable() instead. More: https://github.com/ipfs-shipyard/ipfs-companion/blob/master/docs/window.ipfs.md')
39+
return fn.apply(this, arguments)
40+
}
41+
}
42+
3343
// TODO: return thin object with lazy-init inside of window.ipfs.enable
44+
assign(proxyClient, createEnableCommand())
45+
3446
return freeze(proxyClient)
3547
}
3648

0 commit comments

Comments
 (0)