Add an option to disable toasts

This commit is contained in:
Samuel Elliott 2018-08-10 13:37:47 +01:00
parent 87ec7d8773
commit 4970214324
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 23 additions and 0 deletions

View File

@ -93,6 +93,13 @@
"hint": "When this is enabled you can use Ctrl/Cmd + B to open the BetterDiscord settings menu.",
"value": false,
"disabled": false
},
{
"id": "enable-toasts",
"type": "bool",
"text": "Enable Toasts",
"hint": "Allows plugins to show toasts.",
"value": true
}
]
}

View File

@ -8,6 +8,8 @@
* LICENSE file in the root directory of this source tree.
*/
import { Settings } from 'modules';
let toasts = 0;
export default class Toasts {
@ -24,6 +26,8 @@ export default class Toasts {
* @returns {Promise} This promise resolves when the toast is removed from the DOM.
*/
static async push(message, options = {}) {
if (!this.enabled) return;
const {type = 'basic', icon, additionalClasses, timeout = 3000} = options;
const toast = {id: toasts++, message, type, icon, additionalClasses, closing: false};
this.stack.push(toast);
@ -72,4 +76,16 @@ export default class Toasts {
return this._stack || (this._stack = []);
}
static get setting() {
return Settings.getSetting('ui', 'default', 'enable-toasts');
}
static get enabled() {
return this.setting.value;
}
static set enabled(enabled) {
this.setting.value = enabled;
}
}