mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
feat: add proxy settings
This commit is contained in:
@@ -14,6 +14,9 @@ import { registerShortcut } from './shortcut'
|
||||
import { $t } from './i18n'
|
||||
import { getProxyAgent } from './proxy-agent'
|
||||
import config from './config'
|
||||
import { initProxy } from './proxy'
|
||||
|
||||
initProxy()
|
||||
|
||||
const electronContextMenu = require('electron-context-menu')
|
||||
const electronRemote = require('@electron/remote/main')
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { app, session } from 'electron'
|
||||
import { registerAction } from './action'
|
||||
import config from './config'
|
||||
|
||||
const keyEnabled = 'proxy.enabled'
|
||||
const keyServer = 'proxy.server'
|
||||
const keyPacUrl = 'proxy.pac-url'
|
||||
const keyBypassList = 'proxy.bypass-list'
|
||||
|
||||
export function initProxy () {
|
||||
const proxyEnabled = config.get(keyEnabled, false)
|
||||
console.log('use proxy:', proxyEnabled)
|
||||
|
||||
const proxyServer = config.get(keyServer, '')
|
||||
if (proxyEnabled && proxyServer && proxyServer.includes(':')) {
|
||||
const proxyPacUrl = config.get(keyPacUrl, '')
|
||||
const proxyBypassList = config.get(keyBypassList, '<local>')
|
||||
|
||||
console.log('proxy server:', proxyServer)
|
||||
console.log('proxy pac-url:', proxyPacUrl)
|
||||
console.log('proxy bypass-list:', proxyBypassList)
|
||||
|
||||
app.commandLine.appendSwitch('proxy-server', proxyServer)
|
||||
proxyPacUrl && app.commandLine.appendSwitch('proxy-pac-url', proxyPacUrl)
|
||||
proxyBypassList && app.commandLine.appendSwitch('proxy-bypass-list', proxyBypassList)
|
||||
}
|
||||
}
|
||||
|
||||
function reloadProxy (config: any) {
|
||||
console.log('reload proxy', config[keyEnabled])
|
||||
|
||||
if (config[keyEnabled]) {
|
||||
session.defaultSession.setProxy({
|
||||
proxyRules: config[keyServer],
|
||||
proxyBypassRules: config[keyBypassList],
|
||||
pacScript: config[keyPacUrl]
|
||||
})
|
||||
} else {
|
||||
session.defaultSession.setProxy({ mode: 'system' })
|
||||
}
|
||||
}
|
||||
|
||||
registerAction('proxy.reload', reloadProxy)
|
||||
@@ -360,6 +360,8 @@ const setting = async (ctx: any, next: any) => {
|
||||
getAction('updater.change-source')(data['updater.source'])
|
||||
}
|
||||
|
||||
getAction('proxy.reload')(data)
|
||||
|
||||
ctx.body = result('ok', 'success')
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -231,7 +231,42 @@ const schema: Schema = {
|
||||
group: 'other',
|
||||
format: 'checkbox',
|
||||
required: true,
|
||||
}
|
||||
},
|
||||
'proxy.enabled': {
|
||||
defaultValue: false,
|
||||
title: 'T_setting-panel.schema.proxy.enabled',
|
||||
type: 'boolean',
|
||||
format: 'checkbox',
|
||||
group: 'proxy',
|
||||
},
|
||||
'proxy.server': {
|
||||
defaultValue: '',
|
||||
title: 'T_setting-panel.schema.proxy.server',
|
||||
type: 'string',
|
||||
group: 'proxy',
|
||||
pattern: '^.+:\\d{2,5}$',
|
||||
options: {
|
||||
inputAttributes: { placeholder: 'T_setting-panel.schema.proxy.server-hint', }
|
||||
}
|
||||
},
|
||||
'proxy.bypass-list': {
|
||||
defaultValue: '<local>',
|
||||
title: 'T_setting-panel.schema.proxy.bypass-list',
|
||||
type: 'string',
|
||||
group: 'proxy',
|
||||
options: {
|
||||
inputAttributes: { placeholder: '<local>;*.google.com;*foo.com;1.2.3.4:5678', }
|
||||
}
|
||||
},
|
||||
'proxy.pac-url': {
|
||||
defaultValue: '',
|
||||
title: 'T_setting-panel.schema.proxy.pac-url',
|
||||
type: 'string',
|
||||
group: 'proxy',
|
||||
options: {
|
||||
inputAttributes: { placeholder: 'http://', }
|
||||
}
|
||||
},
|
||||
} as Partial<Schema['properties']> as any,
|
||||
required: [],
|
||||
groups: [
|
||||
@@ -239,6 +274,7 @@ const schema: Schema = {
|
||||
{ label: 'T_setting-panel.tabs.appearance', value: 'appearance' },
|
||||
{ label: 'T_setting-panel.tabs.editor', value: 'editor' },
|
||||
{ label: 'T_setting-panel.tabs.image', value: 'image' },
|
||||
{ label: 'T_setting-panel.tabs.proxy', value: 'proxy' },
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ export namespace Components {
|
||||
export type ThemeName = 'system' | 'dark' | 'light'
|
||||
export type LanguageName = 'system' | Language
|
||||
export type ExportType = 'pdf' | 'docx' | 'html' | 'rst' | 'adoc'
|
||||
export type SettingGroup = 'repos' | 'appearance' | 'editor' | 'image' | 'other' | 'openai'
|
||||
export type SettingGroup = 'repos' | 'appearance' | 'editor' | 'image' | 'proxy' | 'other' | 'openai'
|
||||
|
||||
export type RenderEnv = {
|
||||
source: string,
|
||||
@@ -126,6 +126,10 @@ export type BuildInSettings = {
|
||||
'doc-history.number-limit': number,
|
||||
'server.host': string,
|
||||
'server.port': number,
|
||||
'proxy.enabled': boolean,
|
||||
'proxy.server': string,
|
||||
'proxy.pac-url': string,
|
||||
'proxy.bypass-list': string,
|
||||
'keep-running-after-closing-window': boolean,
|
||||
'plantuml-api': string,
|
||||
}
|
||||
|
||||
@@ -311,6 +311,7 @@ const data = {
|
||||
'appearance': 'Appearance',
|
||||
'editor': 'Editor',
|
||||
'image': 'Image',
|
||||
'proxy': 'Proxy',
|
||||
'other': 'Other',
|
||||
},
|
||||
'schema': {
|
||||
@@ -348,6 +349,13 @@ const data = {
|
||||
'port': 'Listen Port',
|
||||
'port-desc': 'Need to restart the application.'
|
||||
},
|
||||
'proxy': {
|
||||
'enabled': 'Enabled',
|
||||
'server': 'Proxy Server',
|
||||
'server-hint': '127.0.0.1:8080',
|
||||
'bypass-list': 'Bypass List',
|
||||
'pac-url': 'PAC URL',
|
||||
},
|
||||
}
|
||||
},
|
||||
'quick-open': {
|
||||
|
||||
@@ -342,12 +342,20 @@ const data: BaseLanguage = {
|
||||
'port': '监听端口',
|
||||
'port-desc': '需要重启应用',
|
||||
},
|
||||
'proxy': {
|
||||
'enabled': '启用代理',
|
||||
'server': '代理服务器',
|
||||
'server-hint': '127.0.0.1:8080',
|
||||
'bypass-list': 'Bypass List',
|
||||
'pac-url': 'PAC URL',
|
||||
},
|
||||
},
|
||||
'tabs': {
|
||||
'repos': '仓库',
|
||||
'appearance': '外观',
|
||||
'editor': '编辑器',
|
||||
'image': '图片',
|
||||
'proxy': '代理',
|
||||
'other': '其他',
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user