-
-
Notifications
You must be signed in to change notification settings - Fork 147
May 2020 Migration Guide
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.
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.
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]')
}
}
// 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')
}
}
// 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')
}
}
// 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')
}
}
// 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')
}
}
// 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')
}
}
// 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')
}
}
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