mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
migrate from remote to ipc
This commit is contained in:
15
plugins/quality-changer/back.js
Normal file
15
plugins/quality-changer/back.js
Normal file
@ -0,0 +1,15 @@
|
||||
const { ipcMain, dialog } = require("electron");
|
||||
|
||||
module.exports = () => {
|
||||
ipcMain.handle('qualityChanger', async (_, qualityLabels, currentIndex) => {
|
||||
return await dialog.showMessageBox({
|
||||
type: "question",
|
||||
buttons: qualityLabels,
|
||||
defaultId: currentIndex,
|
||||
title: "Choose Video Quality",
|
||||
message: "Choose Video Quality:",
|
||||
detail: `Current Quality: ${qualityLabels[currentIndex]}`,
|
||||
cancelId: -1
|
||||
})
|
||||
})
|
||||
};
|
||||
@ -1,5 +1,5 @@
|
||||
const { ElementFromFile, templatePath } = require("../utils");
|
||||
const { dialog } = require('@electron/remote');
|
||||
const { ipcRenderer } = require("electron");
|
||||
|
||||
function $(selector) { return document.querySelector(selector); }
|
||||
|
||||
@ -21,21 +21,15 @@ function setup(event) {
|
||||
if (api.getPlayerState() === 2) api.playVideo();
|
||||
else if (api.getPlayerState() === 1) api.pauseVideo();
|
||||
|
||||
const currentIndex = api.getAvailableQualityLevels().indexOf(api.getPlaybackQuality())
|
||||
const qualityLevels = api.getAvailableQualityLevels();
|
||||
|
||||
dialog.showMessageBox({
|
||||
type: "question",
|
||||
buttons: api.getAvailableQualityLabels(),
|
||||
defaultId: currentIndex,
|
||||
title: "Choose Video Quality",
|
||||
message: "Choose Video Quality:",
|
||||
detail: `Current Quality: ${api.getAvailableQualityLabels()[currentIndex]}`,
|
||||
cancelId: -1
|
||||
}).then((promise) => {
|
||||
const currentIndex = qualityLevels.indexOf(api.getPlaybackQuality());
|
||||
|
||||
ipcRenderer.invoke('qualityChanger', api.getAvailableQualityLabels(), currentIndex).then(promise => {
|
||||
if (promise.response === -1) return;
|
||||
const newQuality = api.getAvailableQualityLevels()[promise.response];
|
||||
const newQuality = qualityLevels[promise.response];
|
||||
api.setPlaybackQualityRange(newQuality);
|
||||
api.setPlaybackQuality(newQuality)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user