Skip to content
This repository was archived by the owner on Mar 6, 2020. It is now read-only.

Commit 0bdeb84

Browse files
committed
convert plug.dj settings mirror to Plugin
1 parent 7ee9d57 commit 0bdeb84

5 files changed

Lines changed: 38 additions & 40 deletions

File tree

src/ExtPlug.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import TooltipsPlugin from './plugins/TooltipsPlugin';
1919
import GuestPlugin from './plugins/GuestPlugin';
2020
import SocketEventsPlugin from './plugins/SocketEventsPlugin';
2121
import WaitlistEventsPlugin from './plugins/WaitlistEventsPlugin';
22+
import PlugSettingsPlugin from './plugins/PlugSettingsPlugin';
2223

2324
import * as _package from './package';
2425

@@ -89,7 +90,8 @@ const ExtPlug = Plugin.extend({
8990
new EmojiDataPlugin('extplug:emoji-data', this),
9091
new TooltipsPlugin('extplug:tooltips', this),
9192
new SocketEventsPlugin('extplug:socket-events', this),
92-
new WaitlistEventsPlugin('extplug:waitlist-events', this)
93+
new WaitlistEventsPlugin('extplug:waitlist-events', this),
94+
new PlugSettingsPlugin('extplug:plug-settings', this)
9395
];
9496

9597
this._guest = new GuestPlugin('extplug:guest', this);
@@ -249,7 +251,6 @@ const ExtPlug = Plugin.extend({
249251

250252
this.upgrade();
251253

252-
settings.update();
253254
this.appView = getApplicationView();
254255

255256
// install extra events

src/hooks/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import * as apiEarlyHook from './api-early';
22
import * as playbackHook from './playback';
3-
import * as settingsHook from './settings';
43
import * as popoutStyleHook from './popout-style';
54

65
export default [
76
apiEarlyHook,
87
playbackHook,
9-
settingsHook,
108
popoutStyleHook
119
];

src/hooks/settings.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/plugins/PlugSettingsPlugin.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Plugin from '../Plugin';
2+
import { before } from 'meld';
3+
import plugSettings from 'plug/store/settings';
4+
import extMirror from '../store/settings';
5+
6+
const PlugSettingsPlugin = Plugin.extend({
7+
name: 'Plug.dj Settings Sync',
8+
description: 'Mirrors plug.dj settings to the ExtPlug settings model, firing change events.',
9+
10+
enable() {
11+
this.advice = before(plugSettings, 'save', this.sync.bind(this));
12+
this.sync();
13+
},
14+
15+
disable() {
16+
this.advice.remove();
17+
this.advice = null;
18+
},
19+
20+
sync() {
21+
const newSettings = _.extend({}, plugSettings.settings);
22+
const muted = $('#volume .icon').hasClass('icon-volume-off');
23+
// when you mute a song using the volume button, plug.dj does not change the associated setting.
24+
// here we fake a volume of 0% anyway if the volume is muted, so ExtPlug modules can just
25+
// use volume throughout and have it work.
26+
if (newSettings.volume !== 0 && muted) {
27+
newSettings.volume = 0;
28+
}
29+
newSettings.muted = muted;
30+
extMirror.set(newSettings);
31+
}
32+
});
33+
34+
export default PlugSettingsPlugin;

src/store/settings.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
import _ from 'underscore';
2-
import plugSettings from 'plug/store/settings';
31
import Settings from '../models/Settings';
42

5-
const settings = new Settings();
6-
7-
function sync() {
8-
let newSettings = _.extend({}, plugSettings.settings);
9-
let muted = $('#volume .icon').hasClass('icon-volume-off');
10-
// when you mute a song using the volume button, plug.dj does not change the associated setting.
11-
// here we fake a volume of 0% anyway if the volume is muted, so ExtPlug modules can just
12-
// use volume throughout and have it work.
13-
if (newSettings.volume !== 0 && muted) {
14-
newSettings.volume = 0;
15-
}
16-
newSettings.muted = muted;
17-
settings.set(newSettings);
18-
}
19-
20-
settings.update = sync;
21-
22-
export default settings;
3+
export default new Settings();

0 commit comments

Comments
 (0)