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
- 支持自定义CSS样式
- 支持自定义主题
- 复制环境变量类型支持多选
- 添加用户验证相关设置

View File

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

View File

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

View File

@ -205,7 +205,7 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('resolveThemes', () => ipcErrorWrapper(resolveThemes)())
ipcMain.handle('fetchThemes', () => ipcErrorWrapper(fetchThemes)())
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) => {
dialog.showErrorBox('Mihomo Party', msg)
})

View File

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

View File

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

View File

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

View File

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