Coloured text refactor to use new builtin base
This commit is contained in:
parent
c11aa205a3
commit
62b7679408
|
@ -15,37 +15,40 @@ import { Settings, Patcher, MonkeyPatch, Reflection, ReactComponents, DiscordApi
|
|||
|
||||
export default new class ColoredText extends BuiltinModule {
|
||||
|
||||
get moduleName() { return 'ColoredText' }
|
||||
|
||||
get settingPath() { return ['ui', 'default', 'colored-text'] }
|
||||
|
||||
get intensityPath() { return ['ui', 'advanced', 'colored-text-intensity'] }
|
||||
|
||||
get intensitySetting() { return Settings.getSetting(...this.intensityPath) }
|
||||
|
||||
get intensity() { return 100 - this.intensitySetting.value }
|
||||
|
||||
get defaultColor() { return DiscordApi.UserSettings.theme == 'light' ? '#747f8d' : '#dcddde' }
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._intensityUpdated = this._intensityUpdated.bind(this);
|
||||
this.injectColoredText = this.injectColoredText.bind(this);
|
||||
}
|
||||
|
||||
get settingPath() {
|
||||
return ['ui', 'default', 'colored-text'];
|
||||
async enabled(e) {
|
||||
this.intensitySetting.off('setting-updated', this._intensityUpdated);
|
||||
this.intensitySetting.on('setting-updated', this._intensityUpdated);
|
||||
}
|
||||
|
||||
get intensityPath() {
|
||||
return ['ui', 'advanced', 'colored-text-intensity'];
|
||||
}
|
||||
|
||||
get intensitySetting() {
|
||||
return Settings.getSetting(...this.intensityPath);
|
||||
}
|
||||
|
||||
get intensity() {
|
||||
return 100 - this.intensitySetting.value;
|
||||
disabled(e) {
|
||||
this.intensitySetting.off('setting-updated', this._intensityUpdated);
|
||||
}
|
||||
|
||||
_intensityUpdated() {
|
||||
this.MessageContent.forceUpdateAll();
|
||||
}
|
||||
|
||||
async enabled(e) {
|
||||
if (Patcher.getPatchesByCaller('BD:ColoredText').length) return;
|
||||
this.intensitySetting.on('setting-updated', this._intensityUpdated);
|
||||
async applyPatches() {
|
||||
if (this.patches.length) return;
|
||||
this.MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector });
|
||||
MonkeyPatch('BD:ColoredText', this.MessageContent.component.prototype).after('render', this.injectColoredText);
|
||||
this.patch(this.MessageContent.component.prototype, 'render', this.injectColoredText);
|
||||
this.MessageContent.forceUpdateAll();
|
||||
}
|
||||
|
||||
|
@ -55,14 +58,4 @@ export default new class ColoredText extends BuiltinModule {
|
|||
const roleColor = thisObject.props.message.colorString;
|
||||
if (markup && roleColor) markup.props.style = {color: TinyColor.mix(roleColor, this.defaultColor, this.intensity)};
|
||||
}
|
||||
|
||||
get defaultColor() {
|
||||
return DiscordApi.UserSettings.theme == 'light' ? '#747f8d' : '#dcddde';
|
||||
}
|
||||
|
||||
disabled(e) {
|
||||
Patcher.unpatchAll('BD:ColoredText');
|
||||
this.intensitySetting.off('setting-updated', this._intensityUpdated);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue