mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-15 19:22:31 +08:00
support multiple env copy type
This commit is contained in:
parent
ddfa4e75f3
commit
f156dd1311
|
@ -4,5 +4,6 @@
|
|||
|
||||
### Features
|
||||
|
||||
- 支持自定义CSS样式
|
||||
- 支持自定义主题
|
||||
- 复制环境变量类型支持多选
|
||||
- 添加用户验证相关设置
|
||||
|
|
|
@ -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}`
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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])
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
2
src/shared/types.d.ts
vendored
2
src/shared/types.d.ts
vendored
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue
Block a user