Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add env proxy #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -27,6 +28,10 @@ const configSchema = {
type: 'boolean',
default: false,
},
proxy: {
type: 'string',
default: '',
},
}
const config = new Store({ schema: configSchema, clearInvalidConfig: true })

Expand All @@ -37,8 +42,8 @@ const createWindow = () => {
theme === 'system'
? nativeTheme.shouldUseDarkColors
: theme === 'dark'
? true
: false
? true
: false
// Create window
const mainWindow = new BrowserWindow({
title: 'BingGPT',
Expand All @@ -65,6 +70,11 @@ const createWindow = () => {
const locale = app.getLocale() || 'en-US'
// Hide main menu (Windows)
Menu.setApplicationMenu(null)
// Set proxy
const proxy = config.get('proxy')
if (proxy) {
mainWindow.webContents.session.setProxy({ proxyRules: proxy })
}
// Create context menu
contextMenu({
window: mainWindow.webContents,
Expand Down Expand Up @@ -214,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,
Expand Down Expand Up @@ -294,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)
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down