From 97a9e632317c674bae580f818d474fd21487698d Mon Sep 17 00:00:00 2001 From: Araxeus Date: Sat, 17 Apr 2021 21:17:07 +0300 Subject: [PATCH] xo --fix --- preload.js | 2 +- providers/{frontLogger.js => front-logger.js} | 0 providers/prompt/index.js | 16 +++--- providers/prompt/page/prompt.js | 51 +++++++++++-------- 4 files changed, 38 insertions(+), 31 deletions(-) rename providers/{frontLogger.js => front-logger.js} (100%) diff --git a/preload.js b/preload.js index 5fcb2e07..74860cec 100644 --- a/preload.js +++ b/preload.js @@ -34,7 +34,7 @@ document.addEventListener("DOMContentLoaded", () => { fileExists(songInfoProviderPath, require(songInfoProviderPath)); // inject front logger - const loggerPath = path.join(__dirname, "providers", "frontLogger.js") + const loggerPath = path.join(__dirname, "providers", "front-logger.js") fileExists(loggerPath, require(loggerPath)); // Add action for reloading diff --git a/providers/frontLogger.js b/providers/front-logger.js similarity index 100% rename from providers/frontLogger.js rename to providers/front-logger.js diff --git a/providers/prompt/index.js b/providers/prompt/index.js index 1c14cfa2..1e29766f 100644 --- a/providers/prompt/index.js +++ b/providers/prompt/index.js @@ -8,7 +8,7 @@ const path = require("path"); const DEFAULT_WIDTH = 370; const DEFAULT_COUNTER_WIDTH = 300; const DEFAULT_HEIGHT = 160; -const DEFAULT_COUNTER_HEIGHT= 150; +const DEFAULT_COUNTER_HEIGHT = 150; function electronPrompt(options, parentWindow) { return new Promise((resolve, reject) => { @@ -40,9 +40,9 @@ function electronPrompt(options, parentWindow) { options || {} ); - options_.minWidth = options.minWidth || options.width || + options_.minWidth = options.minWidth || options.width || options_.type === "counter" ? DEFAULT_COUNTER_WIDTH : DEFAULT_WIDTH; - options_.minHeight = options.minHeight || options.height || + options_.minHeight = options.minHeight || options.height || options_.type === "counter" ? DEFAULT_COUNTER_HEIGHT : DEFAULT_HEIGHT; if (options_.type === "select" && (options_.selectOptions === null || typeof options_.selectOptions !== "object")) { @@ -130,21 +130,21 @@ function electronPrompt(options, parentWindow) { event, errorCode, errorDescription, - validatedURL, + validatedURL ) => { const log = { error: "did-fail-load", errorCode, errorDescription, - validatedURL, + validatedURL }; - reject(new Error("prompt.html did-fail-load, log:\n", + log.toString())); + reject(new Error("prompt.html did-fail-load, log:\n" + log.toString())); }); const promptUrl = url.format({ - protocol: 'file', + protocol: "file", slashes: true, - pathname: path.join(__dirname, 'page', 'prompt.html'), + pathname: path.join(__dirname, "page", "prompt.html"), hash: id }); diff --git a/providers/prompt/page/prompt.js b/providers/prompt/page/prompt.js index d3abfeab..ac79f106 100644 --- a/providers/prompt/page/prompt.js +++ b/providers/prompt/page/prompt.js @@ -4,9 +4,11 @@ const { ipcRenderer } = require("electron"); let promptId = null; let promptOptions = null; -function $(selector) { return document.querySelector(selector) } +function $(selector) { + return document.querySelector(selector); +} -document.addEventListener('DOMContentLoaded', promptRegister); +document.addEventListener("DOMContentLoaded", promptRegister); function promptRegister() { //get custom session id @@ -54,7 +56,6 @@ function promptRegister() { $("#form").addEventListener("submit", promptSubmit); $("#cancel").addEventListener("click", promptCancel); - //create input/select const dataContainerElement = $("#data-container"); let dataElement; @@ -70,19 +71,20 @@ function promptRegister() { default: return promptError(`Unhandled input type '${promptOptions.type}'`); } + if (promptOptions.type === "counter") { dataElement.style.width = "unset"; dataElement.style["text-align"] = "center"; - //dataElement.style["min-height"] = "1.5em"; - dataContainerElement.append(createMinus(dataElement)); + dataContainerElement.append(createMinusButton(dataElement)); dataContainerElement.append(dataElement); - dataContainerElement.append(createPlus(dataElement)); + dataContainerElement.append(createPlusButton(dataElement)); } else { dataContainerElement.append(dataElement); } - dataElement.setAttribute("id", "data"); + dataElement.setAttribute("id", "data"); dataElement.focus(); + if (promptOptions.type === "input" || promptOptions.type === "counter") { dataElement.select(); } @@ -100,7 +102,8 @@ function promptRegister() { window.addEventListener("error", error => { if (promptId) { - promptError("An error has occured on the prompt window: \n" + JSON.stringify(error, ["message", "arguments", "type", "name"]) + promptError("An error has occured on the prompt window: \n" + + JSON.stringify(error, ["message", "arguments", "type", "name"]) ); } }); @@ -209,35 +212,39 @@ function promptCreateSelect() { return dataElement; } -function createMinus(dataElement) { - const minus = document.createElement("span"); - minus.textContent = "-"; - minus.classList.add("minus"); - minus.onmousedown = () => { +function createMinusButton(dataElement) { + const minusBtn = document.createElement("span"); + minusBtn.textContent = "-"; + minusBtn.classList.add("minus"); + minusBtn.onmousedown = () => { dataElement.value = validateCounterInput(parseInt(dataElement.value) - 1); }; - return minus; + return minusBtn; } -function createPlus(dataElement) { - const plus = document.createElement("span"); - plus.textContent = "+"; - plus.classList.add("plus"); - plus.onmousedown = () => { +function createPlusButton(dataElement) { + const plusBtn = document.createElement("span"); + plusBtn.textContent = "+"; + plusBtn.classList.add("plus"); + plusBtn.onmousedown = () => { dataElement.value = validateCounterInput(parseInt(dataElement.value) + 1); }; - return plus; + + return plusBtn; } //validate counter function validateCounterInput(input) { - const min = promptOptions.counterOptions?.minimum, - max = promptOptions.counterOptions?.maximum; + const min = promptOptions.counterOptions?.minimum; + const max = promptOptions.counterOptions?.maximum; + if (min !== undefined && input < min) { return min; } + if (max !== undefined && input > max) { return max; } + return input; }