-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (50 loc) · 2.15 KB
/
index.js
File metadata and controls
58 lines (50 loc) · 2.15 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
const { Plugin } = require('powercord/entities');
const { inject, uninject } = require('powercord/injector');
const { getModuleByDisplayName, i18n: { Messages }, React } = require('powercord/webpack');
const Settings = require('./Settings');
const defaultMaxVolume = 400;
const defaultMaxStreamVolume = 400;
module.exports = class CustomVolumeRange extends Plugin {
startPlugin() {
this.adjustVolumeSlider();
powercord.api.settings.registerSettings('custom-volume-range_settings', {
category: this.entityID,
label: 'Custom Volume Range',
render: props => React.createElement(Settings, {
...props,
defaultMaxVolume,
defaultMaxStreamVolume
})
});
}
adjustVolumeSlider() {
const Slider = getModuleByDisplayName('Slider', false);
// pluginSettings must be a separate variable because 'this' refers to the module we inject into
let pluginSettings = this.settings;
inject('custom-volume-range_slider', Slider.prototype, 'render', function (args) {
if (this.props) {
let maxVolume = 0;
// only change range if label is 'User Volume' or 'Stream Volume'
switch (this.props['aria-label']) {
case Messages.USER_VOLUME:
maxVolume = pluginSettings.get('maxAdjustableVolume', defaultMaxVolume);
break;
case Messages.STREAM_VOLUME:
maxVolume = pluginSettings.get('maxAdjustableStreamVolume', defaultMaxStreamVolume);
break;
default:
return args;
}
this.props.maxValue = maxVolume;
this.state.value = this.state.initialValueProp;
this.state.max = maxVolume;
this.state.range = this.state.max;
}
return args;
}, true);
}
pluginWillUnload() {
uninject('custom-volume-range_slider');
powercord.api.settings.unregisterSettings('custom-volume-range_settings');
}
};