From 690ad80e1948387c25f0c081ece3c2681ce93918 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 3 Jan 2019 13:21:37 +0100 Subject: [PATCH] feat: add deprecation warning to window.ipfs. --- add-on/src/contentScripts/ipfs-proxy/page.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/add-on/src/contentScripts/ipfs-proxy/page.js b/add-on/src/contentScripts/ipfs-proxy/page.js index b892e5e8f..3926af706 100644 --- a/add-on/src/contentScripts/ipfs-proxy/page.js +++ b/add-on/src/contentScripts/ipfs-proxy/page.js @@ -10,11 +10,12 @@ const { createProxyClient } = require('ipfs-postmsg-proxy') function createEnableCommand (proxyClient) { return { enable: async (opts) => { - // (This should be a lazy-load) // Send message to proxy server for additional validation // eg. trigger user prompt if a list of requested capabilities is not empty // or fail fast and throw if IPFS Proxy is disabled globally await require('postmsg-rpc').call('proxy.enable', opts) + // Create client + const proxyClient = createProxyClient() // Additional client-side features if (opts && opts.experiments) { if (opts.experiments.ipfsx) { @@ -29,8 +30,19 @@ function createEnableCommand (proxyClient) { function createWindowIpfs () { const proxyClient = createProxyClient() - assign(proxyClient, createEnableCommand(proxyClient)) + + // Add deprecation warning to window.ipfs. + for (let cmd in proxyClient) { + let fn = proxyClient[cmd] + proxyClient[cmd] = function () { + 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') + return fn.apply(this, arguments) + } + } + // TODO: return thin object with lazy-init inside of window.ipfs.enable + assign(proxyClient, createEnableCommand()) + return freeze(proxyClient) }