完善代理设置
parent
fa9b84a9c9
commit
9a692a99f6
|
@ -128,7 +128,7 @@ const defaultSetting: LX.AppSetting = {
|
||||||
'search.isShowHistorySearch': false,
|
'search.isShowHistorySearch': false,
|
||||||
'search.isFocusSearchBox': false,
|
'search.isFocusSearchBox': false,
|
||||||
|
|
||||||
'network.proxy.enable': false,
|
'network.proxy.type': 'disable',
|
||||||
'network.proxy.host': '',
|
'network.proxy.host': '',
|
||||||
'network.proxy.port': '',
|
'network.proxy.port': '',
|
||||||
|
|
||||||
|
|
|
@ -596,9 +596,9 @@ declare global {
|
||||||
'search.isFocusSearchBox': boolean
|
'search.isFocusSearchBox': boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否启用代理
|
* 代理类型
|
||||||
*/
|
*/
|
||||||
'network.proxy.enable': boolean
|
'network.proxy.type': 'disable' | 'system' | 'custom'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代理服务器地址
|
* 代理服务器地址
|
||||||
|
|
|
@ -113,7 +113,7 @@ export default (setting: any): Partial<LX.AppSetting> => {
|
||||||
setting['search.isShowHistorySearch'] = setting.search?.isShowHistorySearch
|
setting['search.isShowHistorySearch'] = setting.search?.isShowHistorySearch
|
||||||
setting['search.isFocusSearchBox'] = setting.search?.isFocusSearchBox
|
setting['search.isFocusSearchBox'] = setting.search?.isFocusSearchBox
|
||||||
|
|
||||||
setting['network.proxy.enable'] = setting.network?.proxy?.enable
|
// setting['network.proxy.enable'] = setting.network?.proxy?.enable
|
||||||
setting['network.proxy.host'] = setting.network?.proxy?.host
|
setting['network.proxy.host'] = setting.network?.proxy?.host
|
||||||
setting['network.proxy.port'] = setting.network?.proxy?.port
|
setting['network.proxy.port'] = setting.network?.proxy?.port
|
||||||
|
|
||||||
|
|
|
@ -472,6 +472,9 @@
|
||||||
"setting__list_scroll": "Remember position of scroll bar of playlist (Only valid for \"Your Library\" page)",
|
"setting__list_scroll": "Remember position of scroll bar of playlist (Only valid for \"Your Library\" page)",
|
||||||
"setting__list_source": "Show which music streaming service the song is from (Only valid for \"Your Library\" page)",
|
"setting__list_source": "Show which music streaming service the song is from (Only valid for \"Your Library\" page)",
|
||||||
"setting__network": "Network",
|
"setting__network": "Network",
|
||||||
|
"setting__network_proxy_type_disable": "Do not use proxy",
|
||||||
|
"setting__network_proxy_type_system": "Use system proxy",
|
||||||
|
"setting__network_proxy_type_custom": "Custom proxy",
|
||||||
"setting__network_proxy_host": "Host",
|
"setting__network_proxy_host": "Host",
|
||||||
"setting__network_proxy_password": "Password",
|
"setting__network_proxy_password": "Password",
|
||||||
"setting__network_proxy_port": "Port",
|
"setting__network_proxy_port": "Port",
|
||||||
|
|
|
@ -472,6 +472,9 @@
|
||||||
"setting__list_scroll": "记住播放列表滚动条位置(仅对「我的列表」有效)",
|
"setting__list_scroll": "记住播放列表滚动条位置(仅对「我的列表」有效)",
|
||||||
"setting__list_source": "显示歌曲来源平台(仅对「我的列表」有效)",
|
"setting__list_source": "显示歌曲来源平台(仅对「我的列表」有效)",
|
||||||
"setting__network": "网络设置",
|
"setting__network": "网络设置",
|
||||||
|
"setting__network_proxy_type_disable": "不使用代理",
|
||||||
|
"setting__network_proxy_type_system": "使用系统代理",
|
||||||
|
"setting__network_proxy_type_custom": "自定义代理",
|
||||||
"setting__network_proxy_host": "主机",
|
"setting__network_proxy_host": "主机",
|
||||||
"setting__network_proxy_password": "密码",
|
"setting__network_proxy_password": "密码",
|
||||||
"setting__network_proxy_port": "端口",
|
"setting__network_proxy_port": "端口",
|
||||||
|
|
|
@ -472,6 +472,9 @@
|
||||||
"setting__list_scroll": "記住播放清單滾動條位置(僅對「我的清單」有效)",
|
"setting__list_scroll": "記住播放清單滾動條位置(僅對「我的清單」有效)",
|
||||||
"setting__list_source": "顯示歌曲來自哪個音樂串流平台(僅對「我的清單」有效)",
|
"setting__list_source": "顯示歌曲來自哪個音樂串流平台(僅對「我的清單」有效)",
|
||||||
"setting__network": "網路設定",
|
"setting__network": "網路設定",
|
||||||
|
"setting__network_proxy_type_disable": "不使用代理",
|
||||||
|
"setting__network_proxy_type_system": "使用系統代理",
|
||||||
|
"setting__network_proxy_type_custom": "自訂代理",
|
||||||
"setting__network_proxy_host": "主機",
|
"setting__network_proxy_host": "主機",
|
||||||
"setting__network_proxy_password": "密碼",
|
"setting__network_proxy_password": "密碼",
|
||||||
"setting__network_proxy_port": "埠",
|
"setting__network_proxy_port": "埠",
|
||||||
|
|
|
@ -19,31 +19,41 @@ const denyEvents = [
|
||||||
'media-started-playing',
|
'media-started-playing',
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
|
|
||||||
export const getProxy = () => {
|
export const getProxy = () => {
|
||||||
if (global.lx.appSetting['network.proxy.enable'] && global.lx.appSetting['network.proxy.host']) {
|
const envProxyStr = envParams.cmdParams['proxy-server']
|
||||||
|
if (envProxyStr && typeof envProxyStr == 'string') {
|
||||||
|
const [host, port = ''] = envProxyStr.split(':')
|
||||||
return {
|
return {
|
||||||
|
host,
|
||||||
|
port: parseInt(port || '80'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (global.lx.appSetting['network.proxy.type']) {
|
||||||
|
case 'custom':
|
||||||
|
const custom = {
|
||||||
|
enable: global.lx.appSetting['network.proxy.type'] === 'custom',
|
||||||
host: global.lx.appSetting['network.proxy.host'],
|
host: global.lx.appSetting['network.proxy.host'],
|
||||||
port: global.lx.appSetting['network.proxy.port'],
|
port: global.lx.appSetting['network.proxy.port'],
|
||||||
}
|
}
|
||||||
|
return custom.enable && custom.host
|
||||||
|
? {
|
||||||
|
host: custom.host,
|
||||||
|
port: parseInt(custom.port || '80'),
|
||||||
}
|
}
|
||||||
const envProxy = envParams.cmdParams['proxy-server']
|
: {
|
||||||
if (envProxy) {
|
host: '',
|
||||||
if (envProxy && typeof envProxy == 'string') {
|
port: '',
|
||||||
const [host, port = ''] = envProxy.split(':')
|
|
||||||
return {
|
|
||||||
host,
|
|
||||||
port,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
return {
|
return {
|
||||||
host: '',
|
host: '',
|
||||||
port: '',
|
port: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const handleUpdateProxy = (keys: Array<keyof LX.AppSetting>) => {
|
const handleUpdateProxy = (keys: Array<keyof LX.AppSetting>) => {
|
||||||
if (keys.includes('network.proxy.enable') || (global.lx.appSetting['network.proxy.enable'] && keys.some(k => k.startsWith('network.proxy.')))) {
|
if (keys.some(k => k.startsWith('network.proxy.'))) {
|
||||||
sendEvent(USER_API_RENDERER_EVENT_NAME.proxyUpdate, getProxy())
|
sendEvent(USER_API_RENDERER_EVENT_NAME.proxyUpdate, getProxy())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ export default () => {
|
||||||
setProgressBar(-1, { mode: 'none' })
|
setProgressBar(-1, { mode: 'none' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (keys.includes('network.proxy.enable') || (global.lx.appSetting['network.proxy.enable'] && keys.some(k => k.includes('network.proxy.')))) {
|
if (keys.some(k => k.includes('network.proxy.'))) {
|
||||||
setProxy()
|
setProxy()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -65,12 +65,6 @@ export const createWindow = () => {
|
||||||
|
|
||||||
const { shouldUseDarkColors, theme } = global.lx.theme
|
const { shouldUseDarkColors, theme } = global.lx.theme
|
||||||
const ses = session.fromPartition('persist:win-main')
|
const ses = session.fromPartition('persist:win-main')
|
||||||
const proxy = getProxy()
|
|
||||||
if (proxy) {
|
|
||||||
void ses.setProxy({
|
|
||||||
proxyRules: `http://${proxy.host}:${proxy.port}`,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initial window options
|
* Initial window options
|
||||||
|
@ -108,11 +102,12 @@ export const createWindow = () => {
|
||||||
}
|
}
|
||||||
browserWindow = new BrowserWindow(options)
|
browserWindow = new BrowserWindow(options)
|
||||||
|
|
||||||
|
setProxy()
|
||||||
|
winEvent()
|
||||||
|
|
||||||
const winURL = process.env.NODE_ENV !== 'production' ? 'http://localhost:9080' : `file://${path.join(encodePath(__dirname), 'index.html')}`
|
const winURL = process.env.NODE_ENV !== 'production' ? 'http://localhost:9080' : `file://${path.join(encodePath(__dirname), 'index.html')}`
|
||||||
void browserWindow.loadURL(winURL + `?os=${getPlatform()}&dt=${global.envParams.cmdParams.dt}&dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
|
void browserWindow.loadURL(winURL + `?os=${getPlatform()}&dt=${global.envParams.cmdParams.dt}&dark=${shouldUseDarkColors}&theme=${encodeURIComponent(JSON.stringify(theme))}`)
|
||||||
|
|
||||||
winEvent()
|
|
||||||
|
|
||||||
if (global.envParams.cmdParams.odt) handleOpenDevTools(browserWindow.webContents)
|
if (global.envParams.cmdParams.odt) handleOpenDevTools(browserWindow.webContents)
|
||||||
|
|
||||||
// global.lx.mainWindowClosed = false
|
// global.lx.mainWindowClosed = false
|
||||||
|
@ -133,19 +128,27 @@ export const closeWindow = () => {
|
||||||
|
|
||||||
export const setProxy = () => {
|
export const setProxy = () => {
|
||||||
if (!browserWindow) return
|
if (!browserWindow) return
|
||||||
|
switch (global.lx.appSetting['network.proxy.type']) {
|
||||||
|
case 'system':
|
||||||
|
void browserWindow.webContents.session.setProxy({
|
||||||
|
mode: 'system',
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'disable':
|
||||||
|
void browserWindow.webContents.session.setProxy({
|
||||||
|
mode: 'direct',
|
||||||
|
})
|
||||||
|
break
|
||||||
|
default:
|
||||||
const proxy = getProxy()
|
const proxy = getProxy()
|
||||||
if (proxy) {
|
if (!proxy) break
|
||||||
void browserWindow.webContents.session.setProxy({
|
void browserWindow.webContents.session.setProxy({
|
||||||
proxyRules: `http://${proxy.host}:${proxy.port}`,
|
proxyRules: `http://${proxy.host}:${proxy.port}`,
|
||||||
})
|
})
|
||||||
} else {
|
break
|
||||||
void browserWindow.webContents.session.setProxy({
|
|
||||||
proxyRules: '',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const sendEvent = <T = any>(name: string, params?: T) => {
|
export const sendEvent = <T = any>(name: string, params?: T) => {
|
||||||
if (!browserWindow) return
|
if (!browserWindow) return
|
||||||
mainSend(browserWindow, name, params)
|
mainSend(browserWindow, name, params)
|
||||||
|
|
|
@ -295,30 +295,25 @@ export const setPowerSaveBlocker = (enabled: boolean) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let envProxy: null | { host: string, port: number } = null
|
|
||||||
export const getProxy = () => {
|
export const getProxy = () => {
|
||||||
if (global.lx.appSetting['network.proxy.enable'] && global.lx.appSetting['network.proxy.host']) {
|
|
||||||
return {
|
|
||||||
host: global.lx.appSetting['network.proxy.host'],
|
|
||||||
port: parseInt(global.lx.appSetting['network.proxy.port'] || '80'),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (envProxy) {
|
|
||||||
return {
|
|
||||||
host: envProxy.host,
|
|
||||||
port: envProxy.port,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const envProxyStr = envParams.cmdParams['proxy-server']
|
const envProxyStr = envParams.cmdParams['proxy-server']
|
||||||
if (envProxyStr && typeof envProxyStr == 'string') {
|
if (envProxyStr && typeof envProxyStr == 'string') {
|
||||||
const [host, port = ''] = envProxyStr.split(':')
|
const [host, port = ''] = envProxyStr.split(':')
|
||||||
return envProxy = {
|
return {
|
||||||
host,
|
host,
|
||||||
port: parseInt(port || '80'),
|
port: parseInt(port || '80'),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
const custom = {
|
||||||
|
enable: global.lx.appSetting['network.proxy.type'] === 'custom',
|
||||||
|
host: global.lx.appSetting['network.proxy.host'],
|
||||||
|
port: global.lx.appSetting['network.proxy.port'],
|
||||||
|
}
|
||||||
|
return custom.enable && custom.host
|
||||||
|
? {
|
||||||
|
host: custom.host,
|
||||||
|
port: parseInt(custom.port || '80'),
|
||||||
|
}
|
||||||
|
: null
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import handleListAutoUpdate from './listAutoUpdate'
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
// apiSource.value = appSetting['common.apiSource']
|
// apiSource.value = appSetting['common.apiSource']
|
||||||
proxy.enable = appSetting['network.proxy.enable']
|
proxy.type = appSetting['network.proxy.type']
|
||||||
proxy.host = appSetting['network.proxy.host']
|
proxy.host = appSetting['network.proxy.host']
|
||||||
proxy.port = appSetting['network.proxy.port']
|
proxy.port = appSetting['network.proxy.port']
|
||||||
isFullscreen.value = appSetting['common.startInFullscreen']
|
isFullscreen.value = appSetting['common.startInFullscreen']
|
||||||
|
|
|
@ -95,11 +95,8 @@ export default () => {
|
||||||
sync.client.host = host
|
sync.client.host = host
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(() => appSetting['network.proxy.enable'], enable => {
|
watch(() => appSetting['network.proxy.type'], type => {
|
||||||
proxy.enable = enable
|
proxy.type = type
|
||||||
})
|
|
||||||
watch(() => appSetting['network.proxy.enable'], enable => {
|
|
||||||
proxy.enable = enable
|
|
||||||
})
|
})
|
||||||
watch(() => appSetting['network.proxy.host'], host => {
|
watch(() => appSetting['network.proxy.host'], host => {
|
||||||
proxy.host = host
|
proxy.host = host
|
||||||
|
|
|
@ -134,7 +134,7 @@ const setStatus = (downloadInfo: LX.Download.ListItem, status: LX.Download.Downl
|
||||||
const fixKgLyric = (lrc: string) => /\[00:\d\d:\d\d.\d+\]/.test(lrc) ? lrc.replace(/(?:\[00:(\d\d:\d\d.\d+\]))/gm, '[$1') : lrc
|
const fixKgLyric = (lrc: string) => /\[00:\d\d:\d\d.\d+\]/.test(lrc) ? lrc.replace(/(?:\[00:(\d\d:\d\d.\d+\]))/gm, '[$1') : lrc
|
||||||
|
|
||||||
const getProxy = () => {
|
const getProxy = () => {
|
||||||
return proxy.enable && proxy.host ? {
|
return proxy.type === 'custom' && proxy.host ? {
|
||||||
host: proxy.host,
|
host: proxy.host,
|
||||||
port: parseInt(proxy.port || '80'),
|
port: parseInt(proxy.port || '80'),
|
||||||
} : proxy.envProxy ? {
|
} : proxy.envProxy ? {
|
||||||
|
|
|
@ -8,16 +8,15 @@ process.versions.app = pkg.version
|
||||||
|
|
||||||
export const apiSource = ref<string | null>(null)
|
export const apiSource = ref<string | null>(null)
|
||||||
export const proxy: {
|
export const proxy: {
|
||||||
enable: boolean
|
type: LX.AppSetting['network.proxy.type']
|
||||||
host: string
|
host: string
|
||||||
port: string
|
port: string
|
||||||
|
|
||||||
envProxy?: {
|
envProxy?: {
|
||||||
host: string
|
host: string
|
||||||
port: string
|
port: string
|
||||||
}
|
}
|
||||||
} = {
|
} = {
|
||||||
enable: false,
|
type: 'disable',
|
||||||
host: '',
|
host: '',
|
||||||
port: '',
|
port: '',
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,23 +10,12 @@ import { httpOverHttp, httpsOverHttp } from 'tunnel'
|
||||||
|
|
||||||
const httpsRxp = /^https:/
|
const httpsRxp = /^https:/
|
||||||
const getRequestAgent = url => {
|
const getRequestAgent = url => {
|
||||||
let options
|
const options = proxy.type === 'custom' && proxy.host
|
||||||
if (proxy.enable && proxy.host) {
|
? { host: proxy.host, port: parseInt(proxy.port || '80') }
|
||||||
options = {
|
: proxy.envProxy
|
||||||
proxy: {
|
? { host: proxy.envProxy.host, port: parseInt(proxy.envProxy.port || '80') }
|
||||||
host: proxy.host,
|
: null
|
||||||
port: proxy.port,
|
return options ? (httpsRxp.test(url) ? httpsOverHttp : httpOverHttp)({ proxy: options }) : undefined
|
||||||
},
|
|
||||||
}
|
|
||||||
} else if (proxy.envProxy) {
|
|
||||||
options = {
|
|
||||||
proxy: {
|
|
||||||
host: proxy.envProxy.host,
|
|
||||||
port: proxy.envProxy.port,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return options ? (httpsRxp.test(url) ? httpsOverHttp : httpOverHttp)(options) : undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,18 @@ dd
|
||||||
h3#network_proxy_title {{ $t('setting__network_proxy_title') }}
|
h3#network_proxy_title {{ $t('setting__network_proxy_title') }}
|
||||||
div
|
div
|
||||||
.p
|
.p
|
||||||
base-checkbox(id="setting_network_proxy_enable" :model-value="appSetting['network.proxy.enable']" :label="$t('setting__is_enable')" @update:model-value="updateSetting({'network.proxy.enable': $event})")
|
base-checkbox.gap-left(id="setting_network_proxy_type_disable" key="disable" value="disable" need :model-value="appSetting['network.proxy.type']" :label="$t('setting__network_proxy_type_disable')" @update:model-value="updateSetting({'network.proxy.type': 'disable'})")
|
||||||
|
base-checkbox.gap-left(id="setting_network_proxy_type_system" key="system" value="system" need :model-value="appSetting['network.proxy.type']" :label="$t('setting__network_proxy_type_system')" @update:model-value="updateSetting({'network.proxy.type': 'system'})")
|
||||||
|
base-checkbox.gap-left(id="setting_network_proxy_type_custom" key="custom" value="custom" need :model-value="appSetting['network.proxy.type']" :label="$t('setting__network_proxy_type_custom')" @update:model-value="updateSetting({'network.proxy.type': 'custom'})")
|
||||||
|
.p(v-if="appSetting['network.proxy.type'] == 'custom'")
|
||||||
.p
|
.p
|
||||||
base-input(:model-value="appSetting['network.proxy.host']" :placeholder="proxy.envProxy ? proxy.envProxy.host : $t('setting__network_proxy_host')" @update:model-value="setHost")
|
base-input(:model-value="appSetting['network.proxy.host']" :placeholder="proxy.envProxy ? proxy.envProxy.host : $t('setting__network_proxy_host')" @update:model-value="setHost")
|
||||||
.p
|
.p
|
||||||
base-input(:model-value="appSetting['network.proxy.port']" :placeholder="proxy.envProxy ? proxy.envProxy.port : $t('setting__network_proxy_port')" @update:model-value="setPort")
|
base-input(:model-value="appSetting['network.proxy.port']" :placeholder="proxy.envProxy ? proxy.envProxy.port : $t('setting__network_proxy_port')" @update:model-value="setPort")
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { onBeforeUnmount } from '@common/utils/vueTools'
|
import { onMounted, onBeforeUnmount } from '@common/utils/vueTools'
|
||||||
import { proxy } from '@renderer/store'
|
import { proxy } from '@renderer/store'
|
||||||
import { debounce } from '@common/utils'
|
import { debounce } from '@common/utils'
|
||||||
|
|
||||||
|
@ -29,8 +31,15 @@ export default {
|
||||||
updateSetting({ 'network.proxy.port': port.trim() })
|
updateSetting({ 'network.proxy.port': port.trim() })
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
||||||
|
let prevProxyType
|
||||||
|
onMounted(() => {
|
||||||
|
prevProxyType = appSetting['network.proxy.type']
|
||||||
|
})
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
if (appSetting['network.proxy.enable'] && !appSetting['network.proxy.host']) proxy.enable = false
|
if (appSetting['network.proxy.type'] === 'custom' && !appSetting['network.proxy.host']) {
|
||||||
|
if (prevProxyType && prevProxyType != 'custom') updateSetting({ 'network.proxy.type': prevProxyType })
|
||||||
|
else updateSetting({ 'network.proxy.type': 'system' })
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue