This commit is contained in:
Mirco Wittrien 2020-11-11 00:36:02 +01:00
parent c3521d057c
commit beba94fa9c
1 changed files with 32 additions and 12 deletions

View File

@ -13,12 +13,13 @@ module.exports = (_ => {
"info": { "info": {
"name": "NotificationSounds", "name": "NotificationSounds",
"author": "DevilBro", "author": "DevilBro",
"version": "3.5.1", "version": "3.5.2",
"description": "Allow you to replace the native sounds of Discord with your own" "description": "Allow you to replace the native sounds of Discord with your own"
}, },
"changeLog": { "changeLog": {
"added": { "added": {
"Halloween": "Added discord's halloween call sound to the choices" "Halloween": "Added discord's halloween call sound to the choices",
"Global Volume": "Added global volume slider affecting all sounds"
} }
} }
}; };
@ -51,6 +52,7 @@ module.exports = (_ => {
stop() {} stop() {}
} : (([Plugin, BDFDB]) => { } : (([Plugin, BDFDB]) => {
var audios, choices, firedEvents; var audios, choices, firedEvents;
var volumes = {};
const removeAllKey = "REMOVE_ALL_BDFDB_DEVILBRO_DO_NOT_COPY"; const removeAllKey = "REMOVE_ALL_BDFDB_DEVILBRO_DO_NOT_COPY";
const defaultDevice = "default"; const defaultDevice = "default";
@ -168,7 +170,7 @@ module.exports = (_ => {
let audio = new Audio; let audio = new Audio;
audio.src = this._src; audio.src = this._src;
audio.onloadeddata = _ => { audio.onloadeddata = _ => {
audio.volume = Math.min((BDFDB.LibraryModules.MediaDeviceUtils.getOutputVolume() / 100) * (this._volume / 100), 1); audio.volume = Math.min((BDFDB.LibraryModules.MediaDeviceUtils.getOutputVolume() / 100) * (this._volume / 100) * (volumes.globalVolume / 100), 1);
BDFDB.LibraryModules.PlatformUtils.embedded && audio.setSinkId(currentDevice || defaultDevice); BDFDB.LibraryModules.PlatformUtils.embedded && audio.setSinkId(currentDevice || defaultDevice);
callback(audio); callback(audio);
}; };
@ -189,11 +191,19 @@ module.exports = (_ => {
choices = {}; choices = {};
firedEvents = {}; firedEvents = {};
this.defaults = {
volumes: {
globalVolume: {value:100, description:"Global Notification Sounds Volume"}
}
};
this.patchedModules = { this.patchedModules = {
after: { after: {
Shakeable: "render" Shakeable: "render"
} }
}; };
this.patchPriority = 10;
} }
onStart() { onStart() {
@ -421,6 +431,19 @@ module.exports = (_ => {
let settingsPanel, settingsItems = []; let settingsPanel, settingsItems = [];
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Settings",
collapseStates: collapseStates,
children: Object.keys(volumes).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Slider",
plugin: this,
keys: ["volumes", key],
basis: "50%",
label: this.defaults.volumes[key].description,
value: volumes[key]
}))
}));
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Add new Sound", title: "Add new Sound",
collapseStates: collapseStates, collapseStates: collapseStates,
@ -470,7 +493,7 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, {
style: {marginBottom: 1}, style: {marginBottom: 1},
onClick: _ => { onClick: _ => {
for (let input of settingsPanel.querySelectorAll(".input-newsound " + BDFDB.dotCN.input)) if (!input.value || input.value.length == 0 || input.value.trim().length == 0) return BDFDB.NotificationUtils.toast("Fill out all fields to add a new sound.", {type:"danger"}); for (let input of settingsPanel.querySelectorAll(".input-newsound " + BDFDB.dotCN.input)) if (!input.value || input.value.length == 0 || input.value.trim().length == 0) return BDFDB.NotificationUtils.toast("Fill out all fields to add a new sound", {type:"danger"});
let category = settingsPanel.querySelector(".input-category " + BDFDB.dotCN.input).value.trim(); let category = settingsPanel.querySelector(".input-category " + BDFDB.dotCN.input).value.trim();
let sound = settingsPanel.querySelector(".input-sound " + BDFDB.dotCN.input).value.trim(); let sound = settingsPanel.querySelector(".input-sound " + BDFDB.dotCN.input).value.trim();
let source = settingsPanel.querySelector(".input-source " + BDFDB.dotCN.input).value.trim(); let source = settingsPanel.querySelector(".input-source " + BDFDB.dotCN.input).value.trim();
@ -479,10 +502,10 @@ module.exports = (_ => {
let type = response.headers["content-type"]; let type = response.headers["content-type"];
if (type && (type.indexOf("octet-stream") > -1 || type.indexOf("audio") > -1 || type.indexOf("video") > -1)) return successSavedAudio({category, sound, source}); if (type && (type.indexOf("octet-stream") > -1 || type.indexOf("audio") > -1 || type.indexOf("video") > -1)) return successSavedAudio({category, sound, source});
} }
BDFDB.NotificationUtils.toast("Use a valid direct link to a video or audio source. They usually end on something like .mp3, .mp4 or .wav.", {type:"danger"}); BDFDB.NotificationUtils.toast("Use a valid direct link to a video or audio source, they usually end on something like .mp3, .mp4 or .wav", {type:"danger"});
}); });
else BDFDB.LibraryRequires.fs.readFile(source, (error, response) => { else BDFDB.LibraryRequires.fs.readFile(source, (error, response) => {
if (error) BDFDB.NotificationUtils.toast("Could not fetch file. Please make sure the file exists.", {type:"danger"}); if (error) BDFDB.NotificationUtils.toast("Could not fetch file. Please make sure the file exists", {type:"danger"});
else return successSavedAudio({category, sound, source:`data:audio/mpeg;base64,${response.toString("base64")}`}); else return successSavedAudio({category, sound, source:`data:audio/mpeg;base64,${response.toString("base64")}`});
}); });
}, },
@ -551,7 +574,7 @@ module.exports = (_ => {
}), }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
grow: 0, grow: 0,
shrink: 0, shrink: 1,
basis: "25%", basis: "25%",
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, {
style: {marginBottom: 1}, style: {marginBottom: 1},
@ -580,7 +603,7 @@ module.exports = (_ => {
this.loadChoices(); this.loadChoices();
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
}); });
else BDFDB.NotificationUtils.toast("No sounds to delete.", {type:"danger"}); else BDFDB.NotificationUtils.toast("No sounds to delete", {type:"danger"});
} }
}, },
children: BDFDB.LanguageUtils.LanguageStrings.DELETE children: BDFDB.LanguageUtils.LanguageStrings.DELETE
@ -605,6 +628,7 @@ module.exports = (_ => {
forceUpdateAll () { forceUpdateAll () {
repatchIncoming = true; repatchIncoming = true;
createdAudios["call_calling"] = BDFDB.LibraryModules.SoundUtils.createSound("call_calling"); createdAudios["call_calling"] = BDFDB.LibraryModules.SoundUtils.createSound("call_calling");
volumes = BDFDB.DataUtils.get(this, "volumes");
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
} }
@ -637,10 +661,6 @@ module.exports = (_ => {
let loadedChoices = BDFDB.DataUtils.load(this, "choices"); let loadedChoices = BDFDB.DataUtils.load(this, "choices");
for (let type in types) { for (let type in types) {
let choice = loadedChoices[type] || {}, soundFound = false; let choice = loadedChoices[type] || {}, soundFound = false;
// REMOVE 06.10.2020
choice.sound = choice.song || choice.sound;
delete choice.song;
delete choice.src;
for (let category in audios) if (choice.category == category) for (let sound in audios[category]) if (choice.sound == sound) { for (let category in audios) if (choice.category == category) for (let sound in audios[category]) if (choice.sound == sound) {
soundFound = true; soundFound = true;
break; break;