generated from vendetta-mod/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "LoginSound", | ||
"description": "ディスコード!", | ||
"authors": [ | ||
{ | ||
"name": "Rico040", | ||
"id": "619474349845643275" | ||
} | ||
], | ||
"main": "src/index.ts", | ||
"vendetta": { | ||
"icon": "ic_voice_channel_24px" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}); | ||
} | ||
} | ||
} |