From 12a2517697f1f66396faed8653259ee012585491 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Sat, 17 Apr 2021 15:03:19 +0300 Subject: [PATCH] xo --fix --- plugins/precise-volume/back.js | 10 +++++----- plugins/precise-volume/front.js | 27 +++++++++++++-------------- plugins/precise-volume/menu.js | 18 +++++++++--------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/plugins/precise-volume/back.js b/plugins/precise-volume/back.js index 7582f4ce..e6b101f9 100644 --- a/plugins/precise-volume/back.js +++ b/plugins/precise-volume/back.js @@ -1,12 +1,12 @@ /* -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) */ let enabled = false; -module.exports = (win,options) => { - enabled = true; +module.exports = () => { + enabled = true; }; module.exports.enabled = () => { - return enabled; -}; \ No newline at end of file + return enabled; +}; diff --git a/plugins/precise-volume/front.js b/plugins/precise-volume/front.js index 7aa42dc5..d6424df1 100644 --- a/plugins/precise-volume/front.js +++ b/plugins/precise-volume/front.js @@ -3,9 +3,9 @@ const { ipcRenderer } = require("electron"); module.exports = (options) => { setPlaybarOnwheel(options); - setObserver(options); - firstRun(options); + setupObserver(options); setupArrowShortcuts(options); + firstRun(options); }; function saveVolume(volume, options) { @@ -45,11 +45,16 @@ function setPlaybarOnwheel(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) => { options.arrowsShortcut = isEnabled; setOptions("precise-volume", options); - //can setting without restarting app + // Can setting without restarting app if (isEnabled) { addListener(); } else { @@ -57,11 +62,6 @@ function setupArrowShortcuts(options) { } }); - //register shortcuts if enabled - if (options.arrowsShortcut) { - addListener(); - } - function addListener() { window.addEventListener('keydown', callback); } @@ -101,7 +101,7 @@ function changeVolume(increase, options) { } // Save volume + Update the volume tooltip when volume-slider is manually changed -function setObserver(options) { +function setupObserver(options) { const observer = new MutationObserver(mutations => { for (const mutation of mutations) { // This checks that volume-slider was manually set @@ -129,14 +129,13 @@ const tooltipTargets = [ "#expand-volume" ]; -function setTooltip(newValue) { - newValue += "%"; +function setTooltip(volume) { + const tooltip = volume + "%"; for (target of tooltipTargets) { - document.querySelector(target).title = newValue; + document.querySelector(target).title = tooltip; } } function toPercent(volume) { return Math.round(Number.parseFloat(volume) * 100); } - diff --git a/plugins/precise-volume/menu.js b/plugins/precise-volume/menu.js index a906addf..d4ed37a7 100644 --- a/plugins/precise-volume/menu.js +++ b/plugins/precise-volume/menu.js @@ -1,4 +1,4 @@ -const { enabled } = require("./back") +const { enabled } = require("./back"); const { setOptions } = require("../../config/plugins"); module.exports = (win, options) => [ @@ -7,13 +7,13 @@ module.exports = (win, options) => [ type: "checkbox", checked: !!options.arrowsShortcut, click: (item) => { - //dynamically change setting if plugin enabled - if (enabled()) { - win.webContents.send("setArrowsShortcut", item.checked); - } else { //fallback to usual method if disabled - options.arrowsShortcut = item.checked; - setOptions("precise-volume", options); - } - } + // Dynamically change setting if plugin enabled + if (enabled()) { + win.webContents.send("setArrowsShortcut", item.checked); + } else { // Fallback to usual method if disabled + options.arrowsShortcut = item.checked; + setOptions("precise-volume", options); + } + } } ];