This repository was archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtPlug.js
More file actions
246 lines (206 loc) · 6.76 KB
/
Copy pathExtPlug.js
File metadata and controls
246 lines (206 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import Events from 'plug/core/Events';
import currentUser from 'plug/models/currentUser';
import RoomSettings from './models/RoomSettings';
import Plugin from './Plugin';
import PluginManager from './PluginManager';
import PluginLocalStorage from './PluginLocalStorage';
import getApplicationView from './util/getApplicationView';
import handlers from './handlers';
import EarlyAPIEventsPlugin from './plugins/EarlyAPIEventsPlugin';
import CommandsPlugin from './plugins/CommandsPlugin';
import SettingsTabPlugin from './plugins/SettingsTabPlugin';
import ChatTypePlugin from './plugins/ChatTypePlugin';
import MoreChatEventsPlugin from './plugins/MoreChatEventsPlugin';
import UserClassesPlugin from './plugins/UserClassesPlugin';
import EmojiDataPlugin from './plugins/EmojiDataPlugin';
import TooltipsPlugin from './plugins/TooltipsPlugin';
import GuestPlugin from './plugins/GuestPlugin';
import SocketEventsPlugin from './plugins/SocketEventsPlugin';
import WaitlistEventsPlugin from './plugins/WaitlistEventsPlugin';
import PlaybackEventsPlugin from './plugins/PlaybackEventsPlugin';
import PlugSettingsPlugin from './plugins/PlugSettingsPlugin';
import PopoutStylePlugin from './plugins/PopoutStylePlugin';
import UserMenuPlugin from './plugins/UserMenuPlugin';
import RoomSettingsPlugin from './plugins/RoomSettingsPlugin';
import * as packageMeta from '../package.json';
import style from './styles/index.css';
// Enable compatibility with AMD-based plugins.
import './util/compatibility';
// LocalStorage key name for extplug
const LS_NAME = 'extPlugins';
/**
* Main ExtPlug extension class.
*
* This will be instantiated by ExtPlug later, and can then be accessed
* on `window.ext`.
*
* @constructor
*/
const ExtPlug = Plugin.extend({
name: 'ExtPlug',
settings: {
corsProxy: {
type: 'boolean',
default: true,
label: 'Use CORS proxy',
},
},
style,
init() {
this._super('extplug', this);
this.isFirstRun = localStorage.getItem(LS_NAME) == null;
this.manager = new PluginManager({
storage: new PluginLocalStorage({ version: packageMeta.version }),
});
this.corePlugins = [
new EarlyAPIEventsPlugin('extplug:early-api', this),
new CommandsPlugin('extplug:chat-commands', this),
new SettingsTabPlugin('extplug:settings-tab', this),
new MoreChatEventsPlugin('extplug:more-chat-events', this),
new ChatTypePlugin('extplug:custom-chat-type', this),
new UserClassesPlugin('extplug:user-classes', this),
new EmojiDataPlugin('extplug:emoji-data', this),
new TooltipsPlugin('extplug:tooltips', this),
new SocketEventsPlugin('extplug:socket-events', this),
new WaitlistEventsPlugin('extplug:waitlist-events', this),
new PlaybackEventsPlugin('extplug:playback-events', this),
new PlugSettingsPlugin('extplug:plug-settings', this),
new PopoutStylePlugin('extplug:popout-style', this),
new UserMenuPlugin('extplug:user-menu', this),
new RoomSettingsPlugin('extplug:room-settings', this),
];
this.guestPlugin = new GuestPlugin('extplug:guest', this);
// Alias for compatibility with old versions.
Object.defineProperty(this, '_plugins', {
get() {
return this.plugins;
},
});
},
/**
* Register an ExtPlug plugin by require.js module name.
* This can be anything that is accepted by require.js, including
* modules using require.js plugins or modules on remote URLs.
*/
registerPlugin(id, cb) {
this.manager.load(id).then(
result => cb(null, result),
err => cb(err),
);
},
/**
* Disables and removes an ExtPlug plugin.
*/
unregisterPlugin(id) {
this.manager.unload(id);
},
getPlugin(id) {
return this.manager.getPlugin(id);
},
/**
* Installs a plugin. This is basically registerPlugin(), but it also
* remembers the plugin name so it can be loaded again automatically
* on following ExtPlug runs.
*/
install(id, cb) {
this.manager.install(id).then(
result => cb(null, result),
err => cb(err),
);
},
/**
* Disables and removes a plugin forever.
*/
uninstall(id) {
this.manager.uninstall(id);
},
/**
* Loads installed plugins.
*/
loadInstalledPlugins() {
this.manager.loadInstalledPlugins().then(() => {
Events.trigger('notify', 'icon-extplug', 'ExtPlug: loaded plugins.', () => {
Events.trigger('show:user', 'settings', 'ext-plug');
});
}).catch((err) => {
Events.trigger('notify', 'icon-chat-system', `Plugin error: ${err.message}`);
});
},
/**
* Things that should only happen the first time ExtPlug
* is initialised.
*/
onFirstRun() {
return Promise.all([
this.manager.install('https://unpkg.com/extplug-autowoot'),
this.manager.install('https://unpkg.com/extplug-chat-notifications'),
this.manager.install('https://unpkg.com/extplug-hide-badges'),
this.manager.install('https://unpkg.com/extplug-meh-icons'),
this.manager.install('https://unpkg.com/extplug-room-styles'),
this.manager.install('https://unpkg.com/extplug-show-deleted'),
]);
},
/**
* Initializes ExtPlug.
*
* This attaches events and finds some common DOM elements. Also, adds
* the ExtPlug tab to the user settings area.
*
* @return {ExtPlug} `this`.
*/
enable() {
API.enabled = true;
/**
* Internal map of registered plugins.
*
* TODO Remove this property and add replacement methods and events to
* PluginManager.
*/
Object.defineProperty(this, 'plugins', {
get: () => this.manager.pluginInstances,
});
if (this.isFirstRun) this.onFirstRun();
this.upgrade();
this.appView = getApplicationView();
this.unsubscribeHandlers = handlers(this);
this.corePlugins.forEach((plugin) => {
plugin.enable();
});
// room settings
this.roomSettings = new RoomSettings(this);
this.loadInstalledPlugins();
Events.trigger('notify', 'icon-extplug', `ExtPlug v${packageMeta.version} loaded`);
if (currentUser.get('guest')) {
this.guestPlugin.enable();
currentUser.once('change:guest', () => {
this.guestPlugin.disable();
});
}
return this;
},
/**
* Deinitializes and cleans up ExtPlug.
*
* Everything should be unloaded here, so the Plug.DJ page looks like nothing ever happened.
*/
disable() {
this.manager.unloadAll();
this.corePlugins.forEach((plugin) => {
plugin.disable();
});
this.guestPlugin.disable();
this.unsubscribeHandlers();
this.unsubscribeHandlers = null;
// remove room settings handling
this.roomSettings.dispose();
this.trigger('deinit');
this._super();
},
/**
* Upgrades old ExtPlug version settings.
*/
upgrade() {
// Empty
},
});
export default ExtPlug;