mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +08:00
support copy env
This commit is contained in:
parent
469e9d2818
commit
dcb3efbfb8
@ -1,3 +1,7 @@
|
|||||||
|
### New Features
|
||||||
|
|
||||||
|
- 支持一键复制环境变量
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
- 修复托盘菜单在Linux下崩溃的问题
|
- 修复托盘菜单在Linux下崩溃的问题
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import {
|
|||||||
patchMihomoConfig
|
patchMihomoConfig
|
||||||
} from '../core/mihomoApi'
|
} from '../core/mihomoApi'
|
||||||
import { mainWindow, showMainWindow } from '..'
|
import { mainWindow, showMainWindow } from '..'
|
||||||
import { app, ipcMain, Menu, nativeImage, shell, Tray } from 'electron'
|
import { app, clipboard, ipcMain, Menu, nativeImage, shell, Tray } from 'electron'
|
||||||
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
|
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
|
||||||
import { triggerSysProxy } from '../sys/sysproxy'
|
import { triggerSysProxy } from '../sys/sysproxy'
|
||||||
|
|
||||||
@ -170,6 +170,12 @@ const buildContextMenu = async (): Promise<Menu> => {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'copyenv',
|
||||||
|
label: '复制环境变量',
|
||||||
|
type: 'normal',
|
||||||
|
click: copyEnv
|
||||||
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
id: 'restart',
|
id: 'restart',
|
||||||
@ -250,3 +256,30 @@ async function updateTrayMenu(): Promise<void> {
|
|||||||
tray?.setContextMenu(menu)
|
tray?.setContextMenu(menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function copyEnv(): Promise<void> {
|
||||||
|
const defaultType = process.platform === 'win32' ? 'powershell' : 'bash'
|
||||||
|
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
|
||||||
|
const { envType = defaultType, sysProxy } = await getAppConfig()
|
||||||
|
const { host } = sysProxy
|
||||||
|
switch (envType) {
|
||||||
|
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}`
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'cmd': {
|
||||||
|
clipboard.writeText(
|
||||||
|
`set http_proxy=http://${host || '127.0.0.1'}:${mixedPort}\r\nset https_proxy=http://${host || '127.0.0.1'}:${mixedPort}`
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'powershell': {
|
||||||
|
clipboard.writeText(
|
||||||
|
`$env:HTTP_PROXY="http://${host || '127.0.0.1'}:${mixedPort}"; $env:HTTPS_PROXY="http://${host || '127.0.0.1'}:${mixedPort}"`
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -53,6 +53,7 @@ import { getRuntimeConfig, getRuntimeConfigStr } from '../core/factory'
|
|||||||
import { isPortable, setPortable } from './dirs'
|
import { isPortable, setPortable } from './dirs'
|
||||||
import { listWebdavBackups, webdavBackup, webdavRestore } from '../resolve/backup'
|
import { listWebdavBackups, webdavBackup, webdavRestore } from '../resolve/backup'
|
||||||
import { getInterfaces } from '../sys/interface'
|
import { getInterfaces } from '../sys/interface'
|
||||||
|
import { copyEnv } from '../resolve/tray'
|
||||||
|
|
||||||
function ipcErrorWrapper<T>( // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
function ipcErrorWrapper<T>( // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
fn: (...args: any[]) => Promise<T> // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
fn: (...args: any[]) => Promise<T> // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@ -148,6 +149,7 @@ export function registerIpcMainHandlers(): void {
|
|||||||
ipcMain.handle('webdavBackup', ipcErrorWrapper(webdavBackup))
|
ipcMain.handle('webdavBackup', ipcErrorWrapper(webdavBackup))
|
||||||
ipcMain.handle('webdavRestore', (_e, filename) => ipcErrorWrapper(webdavRestore)(filename))
|
ipcMain.handle('webdavRestore', (_e, filename) => ipcErrorWrapper(webdavRestore)(filename))
|
||||||
ipcMain.handle('listWebdavBackups', ipcErrorWrapper(listWebdavBackups))
|
ipcMain.handle('listWebdavBackups', ipcErrorWrapper(listWebdavBackups))
|
||||||
|
ipcMain.handle('copyEnv', ipcErrorWrapper(copyEnv))
|
||||||
ipcMain.handle('alert', (_e, msg) => {
|
ipcMain.handle('alert', (_e, msg) => {
|
||||||
dialog.showErrorBox('Mihomo Party', msg)
|
dialog.showErrorBox('Mihomo Party', msg)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -15,8 +15,10 @@ import {
|
|||||||
setPortable,
|
setPortable,
|
||||||
restartCore,
|
restartCore,
|
||||||
webdavBackup,
|
webdavBackup,
|
||||||
listWebdavBackups
|
listWebdavBackups,
|
||||||
|
copyEnv
|
||||||
} from '@renderer/utils/ipc'
|
} from '@renderer/utils/ipc'
|
||||||
|
import { BiCopy } from 'react-icons/bi'
|
||||||
import { CgWebsite } from 'react-icons/cg'
|
import { CgWebsite } from 'react-icons/cg'
|
||||||
import { IoLogoGithub } from 'react-icons/io5'
|
import { IoLogoGithub } from 'react-icons/io5'
|
||||||
import { platform, version } from '@renderer/utils/init'
|
import { platform, version } from '@renderer/utils/init'
|
||||||
@ -38,6 +40,7 @@ const Settings: React.FC = () => {
|
|||||||
useDockIcon = true,
|
useDockIcon = true,
|
||||||
showTraffic = true,
|
showTraffic = true,
|
||||||
proxyInTray = true,
|
proxyInTray = true,
|
||||||
|
envType = platform === 'win32' ? 'powershell' : 'bash',
|
||||||
delayTestUrl,
|
delayTestUrl,
|
||||||
delayTestTimeout,
|
delayTestTimeout,
|
||||||
autoCheckUpdate,
|
autoCheckUpdate,
|
||||||
@ -195,6 +198,32 @@ const Settings: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
<SettingItem
|
||||||
|
title="复制环境变量类型"
|
||||||
|
actions={
|
||||||
|
<Button isIconOnly size="sm" className="ml-2" variant="light" onPress={copyEnv}>
|
||||||
|
<BiCopy className="text-lg" />
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
divider
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
className="w-[150px]"
|
||||||
|
size="sm"
|
||||||
|
selectedKeys={new Set([envType])}
|
||||||
|
onSelectionChange={async (v) => {
|
||||||
|
try {
|
||||||
|
await patchAppConfig({ envType: v.currentKey as 'bash' | 'cmd' | 'powershell' })
|
||||||
|
} catch (e) {
|
||||||
|
alert(e)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectItem key="bash">Bash</SelectItem>
|
||||||
|
<SelectItem key="cmd">CMD</SelectItem>
|
||||||
|
<SelectItem key="powershell">PowerShell</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</SettingItem>
|
||||||
{platform !== 'linux' && (
|
{platform !== 'linux' && (
|
||||||
<SettingItem title="托盘菜单显示节点信息" divider>
|
<SettingItem title="托盘菜单显示节点信息" divider>
|
||||||
<Switch
|
<Switch
|
||||||
@ -206,7 +235,6 @@ const Settings: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{platform === 'darwin' && (
|
{platform === 'darwin' && (
|
||||||
<>
|
<>
|
||||||
<SettingItem title="显示Dock图标" divider>
|
<SettingItem title="显示Dock图标" divider>
|
||||||
|
|||||||
@ -283,6 +283,10 @@ export async function quitApp(): Promise<void> {
|
|||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('quitApp'))
|
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('quitApp'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function copyEnv(): Promise<void> {
|
||||||
|
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('copyEnv'))
|
||||||
|
}
|
||||||
|
|
||||||
async function alert<T>(msg: T): Promise<void> {
|
async function alert<T>(msg: T): Promise<void> {
|
||||||
const msgStr = typeof msg === 'string' ? msg : JSON.stringify(msg)
|
const msgStr = typeof msg === 'string' ? msg : JSON.stringify(msg)
|
||||||
return await window.electron.ipcRenderer.invoke('alert', msgStr)
|
return await window.electron.ipcRenderer.invoke('alert', msgStr)
|
||||||
|
|||||||
1
src/shared/types.d.ts
vendored
1
src/shared/types.d.ts
vendored
@ -214,6 +214,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'
|
||||||
proxyInTray: boolean
|
proxyInTray: boolean
|
||||||
siderOrder: string[]
|
siderOrder: string[]
|
||||||
appTheme: AppTheme
|
appTheme: AppTheme
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user