Skip to content

Commit

Permalink
Merge pull request #12 from BluSpring/master
Browse files Browse the repository at this point in the history
Fix message sounds
  • Loading branch information
AAGaming committed Mar 18, 2022
2 parents 7e88d21 + 65b40b7 commit 78f0665
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports = class NotificationSounds extends Plugin {
uninject('ns-createSound');
uninject('ns-call');
uninject('ns-isDisabled');
uninject('ns-showNotificationPre');
uninject('ns-showNotificationPost');
powercord.api.settings.unregisterSettings('notif-sound-changer');
}

Expand All @@ -34,6 +36,7 @@ module.exports = class NotificationSounds extends Plugin {
const isDisabled = await getModule([ 'isSoundDisabled' ]);
const getCurrentUser = await getModule([ 'getCurrentUser' ]);
const { getCalls } = await getModule([ 'getCalls' ]);
const showNotification = await getModule([ 'showNotification' ]);

const settings = powercord.api.settings.buildCategoryObject('notif-sound-changer'); // This fixes... quite a lot for whatever reason

Expand All @@ -56,16 +59,43 @@ module.exports = class NotificationSounds extends Plugin {
audio.play();
playing[type] = audio;
};

inject('ns-playSound', SoundPlayer, 'playSound', (e) => {
this.custom = settings.get('notifsounds', false);
console.log(e);
//console.log(e);
if (this.custom[e[0]] && this.custom[e[0]].url) {
play(e[0]);
return false;
}
return e;
}, true);

// Temporary and ungodly workaround for message notifications not playing

// Prevent message sounds from playing by overwriting the 4th argument.
inject('ns-showNotificationPre', showNotification, 'showNotification', (args) => {
if (args.length >= 4) {
const info = args[3];
if (!!info.sound && info.sound.startsWith('message') && this.custom['message1'] && !info.isReplacedByNSC) {
return [ args[0], args[1], args[2], Object.assign(info, { playSoundIfDisabled: false, sound: null, isReplacedByNSC: true }) ];
}
}

return args;
}, true);

// Now play the sound provided by NSC.
inject('ns-showNotificationPost', showNotification, 'showNotification', (args, res) => {
if (args.length >= 4) {
const info = args[3];
if (info.sound == null && info.isReplacedByNSC) {
play('message1');
}
}

return res;
}, false);

CallHandler.terminate();
/*
* inject('ns-call-reset', CallHandler, 'handleRingUpdate', (_, e) => {
Expand Down

0 comments on commit 78f0665

Please sign in to comment.