This commit is contained in:
Araxeus
2021-04-18 01:44:18 +03:00
parent 00468c7d0e
commit 72716afcd3
4 changed files with 24 additions and 14 deletions

View File

@ -149,7 +149,7 @@ const mainMenuTemplate = (win) => [
type: "checkbox", type: "checkbox",
checked: !!config.get("options.proxy"), checked: !!config.get("options.proxy"),
click: (item) => { click: (item) => {
setProxy(item, win); setProxy(item, win);
} }
}, },
{ {
@ -322,10 +322,10 @@ function setProxy(item, win) {
}, },
type: 'input', type: 'input',
icon: iconPath, icon: iconPath,
customStylesheet: path.join(__dirname, "providers", "prompt", "dark-prompt.css"), customStylesheet: "dark",
}; };
//TODO: custom bar on prompt need testing on macOS //TODO: custom bar on prompt need testing on macOS
if(!is.macOS()) { if (!is.macOS()) {
Object.assign(options, { Object.assign(options, {
frame: false, frame: false,
customScript: path.join(__dirname, "providers", "prompt", "custom-titlebar.js"), customScript: path.join(__dirname, "providers", "prompt", "custom-titlebar.js"),

View File

@ -19,7 +19,7 @@ function electronPrompt(options, parentWindow) {
const options_ = Object.assign( const options_ = Object.assign(
{ {
width: options?.type === "counter" ? DEFAULT_COUNTER_WIDTH : DEFAULT_WIDTH, 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, resizable: false,
title: "Prompt", title: "Prompt",
label: "Please input a value:", label: "Please input a value:",
@ -28,7 +28,7 @@ function electronPrompt(options, parentWindow) {
value: null, value: null,
type: "input", type: "input",
selectOptions: null, selectOptions: null,
counterOptions: {minimum: null, maximum: null, multiFire: false}, counterOptions: { minimum: null, maximum: null, multiFire: false },
icon: null, icon: null,
useHtmlLabel: false, useHtmlLabel: false,
customStylesheet: null, customStylesheet: null,
@ -44,6 +44,10 @@ function electronPrompt(options, parentWindow) {
options_.minWidth = options?.minWidth || options?.width || options_.width; options_.minWidth = options?.minWidth || options?.width || options_.width;
options_.minHeight = options?.minHeight || options?.height || options_.height; 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")) { if (options_.type === "counter" && (options_.counterOptions !== null && typeof options_.selectOptions !== "object")) {
reject(new Error('"counterOptions" must be an object if specified')); reject(new Error('"counterOptions" must be an object if specified'));
return; return;

View File

@ -229,17 +229,18 @@ let nextTimeoutID = null;
function multiFire(callback, timer = { time: 500, scaleSpeed: 140, limit: 100 }, stepsArg = 1, counter = 0) { function multiFire(callback, timer = { time: 500, scaleSpeed: 140, limit: 100 }, stepsArg = 1, counter = 0) {
callback(stepsArg); callback(stepsArg);
const nextTimeout = timer.time const nextTimeout = timer.time;
if (counter > 20) { if (counter > 20) {
counter = 0 - stepsArg; counter = 0 - stepsArg;
if (timer.limit > 1) { if (timer.limit > 1) {
timer.limit = timer.limit / 2; timer.limit /= 2;
} else { } else {
stepsArg *= 2; stepsArg *= 2;
} }
} }
if (timer.time != timer.limit) {
if (timer.time !== timer.limit) {
timer.time = timer.time > timer.limit ? timer.time = timer.time > timer.limit ?
timer.time - timer.scaleSpeed : timer.time - timer.scaleSpeed :
timer.limit; timer.limit;
@ -253,26 +254,28 @@ function multiFire(callback, timer = { time: 500, scaleSpeed: 140, limit: 100 },
timer, timer,
stepsArg, stepsArg,
counter + 1 counter + 1
) );
} }
function createMinusButton(dataElement) { function createMinusButton(dataElement) {
function doMinus(steps) { function doMinus(steps) {
dataElement.value = validateCounterInput(parseInt(dataElement.value) - steps); dataElement.value = validateCounterInput(parseInt(dataElement.value) - steps);
} }
const minusBtn = document.createElement("span"); const minusBtn = document.createElement("span");
minusBtn.textContent = "-"; minusBtn.textContent = "-";
minusBtn.classList.add("minus"); minusBtn.classList.add("minus");
if (promptOptions.counterOptions?.multiFire) { if (promptOptions.counterOptions?.multiFire) {
minusBtn.onmousedown = () => { minusBtn.onmousedown = () => {
multiFire(doMinus); multiFire(doMinus);
}; };
} else { } else {
minusBtn.onmousedown = () => { minusBtn.onmousedown = () => {
doMinus(); doMinus();
}; };
} }
return minusBtn; return minusBtn;
} }
@ -280,9 +283,11 @@ function createPlusButton(dataElement) {
function doPlus(steps) { function doPlus(steps) {
dataElement.value = validateCounterInput(parseInt(dataElement.value) + steps); dataElement.value = validateCounterInput(parseInt(dataElement.value) + steps);
} }
const plusBtn = document.createElement("span"); const plusBtn = document.createElement("span");
plusBtn.textContent = "+"; plusBtn.textContent = "+";
plusBtn.classList.add("plus"); plusBtn.classList.add("plus");
if (promptOptions.counterOptions?.multiFire) { if (promptOptions.counterOptions?.multiFire) {
plusBtn.onmousedown = () => { plusBtn.onmousedown = () => {
multiFire(doPlus); multiFire(doPlus);
@ -292,13 +297,14 @@ function createPlusButton(dataElement) {
doPlus(); doPlus();
}; };
} }
return plusBtn; return plusBtn;
} }
function promptCreateCounter() { function promptCreateCounter() {
if (promptOptions.counterOptions?.multiFire) { if (promptOptions.counterOptions?.multiFire) {
document.onmouseup = () => { document.onmouseup = () => {
if (!!nextTimeoutID) { if (nextTimeoutID) {
clearTimeout(nextTimeoutID) clearTimeout(nextTimeoutID)
nextTimeoutID = null; nextTimeoutID = null;
} }

View File

@ -1,6 +1,6 @@
# Prompt Documentation # Prompt Documentation
<p align="center"><img width="482" alt="prompt-preview" src="https://user-images.githubusercontent.com/17620180/111753337-09c0c680-8897-11eb-8ce8-43de29c143bd.png"></p> <p align="center">Simplest Prompt:<br><img width="482" alt="prompt-preview" src="https://user-images.githubusercontent.com/17620180/111753337-09c0c680-8897-11eb-8ce8-43de29c143bd.png"></p>
## Usage ## Usage
```js ```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. | | 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. | | 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. | | 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. | | 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. | | 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. | | 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 | | 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. | | 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. | | 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. | | 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. | | frame | (optional, boolean) Wether to create prompt with frame. Defaults to true. |