Merge branch 'local-upstream/master' into use-ToastXML

This commit is contained in:
Araxeus
2023-01-16 21:36:47 +02:00
11 changed files with 89 additions and 6966 deletions

View File

@ -1,15 +1,21 @@
const { ipcMain, dialog } = require("electron");
const { ipcMain } = require("electron");
module.exports = () => {
ipcMain.handle('captionsSelector', async (_, captionLabels, currentIndex) => {
return await dialog.showMessageBox({
type: "question",
buttons: captionLabels,
defaultId: currentIndex,
title: "Choose Caption",
message: "Choose Caption:",
detail: `Current Caption: ${captionLabels[currentIndex]}`,
cancelId: -1
})
})
const prompt = require("custom-electron-prompt");
const promptOptions = require("../../providers/prompt-options");
module.exports = (win) => {
ipcMain.handle("captionsSelector", async (_, captionLabels, currentIndex) => {
return await prompt(
{
title: "Choose Caption",
label: `Current Caption: ${captionLabels[currentIndex] || "None"}`,
type: "select",
value: currentIndex,
selectOptions: captionLabels,
resizable: true,
...promptOptions(),
},
win
);
});
};

View File

@ -4,7 +4,7 @@ const { ipcRenderer } = require("electron");
function $(selector) { return document.querySelector(selector); }
const captionsSettingsButton = ElementFromFile(
templatePath(__dirname, "captionsSettingsTemplate.html")
templatePath(__dirname, "captions-settings-template.html")
);
module.exports = (options) => {
@ -28,33 +28,33 @@ function setup(event, options) {
$(".right-controls-buttons").append(captionsSettingsButton);
captionsSettingsButton.onclick = function chooseQuality() {
captionsSettingsButton.onclick = async () => {
api.loadModule("captions");
const captionTrackList = api.getOption("captions", "tracklist");
if (captionTrackList?.length) {
const currentCaptionTrack = api.getOption("captions", "track");
const currentIndex = captionTrackList.indexOf(captionTrackList.find(track => track.languageCode === currentCaptionTrack.languageCode));
let currentIndex = !currentCaptionTrack ?
null :
captionTrackList.indexOf(captionTrackList.find(track => track.languageCode === currentCaptionTrack.languageCode));
const captionLabels = [
...captionTrackList.map(track => track.displayName),
'None'
];
ipcRenderer.invoke('captionsSelector', captionLabels, currentIndex).then(promise => {
if (promise.response === -1) return;
currentIndex = await ipcRenderer.invoke('captionsSelector', captionLabels, currentIndex)
if (currentIndex === null) return;
const newCaptions = captionTrackList[promise.response];
if (newCaptions) {
api.loadModule("captions");
api.setOption("captions", "track", { languageCode: newCaptions.languageCode });
} else {
api.unloadModule("captions");
}
const newCaptions = captionTrackList[currentIndex];
if (newCaptions) {
api.setOption("captions", "track", { languageCode: newCaptions.languageCode });
} else {
api.setOption("captions", "track", {});
}
setTimeout(() => api.playVideo());
});
setTimeout(() => api.playVideo());
}
}
}

View File

@ -5,6 +5,7 @@ const registerCallback = require("../../providers/song-info");
const secToMilisec = t => Math.round(Number(t) * 1e3);
const data = {
cover: '',
cover_url: '',
title: '',
artists: [],
@ -43,6 +44,7 @@ module.exports = async (win) => {
data.duration = secToMilisec(songInfo.songDuration)
data.progress = secToMilisec(songInfo.elapsedSeconds)
data.cover = songInfo.imageSrc;
data.cover_url = songInfo.imageSrc;
data.album_url = songInfo.imageSrc;
data.title = songInfo.title;