Skip to content

May 2020 Migration Guide

Bowser65 edited this page May 27, 2020 · 2 revisions

Powercord's May Core Cleanup

Many functions of the Plugin class have been marked as deprecated and they'll be removed on the 1st November 2020. You have until this date to migrate your plugins to the newer syntax, or else your plugins will become unusable.

Why doing this?

While all the helper methods we've been telling people to use did make sense in the early days, we've created the powercord.api object, which caused those helper functions to become aliases. We've however made the decision to keep them to avoid breaking plugins and because they automatically unregister stuff.

However, in the end this accounts for more than half of the Plugin.js file and is becoming more and more painful to maintain. Also, those creates an inconsistent behavior, with some injections requiring to manually uninject at plugin unload and some automatically unregistering.

Migration Guides

Plugin#loadCSS

This method will not require you to manually unregister. We're doing it this way because this function is handled by the plugin itself rather than by an API, so tearing it down automatically is part of the plugin unload lifecycle. The main reason of the change is due to name consistency (you can load Stylus with loadCSS?) as well as some internal behavior changes.

// Before
class Weeb extends Plugin {
  startPlugin () {
    this.loadCSS('[absolute path to file]')
  }
}

// After
class Weeb extends Plugin {
  startPlugin () {
    this.loadStylesheet('[path, either absolute or relative to plugin root]')
  }
}

Plugin#registerSettings

// Before
class Weeb extends Plugin {
  startPlugin () {
    this.registerSettings('epic-settings', 'Epic Settings', EpicSettingsComponent);
  }
}

// After
class Weeb extends Plugin {
  startPlugin () {
    powercord.api.settings.registerSettings('epic-settings', {
      category: this.entityID,
      label: 'Epic Settings',
      render: EpicSettingsComponent
    })
  }

  pluginWillUnload () {
    powercord.api.settings.unregisterSettings('epic-settings')
  }
}

Plugin#registerCommand

// Before
class Weeb extends Plugin {
  startPlugin () {
    this.registerCommand(
      'command-name',
      [ 'alias1', 'alias2' ],
      'Very nice command description',
      '{c} blah blah',
      (args) => ({ send: false, result: args.join(' ') })
    )
  }
}

// After
class Weeb extends Plugin {
  startPlugin () {
    powercord.api.commands.registerCommand({
      command: 'command-name',
      aliases: [ 'alias1', 'alias2' ],
      description: 'Very nice command description',
      usage: '{c} blah blah',
      executor: (args) => ({ send: false, result: args.join(' ') })
    })
  }

  pluginWillUnload () {
    powercord.api.commands.unregisterCommand('command-name')
  }
}

Plugin#registerKeybind

// Before
class Weeb extends Plugin {
  startPlugin () {
    this.registerKeybind('my-keybind', 'My Keybind', 'Pings b1nzy', 'Ctrl+P', () => this.pingB1nzy())
  }
}

// After
class Weeb extends Plugin {
  startPlugin () {
    powercord.api.keybinds.registerKeybind('my-keybind', {
      keybind: 'Ctrl+P',
      executor: () => this.pingB1nzy()
    })
  }

  pluginWillUnload () {
    powercord.api.keybinds.unregisterKeybind('my-keybind')
  }
}

Plugin#registerRoute

// Before
class Weeb extends Plugin {
  startPlugin () {
    this.registerRoute('/yeet', Yeet, true)
  }
}

// After
class Weeb extends Plugin {
  startPlugin () {
    powercord.api.router.registerRoute({
      path: '/yeet',
      render: Yeet,
      noSidebar: true
    })
  }

  pluginWillUnload () {
    powercord.api.router.unregisterRoute('/yeet')
  }
}

Plugin#registerRPCScope

// Before
class Weeb extends Plugin {
  startPlugin () {
    this.registerRPCScope('PRINTER', origin => origin === 'printer.discord.com')
  }
}

// After
class Weeb extends Plugin {
  startPlugin () {
    powercord.api.rpc.registerScope('PRINTER', origin => origin === 'printer.discord.com')
  }

  pluginWillUnload () {
    powercord.api.rpc.unregisterScope('PRINTER')
  }
}

Plugin#registerRPCEvent

// Before
class Weeb extends Plugin {
  startPlugin () {
    this.registerRPCEvent('EVENT_NAME', {
      scope: 'POWERCORD_PRIVATE',
      handler: (e) => console.log(e)
    })
  }
}

// After
class Weeb extends Plugin {
  startPlugin () {
    powercord.api.rpc.registerEvent('EVENT_NAME', {
      scope: 'POWERCORD_PRIVATE',
      handler: (e) => console.log(e)
    })
  }

  pluginWillUnload () {
    powercord.api.rpc.unregisterEvent('EVENT_NAME')
  }
}

Toast and announcements

All of the following methods can be upgraded simply by changing this by powercord.api.notices. Yes it's as simple.

  • this.sendToast
  • this.closeToast
  • this.sendAnnouncement
  • this.closeAnnouncement