Skip to content

Commit

Permalink
feat: add deprecation warning to window.ipfs.<cmd>
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Jan 3, 2019
1 parent b633eb4 commit 690ad80
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions add-on/src/contentScripts/ipfs-proxy/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -29,8 +30,19 @@ function createEnableCommand (proxyClient) {

function createWindowIpfs () {
const proxyClient = createProxyClient()
assign(proxyClient, createEnableCommand(proxyClient))

// Add deprecation warning to window.ipfs.<cmd>
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)
}

Expand Down

0 comments on commit 690ad80

Please sign in to comment.