1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-08-18 13:31:41 +02:00
Files
Configuration
Core
Libraries
Plugins
Properties
Resources
Plugins
Scripts
pages
code.js
notification.js
plugins.browser.js
plugins.js
plugins.notification.js
update.js
ScriptLoader.cs
about.png
icon-small.ico
icon-tray-new.ico
icon-tray.ico
icon.ico
Updates
bld
tests
.gitignore
LICENSE.md
Program.cs
README.md
Reporter.cs
TweetDck.csproj
TweetDck.sln
TweetDck.sln.DotSettings
_postbuild.bat
packages.config

87 lines
1.9 KiB
JavaScript

(function(){
//
// Class: Abstract plugin base class.
//
window.PluginBase = class{
constructor(pluginSettings){
this.$pluginSettings = pluginSettings || {};
}
enabled(){}
ready(){}
disabled(){}
};
//
// Variable: Main object for containing and managing plugins.
//
window.TD_PLUGINS = new class{
constructor(){
this.installed = [];
this.disabled = [];
this.waiting = [];
}
isDisabled(plugin){
return this.disabled.includes(plugin.id);
}
findObject(identifier){
return this.installed.find(plugin => plugin.id === identifier);
}
install(plugin){
this.installed.push(plugin);
if (!this.isDisabled(plugin)){
plugin.obj.enabled();
this.runWhenReady(plugin);
}
}
runWhenReady(plugin){
if (window.TD_APP_READY){
plugin.obj.ready();
}
else{
this.waiting.push(plugin);
}
}
setState(plugin, enable){
let reloading = plugin.obj.$pluginSettings.requiresPageReload;
if (enable && this.isDisabled(plugin)){
if (reloading){
location.reload();
}
else{
this.disabled.splice(this.disabled.indexOf(plugin.id), 1);
plugin.obj.enabled();
this.runWhenReady(plugin);
}
}
else if (!enable && !this.isDisabled(plugin)){
if (reloading){
location.reload();
}
else{
this.disabled.push(plugin.id);
plugin.obj.disabled();
}
}
}
onReady(){
this.waiting.forEach(plugin => plugin.obj.ready());
this.waiting = [];
}
};
//
// Block: Setup global function to change plugin state.
//
window.TDPF_setPluginState = function(identifier, enable){
window.TD_PLUGINS.setState(window.TD_PLUGINS.findObject(identifier), enable);
};
})();