From 061e4a9e5f0e8d6743f933df14aefa6685bbb8ed Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 3 Apr 2021 21:51:35 +0300 Subject: [PATCH] add 'electron-prompt' and use it for setting proxy --- menu.js | 36 +++++++++++++++++++++++++++++++++--- package.json | 1 + yarn.lock | 19 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/menu.js b/menu.js index c0843247..3c6efa86 100644 --- a/menu.js +++ b/menu.js @@ -6,11 +6,13 @@ const is = require("electron-is"); const { getAllPlugins } = require("./plugins/utils"); const config = require("./config"); +const prompt = require('electron-prompt'); const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({ label: label || plugin, type: "checkbox", checked: config.plugins.isEnabled(plugin), + hasSubmenu: hasSubmenu || undefined, click: (item) => { if (item.checked) { config.plugins.enable(plugin); @@ -142,12 +144,12 @@ const mainMenuTemplate = (win) => [ label: "Advanced options", submenu: [ { - label: "Use Proxy", + label: "Proxy", type: "checkbox", checked: !!config.get("options.proxy"), + //fixed: true, //skip in-app-menu click() override click: (item) => { - const value = item.checked? "socks5://127.0.0.1:9999" : ""; - config.set("options.proxy", value); + setProxy(item, win); } }, { @@ -307,3 +309,31 @@ module.exports.setApplicationMenu = (win) => { const menu = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menu); }; + +// +const iconPath = path.join(__dirname, "assets", "youtube-music-tray.png"); +function setProxy(item, win) { + prompt({ + title: 'Set Proxy', + label: 'Enter Proxy Adress:', + value: config.get("options.proxy") || `Example - "socks5://127.0.0.1:9999"`, + inputAttrs: { + type: 'text' + }, + type: 'input', + alwaysOnTop: true, + icon: iconPath + }) + .then((input) => { + if(input !== null) { + console.log(`setting proxy to ${input}`); + config.set("options.proxy", input); + if(input === "") + item.checked = false; + item.checked = (input === "") ? false : true; + } else { //user pressed cancel + item.checked = !item.checked; //reset checkbox + } + }) + .catch(console.error); +} \ No newline at end of file diff --git a/package.json b/package.json index ce144c38..736374c5 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "electron-debug": "^3.2.0", "electron-is": "^3.0.0", "electron-localshortcut": "^3.2.1", + "electron-prompt": "^1.6.2", "electron-store": "^7.0.2", "electron-unhandled": "^3.0.2", "electron-updater": "^4.3.6", diff --git a/yarn.lock b/yarn.lock index c969527e..b029d432 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2908,6 +2908,13 @@ dmg-builder@22.9.1: js-yaml "^3.14.0" sanitize-filename "^1.6.3" +doc-ready@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/doc-ready/-/doc-ready-1.0.4.tgz#37f5391969cff994303fdfef2e5d50357f8164d3" + integrity sha1-N/U5GWnP+ZQwP9/vLl1QNX+BZNM= + dependencies: + eventie "^1" + doctrine@1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa" @@ -3086,6 +3093,13 @@ electron-localshortcut@^3.1.0, electron-localshortcut@^3.2.1: keyboardevent-from-electron-accelerator "^2.0.0" keyboardevents-areequal "^0.2.1" +electron-prompt@^1.6.2: + version "1.6.2" + resolved "https://registry.yarnpkg.com/electron-prompt/-/electron-prompt-1.6.2.tgz#e26bd3d359120bd45ce2f9625bdc380deb7ee269" + integrity sha512-gC9ZpMopIgz1kW92J7UfsXarkLdPH2zhr77bnJFlDSduYjRlr9nEPm4ux1vyzJsO72AdOyvuPPIQB0j+gWsncQ== + dependencies: + doc-ready "^1.0.4" + electron-publish@22.9.1: version "22.9.1" resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-22.9.1.tgz#7cc76ac4cc53efd29ee31c1e5facb9724329068e" @@ -3605,6 +3619,11 @@ esutils@^2.0.2: resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== +eventie@^1: + version "1.0.6" + resolved "https://registry.yarnpkg.com/eventie/-/eventie-1.0.6.tgz#d4ffc8b0c2b5e493c2aa1b22cbe918d3aee74437" + integrity sha1-1P/IsMK15JPCqhsiy+kY067nRDc= + events@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/events/-/events-3.2.0.tgz#93b87c18f8efcd4202a461aec4dfc0556b639379"