support multiple env copy type

This commit is contained in:
pompurin404 2024-09-20 14:15:50 +08:00
parent ddfa4e75f3
commit f156dd1311
No known key found for this signature in database
8 changed files with 66 additions and 30 deletions

View File

@ -4,5 +4,6 @@
### Features ### Features
- 支持自定义CSS样式 - 支持自定义主题
- 复制环境变量类型支持多选
- 添加用户验证相关设置 - 添加用户验证相关设置

View File

@ -27,6 +27,7 @@ const buildContextMenu = async (): Promise<Menu> => {
const { mode, tun } = await getControledMihomoConfig() const { mode, tun } = await getControledMihomoConfig()
const { const {
sysProxy, sysProxy,
envType = process.platform === 'win32' ? ['powershell'] : ['bash'],
autoCloseConnection, autoCloseConnection,
proxyInTray = true, proxyInTray = true,
triggerSysProxyShortcut = '', triggerSysProxyShortcut = '',
@ -210,12 +211,29 @@ const buildContextMenu = async (): Promise<Menu> => {
} }
] ]
}, },
{ envType.length > 1
id: 'copyenv', ? {
label: '复制环境变量', type: 'submenu',
type: 'normal', label: '复制环境变量',
click: copyEnv submenu: envType.map((type) => {
}, return {
id: type,
label: type,
type: 'normal',
click: async (): Promise<void> => {
await copyEnv(type)
}
}
})
}
: {
id: 'copyenv',
label: '复制环境变量',
type: 'normal',
click: async (): Promise<void> => {
await copyEnv(envType[0])
}
},
{ type: 'separator' }, { type: 'separator' },
{ {
id: 'quitWithoutCore', id: 'quitWithoutCore',
@ -316,12 +334,11 @@ async function updateTrayMenu(): Promise<void> {
} }
} }
export async function copyEnv(): Promise<void> { export async function copyEnv(type: 'bash' | 'cmd' | 'powershell'): Promise<void> {
const defaultType = process.platform === 'win32' ? 'powershell' : 'bash'
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig() const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
const { envType = defaultType, sysProxy } = await getAppConfig() const { sysProxy } = await getAppConfig()
const { host } = sysProxy const { host } = sysProxy
switch (envType) { switch (type) {
case 'bash': { case 'bash': {
clipboard.writeText( clipboard.writeText(
`export https_proxy=http://${host || '127.0.0.1'}:${mixedPort} http_proxy=http://${host || '127.0.0.1'}:${mixedPort} all_proxy=http://${host || '127.0.0.1'}:${mixedPort}` `export https_proxy=http://${host || '127.0.0.1'}:${mixedPort} http_proxy=http://${host || '127.0.0.1'}:${mixedPort} all_proxy=http://${host || '127.0.0.1'}:${mixedPort}`

View File

@ -146,6 +146,7 @@ async function migration(): Promise<void> {
'substore' 'substore'
], ],
appTheme = 'system', appTheme = 'system',
envType = [process.platform === 'win32' ? 'powershell' : 'bash'],
useSubStore = true useSubStore = true
} = await getAppConfig() } = await getAppConfig()
const { const {
@ -183,6 +184,10 @@ async function migration(): Promise<void> {
if (!['system', 'light', 'dark'].includes(appTheme)) { if (!['system', 'light', 'dark'].includes(appTheme)) {
await patchAppConfig({ appTheme: 'system' }) await patchAppConfig({ appTheme: 'system' })
} }
// change env type
if (typeof envType === 'string') {
await patchAppConfig({ envType: [envType] })
}
} }
function initDeeplink(): void { function initDeeplink(): void {

View File

@ -205,7 +205,7 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('resolveThemes', () => ipcErrorWrapper(resolveThemes)()) ipcMain.handle('resolveThemes', () => ipcErrorWrapper(resolveThemes)())
ipcMain.handle('fetchThemes', () => ipcErrorWrapper(fetchThemes)()) ipcMain.handle('fetchThemes', () => ipcErrorWrapper(fetchThemes)())
ipcMain.handle('applyTheme', (_e, theme) => ipcErrorWrapper(applyTheme)(theme)) ipcMain.handle('applyTheme', (_e, theme) => ipcErrorWrapper(applyTheme)(theme))
ipcMain.handle('copyEnv', ipcErrorWrapper(copyEnv)) ipcMain.handle('copyEnv', (_e, type) => ipcErrorWrapper(copyEnv)(type))
ipcMain.handle('alert', (_e, msg) => { ipcMain.handle('alert', (_e, msg) => {
dialog.showErrorBox('Mihomo Party', msg) dialog.showErrorBox('Mihomo Party', msg)
}) })

View File

@ -84,16 +84,18 @@ const App: React.FC = () => {
setTheme(appTheme) setTheme(appTheme)
if (customTheme) applyTheme(customTheme) if (customTheme) applyTheme(customTheme)
if (!useWindowFrame) { if (!useWindowFrame) {
const options = { height: 48 } as TitleBarOverlayOptions setTimeout(() => {
try { const options = { height: 48 } as TitleBarOverlayOptions
if (platform !== 'darwin') { try {
options.color = window.getComputedStyle(document.documentElement).backgroundColor if (platform !== 'darwin') {
options.symbolColor = window.getComputedStyle(document.documentElement).color options.color = window.getComputedStyle(document.documentElement).backgroundColor
options.symbolColor = window.getComputedStyle(document.documentElement).color
}
setTitleBarOverlay(options)
} catch (e) {
// ignore
} }
setTitleBarOverlay(options) }, 0)
} catch (e) {
// ignore
}
} }
}, [appTheme, systemTheme, customTheme]) }, [appTheme, systemTheme, customTheme])

View File

@ -36,7 +36,7 @@ const GeneralConfig: React.FC = () => {
autoQuitWithoutCore = false, autoQuitWithoutCore = false,
autoQuitWithoutCoreDelay = 60, autoQuitWithoutCoreDelay = 60,
customTheme = 'default.css', customTheme = 'default.css',
envType = platform === 'win32' ? 'powershell' : 'bash', envType = [platform === 'win32' ? 'powershell' : 'bash'],
autoCheckUpdate, autoCheckUpdate,
appTheme = 'system' appTheme = 'system'
} = appConfig || {} } = appConfig || {}
@ -125,20 +125,31 @@ const GeneralConfig: React.FC = () => {
)} )}
<SettingItem <SettingItem
title="复制环境变量类型" title="复制环境变量类型"
actions={ actions={envType.map((type) => (
<Button isIconOnly size="sm" className="ml-2" variant="light" onPress={copyEnv}> <Button
key={type}
title={type}
isIconOnly
size="sm"
className="ml-2"
variant="light"
onPress={() => copyEnv(type)}
>
<BiCopy className="text-lg" /> <BiCopy className="text-lg" />
</Button> </Button>
} ))}
divider divider
> >
<Select <Select
className="w-[150px]" className="w-[150px]"
size="sm" size="sm"
selectedKeys={new Set([envType])} selectionMode="multiple"
selectedKeys={new Set(envType)}
onSelectionChange={async (v) => { onSelectionChange={async (v) => {
try { try {
await patchAppConfig({ envType: v.currentKey as 'bash' | 'cmd' | 'powershell' }) await patchAppConfig({
envType: Array.from(v) as ('bash' | 'cmd' | 'powershell')[]
})
} catch (e) { } catch (e) {
alert(e) alert(e)
} }

View File

@ -353,8 +353,8 @@ export async function registerShortcut(
) )
} }
export async function copyEnv(): Promise<void> { export async function copyEnv(type: 'bash' | 'cmd' | 'powershell'): Promise<void> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('copyEnv')) return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('copyEnv', type))
} }
async function alert<T>(msg: T): Promise<void> { async function alert<T>(msg: T): Promise<void> {

View File

@ -206,7 +206,7 @@ interface IAppConfig {
core: 'mihomo' | 'mihomo-alpha' core: 'mihomo' | 'mihomo-alpha'
proxyDisplayMode: 'simple' | 'full' proxyDisplayMode: 'simple' | 'full'
proxyDisplayOrder: 'default' | 'delay' | 'name' proxyDisplayOrder: 'default' | 'delay' | 'name'
envType?: 'bash' | 'cmd' | 'powershell' envType?: ('bash' | 'cmd' | 'powershell')[]
proxyCols: 'auto' | '1' | '2' | '3' | '4' proxyCols: 'auto' | '1' | '2' | '3' | '4'
connectionDirection: 'asc' | 'desc' connectionDirection: 'asc' | 'desc'
connectionOrderBy: 'time' | 'upload' | 'download' | 'uploadSpeed' | 'downloadSpeed' connectionOrderBy: 'time' | 'upload' | 'download' | 'uploadSpeed' | 'downloadSpeed'