From 36c0a6646c142fc170b8d849f76b36a5587476d0 Mon Sep 17 00:00:00 2001 From: notplus Date: Mon, 27 Mar 2023 22:42:29 +0800 Subject: [PATCH 1/2] feat: add env proxy --- main.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.js b/main.js index 0e5bcc7..3d67d77 100644 --- a/main.js +++ b/main.js @@ -65,6 +65,11 @@ const createWindow = () => { const locale = app.getLocale() || 'en-US' // Hide main menu (Windows) Menu.setApplicationMenu(null) + // Set proxy + const proxy = process.env.http_proxy || process.env.HTTP_PROXY + if (proxy) { + mainWindow.webContents.session.setProxy({ proxyRules: proxy }) + } // Create context menu contextMenu({ window: mainWindow.webContents, From a003953ffe374a017e1a032716fb3ef1d646a1a7 Mon Sep 17 00:00:00 2001 From: notplus Date: Tue, 28 Mar 2023 13:14:01 +0800 Subject: [PATCH 2/2] feat: add proxy setting prompt * add proxy setting prompt * include electron-prompt dependency --- main.js | 48 ++++++++++++++++++++++++++++++++++++++++++++--- package-lock.json | 6 ++++++ package.json | 1 + 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 3d67d77..657079b 100644 --- a/main.js +++ b/main.js @@ -8,6 +8,7 @@ const { BrowserWindow, } = require('electron') const contextMenu = require('electron-context-menu') +const prompt = require('electron-prompt') const Store = require('electron-store') const path = require('path') const fs = require('fs') @@ -27,6 +28,10 @@ const configSchema = { type: 'boolean', default: false, }, + proxy: { + type: 'string', + default: '', + }, } const config = new Store({ schema: configSchema, clearInvalidConfig: true }) @@ -37,8 +42,8 @@ const createWindow = () => { theme === 'system' ? nativeTheme.shouldUseDarkColors : theme === 'dark' - ? true - : false + ? true + : false // Create window const mainWindow = new BrowserWindow({ title: 'BingGPT', @@ -66,7 +71,7 @@ const createWindow = () => { // Hide main menu (Windows) Menu.setApplicationMenu(null) // Set proxy - const proxy = process.env.http_proxy || process.env.HTTP_PROXY + const proxy = config.get('proxy') if (proxy) { mainWindow.webContents.session.setProxy({ proxyRules: proxy }) } @@ -219,6 +224,26 @@ const createWindow = () => { type: 'separator', visible: parameters.selectionText.trim().length === 0, }, + { + label: 'Proxy', + visible: parameters.selectionText.trim().length === 0, + click: () => { + prompt({ + title: 'Proxy', + label: 'Proxy:', + value: proxy, + inputAttrs: { + type: 'url', + }, + type: 'input', + }, mainWindow) + .then((r) => { + if (r) { + proxyHandler(r) + } + }) + }, + }, { label: 'Feedback', visible: parameters.selectionText.trim().length === 0, @@ -299,6 +324,23 @@ const createWindow = () => { } }) } + // Proxy + const proxyHandler = (newProxy) => { + config.set('proxy', newProxy) + dialog + .showMessageBox(mainWindow, { + type: 'question', + buttons: ['Yes', 'No'], + message: 'Proxy Saved', + detail: 'Do you want to reload BingGPT now?', + }) + .then((result) => { + if (result.response === 0) { + mainWindow.close() + createWindow() + } + }) + } // Font size const fontSizeHandler = (newSize) => { config.set('fontSize', newSize) diff --git a/package-lock.json b/package-lock.json index a992f78..f063bfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "Apache-2.0", "dependencies": { "electron-context-menu": "^3.6.1", + "electron-prompt": "^1.7.0", "electron-squirrel-startup": "^1.0.0", "electron-store": "^8.1.0", "html2canvas": "^1.4.1", @@ -2061,6 +2062,11 @@ "node": ">= 14.17.5" } }, + "node_modules/electron-prompt": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/electron-prompt/-/electron-prompt-1.7.0.tgz", + "integrity": "sha512-IfqJYEgcRO6NuyPROo8AtdkAiZ6N9I1lQEf4dJAkPuhV5YgOHdmLqZJf6OXumZJfzrjpzCM5jHeYOrhGdgbnEA==" + }, "node_modules/electron-squirrel-startup": { "version": "1.0.0", "resolved": "https://registry.npmmirror.com/electron-squirrel-startup/-/electron-squirrel-startup-1.0.0.tgz", diff --git a/package.json b/package.json index 04def37..c177445 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "electron-context-menu": "^3.6.1", + "electron-prompt": "^1.7.0", "electron-squirrel-startup": "^1.0.0", "electron-store": "^8.1.0", "html2canvas": "^1.4.1",