This commit is contained in:
Araxeus
2021-04-17 15:03:19 +03:00
parent 49698ea669
commit 12a2517697
3 changed files with 27 additions and 28 deletions

View File

@ -1,9 +1,9 @@
/* /*
this is used to determine if plugin is actually active This is used to determine if plugin is actually active
(not if its only enabled in options) (not if its only enabled in options)
*/ */
let enabled = false; let enabled = false;
module.exports = (win,options) => { module.exports = () => {
enabled = true; enabled = true;
}; };

View File

@ -3,9 +3,9 @@ const { ipcRenderer } = require("electron");
module.exports = (options) => { module.exports = (options) => {
setPlaybarOnwheel(options); setPlaybarOnwheel(options);
setObserver(options); setupObserver(options);
firstRun(options);
setupArrowShortcuts(options); setupArrowShortcuts(options);
firstRun(options);
}; };
function saveVolume(volume, options) { function saveVolume(volume, options) {
@ -45,11 +45,16 @@ function setPlaybarOnwheel(options) {
} }
function setupArrowShortcuts(options) { function setupArrowShortcuts(options) {
//change options from renderer to keep sync // Register shortcuts if enabled
if (options.arrowsShortcut) {
addListener();
}
// Change options from renderer to keep sync
ipcRenderer.on("setArrowsShortcut", (event, isEnabled) => { ipcRenderer.on("setArrowsShortcut", (event, isEnabled) => {
options.arrowsShortcut = isEnabled; options.arrowsShortcut = isEnabled;
setOptions("precise-volume", options); setOptions("precise-volume", options);
//can setting without restarting app // Can setting without restarting app
if (isEnabled) { if (isEnabled) {
addListener(); addListener();
} else { } else {
@ -57,11 +62,6 @@ function setupArrowShortcuts(options) {
} }
}); });
//register shortcuts if enabled
if (options.arrowsShortcut) {
addListener();
}
function addListener() { function addListener() {
window.addEventListener('keydown', callback); window.addEventListener('keydown', callback);
} }
@ -101,7 +101,7 @@ function changeVolume(increase, options) {
} }
// Save volume + Update the volume tooltip when volume-slider is manually changed // Save volume + Update the volume tooltip when volume-slider is manually changed
function setObserver(options) { function setupObserver(options) {
const observer = new MutationObserver(mutations => { const observer = new MutationObserver(mutations => {
for (const mutation of mutations) { for (const mutation of mutations) {
// This checks that volume-slider was manually set // This checks that volume-slider was manually set
@ -129,14 +129,13 @@ const tooltipTargets = [
"#expand-volume" "#expand-volume"
]; ];
function setTooltip(newValue) { function setTooltip(volume) {
newValue += "%"; const tooltip = volume + "%";
for (target of tooltipTargets) { for (target of tooltipTargets) {
document.querySelector(target).title = newValue; document.querySelector(target).title = tooltip;
} }
} }
function toPercent(volume) { function toPercent(volume) {
return Math.round(Number.parseFloat(volume) * 100); return Math.round(Number.parseFloat(volume) * 100);
} }

View File

@ -1,4 +1,4 @@
const { enabled } = require("./back") const { enabled } = require("./back");
const { setOptions } = require("../../config/plugins"); const { setOptions } = require("../../config/plugins");
module.exports = (win, options) => [ module.exports = (win, options) => [
@ -7,10 +7,10 @@ module.exports = (win, options) => [
type: "checkbox", type: "checkbox",
checked: !!options.arrowsShortcut, checked: !!options.arrowsShortcut,
click: (item) => { click: (item) => {
//dynamically change setting if plugin enabled // Dynamically change setting if plugin enabled
if (enabled()) { if (enabled()) {
win.webContents.send("setArrowsShortcut", item.checked); win.webContents.send("setArrowsShortcut", item.checked);
} else { //fallback to usual method if disabled } else { // Fallback to usual method if disabled
options.arrowsShortcut = item.checked; options.arrowsShortcut = item.checked;
setOptions("precise-volume", options); setOptions("precise-volume", options);
} }