diff --git a/plugins/login-sound/manifest.json b/plugins/login-sound/manifest.json new file mode 100644 index 0000000..0e27449 --- /dev/null +++ b/plugins/login-sound/manifest.json @@ -0,0 +1,14 @@ +{ + "name": "LoginSound", + "description": "ディスコード!", + "authors": [ + { + "name": "Rico040", + "id": "619474349845643275" + } + ], + "main": "src/index.ts", + "vendetta": { + "icon": "ic_voice_channel_24px" + } +} \ No newline at end of file diff --git a/plugins/login-sound/src/index.ts b/plugins/login-sound/src/index.ts new file mode 100644 index 0000000..626aaf4 --- /dev/null +++ b/plugins/login-sound/src/index.ts @@ -0,0 +1,49 @@ +import { ReactNative } from "@vendetta/metro/common" + +const { DCDSoundManager } = ReactNative.NativeModules; + +const soundUrl = "https://raw.githubusercontent.com/Rico040/meine-themen/master/sounds/discordo-discord.mp3"; +const soundId = 6970; +let soundDuration = -1; + +// Function to prepare the sound +const prepareSound = function () { + return new Promise(function (resolve) { + DCDSoundManager.prepare(soundUrl, "notification", soundId, function (error, sound) { + resolve(sound); + }); + }); +}; + +// Variables to manage sound playback state +let timeoutId = null; +let isPlaying = false; + +// Function to play the sound, thanks to moyai obfuscated code +async function playSound() { + if (isPlaying) { + if (timeoutId != null) clearTimeout(timeoutId); + DCDSoundManager.stop(soundId); + isPlaying = false; + } + isPlaying = true; + await DCDSoundManager.play(soundId); + timeoutId = setTimeout(function () { + isPlaying = false; + DCDSoundManager.stop(soundId); + timeoutId = null; + }, soundDuration); +} +let isPrepared = false; + +export default { + onLoad: () => { + if (!isPrepared) { + prepareSound().then(function (sound) { + isPrepared = true; + soundDuration = sound.duration; + playSound() + }); + } + } +} \ No newline at end of file