pull/2382/head
lyswhut 2025-05-10 10:32:07 +08:00
parent 9a692a99f6
commit 4a2201f33a
17 changed files with 99 additions and 109 deletions

View File

@ -1,4 +1,8 @@
### 新增 ### 新增
- 新增「设置 → 其他设置 → 主窗口使用软件内置的圆角及阴影」设置(#2360 - 新增「设置 → 其他设置 → 主窗口使用软件内置的圆角及阴影」设置(#2360
*默认启用,关闭后将使用系统原生的窗口样式,该设置重启软件后生效* *默认启用,关闭后将使用系统原生的窗口样式,该设置重启软件后生效*
### 变更
- 更新代理配置规则,现在不启用代理时,图片、音频加载将不再走系统代理(#2382 @Folltoshe

View File

@ -128,7 +128,7 @@ const defaultSetting: LX.AppSetting = {
'search.isShowHistorySearch': false, 'search.isShowHistorySearch': false,
'search.isFocusSearchBox': false, 'search.isFocusSearchBox': false,
'network.proxy.type': 'disable', 'network.proxy.enable': false,
'network.proxy.host': '', 'network.proxy.host': '',
'network.proxy.port': '', 'network.proxy.port': '',

View File

@ -596,9 +596,9 @@ declare global {
'search.isFocusSearchBox': boolean 'search.isFocusSearchBox': boolean
/** /**
* *
*/ */
'network.proxy.type': 'disable' | 'system' | 'custom' 'network.proxy.enable': boolean
/** /**
* *

View File

@ -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

View File

@ -472,9 +472,6 @@
"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",

View File

@ -472,9 +472,6 @@
"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": "端口",

View File

@ -472,9 +472,6 @@
"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": "埠",

View File

@ -19,41 +19,31 @@ const denyEvents = [
'media-started-playing', 'media-started-playing',
] as const ] as const
export const getProxy = () => { export const getProxy = () => {
const envProxyStr = envParams.cmdParams['proxy-server'] if (global.lx.appSetting['network.proxy.enable'] && global.lx.appSetting['network.proxy.host']) {
if (envProxyStr && typeof envProxyStr == 'string') {
const [host, port = ''] = envProxyStr.split(':')
return { return {
host, host: global.lx.appSetting['network.proxy.host'],
port: parseInt(port || '80'), port: global.lx.appSetting['network.proxy.port'],
} }
} }
const envProxy = envParams.cmdParams['proxy-server']
switch (global.lx.appSetting['network.proxy.type']) { if (envProxy) {
case 'custom': if (envProxy && typeof envProxy == 'string') {
const custom = { const [host, port = ''] = envProxy.split(':')
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'),
}
: {
host: '',
port: '',
}
default:
return { return {
host: '', host,
port: '', port,
} }
}
}
return {
host: '',
port: '',
} }
} }
const handleUpdateProxy = (keys: Array<keyof LX.AppSetting>) => { const handleUpdateProxy = (keys: Array<keyof LX.AppSetting>) => {
if (keys.some(k => k.startsWith('network.proxy.'))) { if (keys.includes('network.proxy.enable') || (global.lx.appSetting['network.proxy.enable'] && keys.some(k => k.startsWith('network.proxy.')))) {
sendEvent(USER_API_RENDERER_EVENT_NAME.proxyUpdate, getProxy()) sendEvent(USER_API_RENDERER_EVENT_NAME.proxyUpdate, getProxy())
} }
} }

View File

@ -108,7 +108,7 @@ export default () => {
setProgressBar(-1, { mode: 'none' }) setProgressBar(-1, { mode: 'none' })
} }
} }
if (keys.some(k => k.includes('network.proxy.'))) { if (keys.includes('network.proxy.enable') || (global.lx.appSetting['network.proxy.enable'] && keys.some(k => k.includes('network.proxy.')))) {
setProxy() setProxy()
} }
}) })

View File

@ -65,6 +65,8 @@ 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()
setSesProxy(ses, proxy?.host, String(proxy?.port))
/** /**
* Initial window options * Initial window options
@ -102,12 +104,11 @@ 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
@ -126,28 +127,24 @@ export const closeWindow = () => {
browserWindow.close() browserWindow.close()
} }
export const setProxy = () => { const setSesProxy = (ses: Electron.Session, host?: string, port?: string) => {
if (!browserWindow) return if (host) {
switch (global.lx.appSetting['network.proxy.type']) { void ses.setProxy({
case 'system': mode: 'fixed_servers',
void browserWindow.webContents.session.setProxy({ proxyRules: `http://${host}:${port}`,
mode: 'system', })
}) } else {
break void ses.setProxy({
case 'disable': mode: 'direct',
void browserWindow.webContents.session.setProxy({ })
mode: 'direct',
})
break
default:
const proxy = getProxy()
if (!proxy) break
void browserWindow.webContents.session.setProxy({
proxyRules: `http://${proxy.host}:${proxy.port}`,
})
break
} }
} }
export const setProxy = () => {
if (!browserWindow) return
const proxy = getProxy()
setSesProxy(browserWindow.webContents.session, proxy?.host, String(proxy?.port))
}
export const sendEvent = <T = any>(name: string, params?: T) => { export const sendEvent = <T = any>(name: string, params?: T) => {
if (!browserWindow) return if (!browserWindow) return

View File

@ -295,25 +295,30 @@ export const setPowerSaveBlocker = (enabled: boolean) => {
} }
} }
let envProxy: null | { host: string, port: number } = null
export const getProxy = () => { export const getProxy = () => {
const envProxyStr = envParams.cmdParams['proxy-server'] if (global.lx.appSetting['network.proxy.enable'] && global.lx.appSetting['network.proxy.host']) {
if (envProxyStr && typeof envProxyStr == 'string') {
const [host, port = ''] = envProxyStr.split(':')
return { return {
host, host: global.lx.appSetting['network.proxy.host'],
port: parseInt(port || '80'), 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']
if (envProxyStr && typeof envProxyStr == 'string') {
const [host, port = ''] = envProxyStr.split(':')
return envProxy = {
host,
port: parseInt(port || '80'),
}
} }
} }
const custom = { return null
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
} }

View File

@ -19,7 +19,7 @@ import handleListAutoUpdate from './listAutoUpdate'
export default () => { export default () => {
// apiSource.value = appSetting['common.apiSource'] // apiSource.value = appSetting['common.apiSource']
proxy.type = appSetting['network.proxy.type'] proxy.enable = appSetting['network.proxy.enable']
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']

View File

@ -95,8 +95,8 @@ export default () => {
sync.client.host = host sync.client.host = host
}) })
watch(() => appSetting['network.proxy.type'], type => { watch(() => appSetting['network.proxy.enable'], enable => {
proxy.type = type proxy.enable = enable
}) })
watch(() => appSetting['network.proxy.host'], host => { watch(() => appSetting['network.proxy.host'], host => {
proxy.host = host proxy.host = host

View File

@ -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.type === 'custom' && proxy.host ? { return proxy.enable && proxy.host ? {
host: proxy.host, host: proxy.host,
port: parseInt(proxy.port || '80'), port: parseInt(proxy.port || '80'),
} : proxy.envProxy ? { } : proxy.envProxy ? {

View File

@ -8,15 +8,16 @@ 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: {
type: LX.AppSetting['network.proxy.type'] enable: boolean
host: string host: string
port: string port: string
envProxy?: { envProxy?: {
host: string host: string
port: string port: string
} }
} = { } = {
type: 'disable', enable: false,
host: '', host: '',
port: '', port: '',
} }

View File

@ -10,12 +10,23 @@ import { httpOverHttp, httpsOverHttp } from 'tunnel'
const httpsRxp = /^https:/ const httpsRxp = /^https:/
const getRequestAgent = url => { const getRequestAgent = url => {
const options = proxy.type === 'custom' && proxy.host let options
? { host: proxy.host, port: parseInt(proxy.port || '80') } if (proxy.enable && proxy.host) {
: proxy.envProxy options = {
? { host: proxy.envProxy.host, port: parseInt(proxy.envProxy.port || '80') } proxy: {
: null host: proxy.host,
return options ? (httpsRxp.test(url) ? httpsOverHttp : httpOverHttp)({ proxy: options }) : undefined port: proxy.port,
},
}
} else if (proxy.envProxy) {
options = {
proxy: {
host: proxy.envProxy.host,
port: proxy.envProxy.port,
},
}
}
return options ? (httpsRxp.test(url) ? httpsOverHttp : httpOverHttp)(options) : undefined
} }

View File

@ -4,18 +4,16 @@ 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.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(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_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'})") .p
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'})") base-input(:model-value="appSetting['network.proxy.host']" :placeholder="proxy.envProxy ? proxy.envProxy.host : $t('setting__network_proxy_host')" @update:model-value="setHost")
.p(v-if="appSetting['network.proxy.type'] == 'custom'") .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.host']" :placeholder="proxy.envProxy ? proxy.envProxy.host : $t('setting__network_proxy_host')" @update:model-value="setHost")
.p
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 { onMounted, onBeforeUnmount } from '@common/utils/vueTools' import { 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'
@ -31,15 +29,8 @@ 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.type'] === 'custom' && !appSetting['network.proxy.host']) { if (appSetting['network.proxy.enable'] && !appSetting['network.proxy.host']) proxy.enable = false
if (prevProxyType && prevProxyType != 'custom') updateSetting({ 'network.proxy.type': prevProxyType })
else updateSetting({ 'network.proxy.type': 'system' })
}
}) })
return { return {