volume max for web remote so I don't go deaf

This commit is contained in:
Maikiwi 2022-02-08 22:02:05 -08:00
parent 748db1030a
commit 308193061d
4 changed files with 27 additions and 1 deletions

View file

@ -61,6 +61,9 @@ export class wsapi {
electron.ipcMain.on('wsapi-returnLyrics', (_event: any, arg: any) => { electron.ipcMain.on('wsapi-returnLyrics', (_event: any, arg: any) => {
this.returnLyrics(JSON.parse(arg)); this.returnLyrics(JSON.parse(arg));
}); });
electron.ipcMain.on('wsapi-returnvolumeMax', (_event: any, arg: any) => {
this.returnmaxVolume(JSON.parse(arg));
});
this.wss = new WebSocketServer({ this.wss = new WebSocketServer({
port: this.port, port: this.port,
perMessageDeflate: { perMessageDeflate: {
@ -162,6 +165,10 @@ export class wsapi {
this._win.webContents.executeJavaScript(`MusicKit.getInstance().stop()`); this._win.webContents.executeJavaScript(`MusicKit.getInstance().stop()`);
response.message = "Stopped"; response.message = "Stopped";
break; break;
case "volumeMax":
this._win.webContents.executeJavaScript(`wsapi.getmaxVolume()`);
response.message = "maxVolume";
break;
case "volume": case "volume":
this._win.webContents.executeJavaScript(`MusicKit.getInstance().volume = ${parseFloat(data.volume)}`); this._win.webContents.executeJavaScript(`MusicKit.getInstance().volume = ${parseFloat(data.volume)}`);
response.message = "Volume"; response.message = "Volume";
@ -295,4 +302,11 @@ export class wsapi {
client.send(JSON.stringify(response)); client.send(JSON.stringify(response));
}); });
} }
returnmaxVolume(vol: any) {
const response: standardResponse = {status: 0, data: vol, message: "OK", type: "maxVolume"};
this.clients.forEach(function each(client: any) {
client.send(JSON.stringify(response));
});
}
} }

View file

@ -107,5 +107,8 @@ const wsapi = {
}else{ }else{
MusicKit.getInstance().repeatMode = 0 MusicKit.getInstance().repeatMode = 0
} }
},
getmaxVolume() {
ipcRenderer.send('wsapi-returnvolumeMax',JSON.stringify(app.cfg.audio.maxVolume));
} }
} }

View file

@ -13,6 +13,7 @@ var app = new Vue({
player: { player: {
currentMediaItem: {}, currentMediaItem: {},
songActions: false, songActions: false,
maxVolume: 1,
lyrics: {}, lyrics: {},
lyricsMediaItem: {}, lyricsMediaItem: {},
lyricsDebug: { lyricsDebug: {
@ -161,6 +162,11 @@ var app = new Vue({
volume: volume volume: volume
})); }));
}, },
getVolumeMax() {
socket.send(JSON.stringify({
action: "volumeMax",
}));
},
getQueue() { getQueue() {
socket.send(JSON.stringify({ socket.send(JSON.stringify({
action: "get-queue" action: "get-queue"
@ -570,6 +576,9 @@ var app = new Vue({
self.updatePlaybackState(response.data) self.updatePlaybackState(response.data)
} }
break; break;
case "maxVolume":
this.player.maxVolume = response.data;
break;
} }
// console.log(e.data); // console.log(e.data);
} }

View file

@ -172,7 +172,7 @@
<div class="player-volume-glyph decrease"></div> <div class="player-volume-glyph decrease"></div>
</div> </div>
<div class="col"> <div class="col">
<input type="range" class="web-slider volume-slider" max="1" min="0" step="0.01" <input type="range" class="web-slider volume-slider" :max="getVolumeMax()" min="0" step="0.01"
@input="setVolume($event.target.value)" :value="player.currentMediaItem.volume"> @input="setVolume($event.target.value)" :value="player.currentMediaItem.volume">
</div> </div>
<div class="col-auto"> <div class="col-auto">