mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Use custom-electron-prompt in caption selector
This commit is contained in:
@ -1,15 +1,21 @@
|
|||||||
const { ipcMain, dialog } = require("electron");
|
const { ipcMain } = require("electron");
|
||||||
|
|
||||||
module.exports = () => {
|
const prompt = require("custom-electron-prompt");
|
||||||
ipcMain.handle('captionsSelector', async (_, captionLabels, currentIndex) => {
|
const promptOptions = require("../../providers/prompt-options");
|
||||||
return await dialog.showMessageBox({
|
|
||||||
type: "question",
|
module.exports = (win) => {
|
||||||
buttons: captionLabels,
|
ipcMain.handle("captionsSelector", async (_, captionLabels, currentIndex) => {
|
||||||
defaultId: currentIndex,
|
return await prompt(
|
||||||
|
{
|
||||||
title: "Choose Caption",
|
title: "Choose Caption",
|
||||||
message: "Choose Caption:",
|
label: `Current Caption: ${captionLabels[currentIndex] || "None"}`,
|
||||||
detail: `Current Caption: ${captionLabels[currentIndex]}`,
|
type: "select",
|
||||||
cancelId: -1
|
value: currentIndex,
|
||||||
})
|
selectOptions: captionLabels,
|
||||||
})
|
resizable: true,
|
||||||
|
...promptOptions(),
|
||||||
|
},
|
||||||
|
win
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,33 +28,33 @@ function setup(event, options) {
|
|||||||
|
|
||||||
$(".right-controls-buttons").append(captionsSettingsButton);
|
$(".right-controls-buttons").append(captionsSettingsButton);
|
||||||
|
|
||||||
captionsSettingsButton.onclick = function chooseQuality() {
|
captionsSettingsButton.onclick = async () => {
|
||||||
api.loadModule("captions");
|
api.loadModule("captions");
|
||||||
|
|
||||||
const captionTrackList = api.getOption("captions", "tracklist");
|
const captionTrackList = api.getOption("captions", "tracklist");
|
||||||
|
|
||||||
if (captionTrackList?.length) {
|
if (captionTrackList?.length) {
|
||||||
const currentCaptionTrack = api.getOption("captions", "track");
|
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 = [
|
const captionLabels = [
|
||||||
...captionTrackList.map(track => track.displayName),
|
...captionTrackList.map(track => track.displayName),
|
||||||
'None'
|
'None'
|
||||||
];
|
];
|
||||||
|
|
||||||
ipcRenderer.invoke('captionsSelector', captionLabels, currentIndex).then(promise => {
|
currentIndex = await ipcRenderer.invoke('captionsSelector', captionLabels, currentIndex)
|
||||||
if (promise.response === -1) return;
|
if (currentIndex === null) return;
|
||||||
|
|
||||||
const newCaptions = captionTrackList[promise.response];
|
const newCaptions = captionTrackList[currentIndex];
|
||||||
if (newCaptions) {
|
if (newCaptions) {
|
||||||
api.loadModule("captions");
|
|
||||||
api.setOption("captions", "track", { languageCode: newCaptions.languageCode });
|
api.setOption("captions", "track", { languageCode: newCaptions.languageCode });
|
||||||
} else {
|
} else {
|
||||||
api.unloadModule("captions");
|
api.setOption("captions", "track", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => api.playVideo());
|
setTimeout(() => api.playVideo());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user