From 72716afcd3fcba96714c360257d95cb77af125a8 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Sun, 18 Apr 2021 01:44:18 +0300 Subject: [PATCH] lint --- menu.js | 6 +++--- providers/prompt/index.js | 8 ++++++-- providers/prompt/page/prompt.js | 18 ++++++++++++------ providers/prompt/readme.md | 6 +++--- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/menu.js b/menu.js index 588dad7c..dddce721 100644 --- a/menu.js +++ b/menu.js @@ -149,7 +149,7 @@ const mainMenuTemplate = (win) => [ type: "checkbox", checked: !!config.get("options.proxy"), click: (item) => { - setProxy(item, win); + setProxy(item, win); } }, { @@ -322,10 +322,10 @@ function setProxy(item, win) { }, type: 'input', icon: iconPath, - customStylesheet: path.join(__dirname, "providers", "prompt", "dark-prompt.css"), + customStylesheet: "dark", }; //TODO: custom bar on prompt need testing on macOS - if(!is.macOS()) { + if (!is.macOS()) { Object.assign(options, { frame: false, customScript: path.join(__dirname, "providers", "prompt", "custom-titlebar.js"), diff --git a/providers/prompt/index.js b/providers/prompt/index.js index 009c8c7a..95babc9c 100644 --- a/providers/prompt/index.js +++ b/providers/prompt/index.js @@ -19,7 +19,7 @@ function electronPrompt(options, parentWindow) { const options_ = Object.assign( { width: options?.type === "counter" ? DEFAULT_COUNTER_WIDTH : DEFAULT_WIDTH, - height:options?.type === "counter" ? DEFAULT_COUNTER_HEIGHT: DEFAULT_HEIGHT, + height: options?.type === "counter" ? DEFAULT_COUNTER_HEIGHT : DEFAULT_HEIGHT, resizable: false, title: "Prompt", label: "Please input a value:", @@ -28,7 +28,7 @@ function electronPrompt(options, parentWindow) { value: null, type: "input", selectOptions: null, - counterOptions: {minimum: null, maximum: null, multiFire: false}, + counterOptions: { minimum: null, maximum: null, multiFire: false }, icon: null, useHtmlLabel: false, customStylesheet: null, @@ -44,6 +44,10 @@ function electronPrompt(options, parentWindow) { options_.minWidth = options?.minWidth || options?.width || options_.width; options_.minHeight = options?.minHeight || options?.height || options_.height; + if (options_.customStylesheet === "dark") { + options_.customStylesheet = require("path").join(__dirname, "dark-prompt.css"); + } + if (options_.type === "counter" && (options_.counterOptions !== null && typeof options_.selectOptions !== "object")) { reject(new Error('"counterOptions" must be an object if specified')); return; diff --git a/providers/prompt/page/prompt.js b/providers/prompt/page/prompt.js index b4759e2d..7f609b52 100644 --- a/providers/prompt/page/prompt.js +++ b/providers/prompt/page/prompt.js @@ -229,17 +229,18 @@ let nextTimeoutID = null; function multiFire(callback, timer = { time: 500, scaleSpeed: 140, limit: 100 }, stepsArg = 1, counter = 0) { callback(stepsArg); - const nextTimeout = timer.time + const nextTimeout = timer.time; if (counter > 20) { counter = 0 - stepsArg; if (timer.limit > 1) { - timer.limit = timer.limit / 2; + timer.limit /= 2; } else { stepsArg *= 2; } } - if (timer.time != timer.limit) { + + if (timer.time !== timer.limit) { timer.time = timer.time > timer.limit ? timer.time - timer.scaleSpeed : timer.limit; @@ -253,26 +254,28 @@ function multiFire(callback, timer = { time: 500, scaleSpeed: 140, limit: 100 }, timer, stepsArg, counter + 1 - ) + ); } function createMinusButton(dataElement) { function doMinus(steps) { dataElement.value = validateCounterInput(parseInt(dataElement.value) - steps); } + const minusBtn = document.createElement("span"); minusBtn.textContent = "-"; minusBtn.classList.add("minus"); + if (promptOptions.counterOptions?.multiFire) { minusBtn.onmousedown = () => { multiFire(doMinus); }; - } else { minusBtn.onmousedown = () => { doMinus(); }; } + return minusBtn; } @@ -280,9 +283,11 @@ function createPlusButton(dataElement) { function doPlus(steps) { dataElement.value = validateCounterInput(parseInt(dataElement.value) + steps); } + const plusBtn = document.createElement("span"); plusBtn.textContent = "+"; plusBtn.classList.add("plus"); + if (promptOptions.counterOptions?.multiFire) { plusBtn.onmousedown = () => { multiFire(doPlus); @@ -292,13 +297,14 @@ function createPlusButton(dataElement) { doPlus(); }; } + return plusBtn; } function promptCreateCounter() { if (promptOptions.counterOptions?.multiFire) { document.onmouseup = () => { - if (!!nextTimeoutID) { + if (nextTimeoutID) { clearTimeout(nextTimeoutID) nextTimeoutID = null; } diff --git a/providers/prompt/readme.md b/providers/prompt/readme.md index ec272375..a3775b8d 100644 --- a/providers/prompt/readme.md +++ b/providers/prompt/readme.md @@ -1,6 +1,6 @@ # Prompt Documentation -

prompt-preview

+

Simplest Prompt:
prompt-preview

## Usage ```js @@ -49,13 +49,13 @@ prompt({ | selectOptions | (optional, object) The items for the select dropdown if using the 'select' type in the format 'value': 'display text', where the value is what will be given to the then block and the display text is what the user will see. | | useHtmlLabel | (optional, boolean) Whether the label should be interpreted as HTML or not. Defaults to false. | | width | (optional, integer) The width of the prompt window. Defaults to 370. | -| minWidth | (optional, integer) The minimum allowed width for the prompt window. Same default value as width. | +| minWidth | (optional, integer) The minimum allowed width for the prompt window. Default to width if specified or default_width(370). | | | height | (optional, integer) The height of the prompt window. Defaults to 130. | | minHeight | (optional, integer) The minimum allowed height for the prompt window. Same default value as height. | | resizable | (optional, boolean) Whether the prompt window can be resized or not (also sets useContentSize). Defaults to false. | | alwaysOnTop | (optional, boolean) Whether the window should always stay on top of other windows. Defaults to false | | icon | (optional, string) The path to an icon image to use in the title bar. Defaults to null and uses electron's icon. | -| customStylesheet | (optional, string) The local path of a CSS file to stylize the prompt window. Defaults to null. | +| customStylesheet | (optional, string) The local path of a CSS file to customize the style of the prompt window, you can use just "dark" to use the premade dark skin. Defaults to null. | | menuBarVisible | (optional, boolean) Whether to show the menubar or not. Defaults to false. | | skipTaskbar | (optional, boolean) Whether to show the prompt window icon in taskbar. Defaults to true. | | frame | (optional, boolean) Wether to create prompt with frame. Defaults to true. |