mirror of
https://github.com/MathMan05/Fermi.git
synced 2026-10-23 17:12:25 +00:00
notification sound fixes
This commit is contained in:
1 parent
54e1fb6071
commit
ea986b5791
5 files changed
+53
-22
No files matched your search
@@ -22,10 +22,10 @@ export class Audio {
|
||||
}
|
||||
return new Audio(name, tracks);
|
||||
}
|
||||
async play() {
|
||||
async play(volume: number) {
|
||||
for (const thing of this.tracks) {
|
||||
if (thing instanceof Track) {
|
||||
thing.play();
|
||||
thing.play(volume);
|
||||
} else {
|
||||
await new Promise((res) => setTimeout(res, thing));
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ export class Track {
|
||||
}
|
||||
return new Track(play2);
|
||||
}
|
||||
async play() {
|
||||
async play(volume: number) {
|
||||
for (const thing of this.seq) {
|
||||
if (thing instanceof AVoice) {
|
||||
thing.playL();
|
||||
thing.playL(volume);
|
||||
} else {
|
||||
await new Promise((res) => setTimeout(res, thing));
|
||||
}
|
||||
|
||||
@@ -82,14 +82,17 @@ class AVoice {
|
||||
}
|
||||
play(): void {
|
||||
if (this.playing) {
|
||||
console.warn("playing?");
|
||||
return;
|
||||
}
|
||||
this.source.connect(this.gainNode);
|
||||
this.playing = true;
|
||||
}
|
||||
playL() {
|
||||
playL(volume: number) {
|
||||
this.gainNode.gain.value *= volume;
|
||||
this.play();
|
||||
setTimeout(() => {
|
||||
this.gainNode.gain.value /= volume;
|
||||
this.stop();
|
||||
}, this.length);
|
||||
}
|
||||
|
||||
+44
-17
@@ -184,9 +184,13 @@ class Localuser {
|
||||
}
|
||||
onswap?: (l: Localuser) => void;
|
||||
constructor(userinfo: Specialuser | -1) {
|
||||
Play.playURL("/audio/sounds.jasf").then((_) => {
|
||||
this.play = _;
|
||||
});
|
||||
const func = () => {
|
||||
Play.playURL("/audio/sounds.jasf").then((_) => {
|
||||
this.play = _;
|
||||
});
|
||||
document.removeEventListener("click", func);
|
||||
};
|
||||
document.addEventListener("click", func);
|
||||
if (userinfo === -1) {
|
||||
this.rights = new Rights("");
|
||||
return;
|
||||
@@ -1648,23 +1652,33 @@ class Localuser {
|
||||
};
|
||||
const sounds = [...AVoice.sounds, I18n.localuser.customSound()];
|
||||
const initIndex = sounds.indexOf(this.getNotificationSound());
|
||||
tas
|
||||
.addSelect(
|
||||
I18n.getTranslation("localuser.notisound"),
|
||||
(index) => {
|
||||
this.setNotificationSound(sounds[index]);
|
||||
},
|
||||
sounds,
|
||||
{defaultIndex: initIndex},
|
||||
)
|
||||
.watchForChange((index) => {
|
||||
initArea(index);
|
||||
this.playSound(sounds[index]);
|
||||
});
|
||||
const select = tas.addSelect(
|
||||
I18n.localuser.notisound(),
|
||||
(index) => {
|
||||
this.setNotificationSound(sounds[index]);
|
||||
},
|
||||
sounds,
|
||||
{defaultIndex: initIndex},
|
||||
);
|
||||
select.watchForChange((index) => {
|
||||
initArea(index);
|
||||
this.playSound(sounds[index]);
|
||||
});
|
||||
const input = document.createElement("input");
|
||||
input.type = "range";
|
||||
input.value = this.getNotiVolume() + "";
|
||||
input.min = "0";
|
||||
input.max = "100";
|
||||
input.onchange = () => {
|
||||
this.setNotificationVolume(+input.value);
|
||||
this.playSound(sounds[select.index]);
|
||||
};
|
||||
|
||||
const area = document.createElement("div");
|
||||
initArea(initIndex);
|
||||
tas.addHTMLArea(area);
|
||||
tas.addText(I18n.notiVolume());
|
||||
tas.addHTMLArea(input);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -3356,21 +3370,34 @@ class Localuser {
|
||||
this.urlsToRefresh.push([url, res]);
|
||||
});
|
||||
}
|
||||
getNotiVolume(): number {
|
||||
const userinfos = getBulkInfo();
|
||||
return userinfos.preferences.volume || 100;
|
||||
}
|
||||
setNotificationVolume(volume: number) {
|
||||
const userinfos = getBulkInfo();
|
||||
userinfos.preferences.volume = volume;
|
||||
localStorage.setItem("userinfos", JSON.stringify(userinfos));
|
||||
}
|
||||
setNotificationSound(sound: string) {
|
||||
const userinfos = getBulkInfo();
|
||||
userinfos.preferences.notisound = sound;
|
||||
localStorage.setItem("userinfos", JSON.stringify(userinfos));
|
||||
}
|
||||
playSound(name = this.getNotificationSound()) {
|
||||
const volume = this.getNotiVolume();
|
||||
if (this.play) {
|
||||
const voice = this.play.audios.get(name);
|
||||
if (voice) {
|
||||
voice.play();
|
||||
voice.play(volume / 100);
|
||||
} else if (this.perminfo.sound && this.perminfo.sound.cSound) {
|
||||
const audio = document.createElement("audio");
|
||||
audio.volume = volume / 100;
|
||||
audio.src = this.perminfo.sound.cSound;
|
||||
audio.play().catch();
|
||||
}
|
||||
} else {
|
||||
console.error("play object is missing");
|
||||
}
|
||||
}
|
||||
getNotificationSound() {
|
||||
|
||||
@@ -381,6 +381,7 @@
|
||||
"totalTime": "$2: $1ms",
|
||||
"traces": "$1 ($2ms) $3"
|
||||
},
|
||||
"notiVolume":"Notification volume:",
|
||||
"localuser": {
|
||||
"trace": "Traces",
|
||||
"install": "Install",
|
||||
|
||||
Reference in new issue
Block a user