From 34fd1b378fc045560e2923da1aad1a25c92dbfb1 Mon Sep 17 00:00:00 2001 From: Naz Date: Sun, 13 Mar 2022 03:57:12 +0800 Subject: [PATCH 1/4] Fix message sound --- index.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/index.js b/index.js index c210762..7de586c 100644 --- a/index.js +++ b/index.js @@ -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'); } @@ -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 @@ -56,6 +59,7 @@ 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); @@ -66,6 +70,33 @@ module.exports = class NotificationSounds extends Plugin { 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) => { + console.log(args) + if (args.length >= 4) { + const info = args[3]; + if (info.sound.startsWith('message') && this.custom['message1']) { + 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) => { From a6350171e4a2b01bc48ecc473e3d1dfc9a0638af Mon Sep 17 00:00:00 2001 From: Naz Date: Sun, 13 Mar 2022 03:59:19 +0800 Subject: [PATCH 2/4] Forgot to comment out the log thing, oops --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7de586c..5d6f856 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,7 @@ module.exports = class NotificationSounds extends Plugin { 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; From ef1a39d1d78e4f8a502ca0ced13c53aa418bb2ad Mon Sep 17 00:00:00 2001 From: Naz Date: Sun, 13 Mar 2022 04:12:35 +0800 Subject: [PATCH 3/4] I keep forgetting to remove console.log --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 5d6f856..fa036f8 100644 --- a/index.js +++ b/index.js @@ -74,7 +74,6 @@ module.exports = class NotificationSounds extends Plugin { // Prevent message sounds from playing by overwriting the 4th argument. inject('ns-showNotificationPre', showNotification, 'showNotification', (args) => { - console.log(args) if (args.length >= 4) { const info = args[3]; if (info.sound.startsWith('message') && this.custom['message1']) { From 65b40b729ca5d7f2406dd7b986aff264754c0a04 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 16 Mar 2022 13:59:04 +0800 Subject: [PATCH 4/4] Quick workaround to an error --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fa036f8..28351f9 100644 --- a/index.js +++ b/index.js @@ -76,7 +76,7 @@ module.exports = class NotificationSounds extends Plugin { inject('ns-showNotificationPre', showNotification, 'showNotification', (args) => { if (args.length >= 4) { const info = args[3]; - if (info.sound.startsWith('message') && this.custom['message1']) { + 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 }) ]; } }