mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
Compare commits
3 Commits
99a5505d16
...
9681f77e20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9681f77e20 | ||
|
|
f488cc3643 | ||
|
|
6832db788a |
@ -11,6 +11,7 @@ import { defaultProfile } from '../utils/template'
|
||||
import { subStorePort } from '../resolve/server'
|
||||
import { join } from 'path'
|
||||
import { app } from 'electron'
|
||||
import { mihomoUpgradeConfig } from '../core/mihomoApi'
|
||||
|
||||
let profileConfig: IProfileConfig // profile.yaml
|
||||
// 最终选中订阅ID
|
||||
@ -221,7 +222,25 @@ export async function setProfileStr(id: string, content: string): Promise<void>
|
||||
// 读取最新的配置
|
||||
const { current } = await getProfileConfig(true)
|
||||
await writeFile(profilePath(id), content, 'utf-8')
|
||||
if (current === id) await restartCore()
|
||||
if (current === id) {
|
||||
try {
|
||||
const { generateProfile } = await import('../core/factory')
|
||||
await generateProfile()
|
||||
await mihomoUpgradeConfig()
|
||||
console.log('[Profile] Config reloaded successfully using mihomoUpgradeConfig')
|
||||
} catch (error) {
|
||||
console.error('[Profile] Failed to reload config with mihomoUpgradeConfig:', error)
|
||||
try {
|
||||
console.log('[Profile] Falling back to restart core')
|
||||
const { restartCore } = await import('../core/manager')
|
||||
await restartCore()
|
||||
console.log('[Profile] Core restarted successfully')
|
||||
} catch (restartError) {
|
||||
console.error('[Profile] Failed to restart core:', restartError)
|
||||
throw restartError
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getProfile(id: string | undefined): Promise<IMihomoConfig> {
|
||||
|
||||
@ -188,6 +188,33 @@ export const mihomoUpgradeUI = async (): Promise<void> => {
|
||||
return await instance.post('/upgrade/ui')
|
||||
}
|
||||
|
||||
export const mihomoUpgradeConfig = async (): Promise<void> => {
|
||||
console.log('[mihomoApi] mihomoUpgradeConfig called')
|
||||
|
||||
try {
|
||||
const instance = await getAxios()
|
||||
console.log('[mihomoApi] axios instance obtained')
|
||||
const { diffWorkDir = false } = await getAppConfig()
|
||||
const { current } = await import('../config').then(mod => mod.getProfileConfig(true))
|
||||
const { mihomoWorkConfigPath } = await import('../utils/dirs')
|
||||
const configPath = diffWorkDir ? mihomoWorkConfigPath(current) : mihomoWorkConfigPath('work')
|
||||
console.log('[mihomoApi] config path:', configPath)
|
||||
const { existsSync } = await import('fs')
|
||||
if (!existsSync(configPath)) {
|
||||
console.log('[mihomoApi] config file does not exist, generating...')
|
||||
const { generateProfile } = await import('./factory')
|
||||
await generateProfile()
|
||||
}
|
||||
const response = await instance.put('/configs?force=true', {
|
||||
path: configPath
|
||||
})
|
||||
console.log('[mihomoApi] config upgrade request completed', response?.status || 'no status')
|
||||
} catch (error) {
|
||||
console.error('[mihomoApi] Failed to upgrade config:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// Smart 内核 API
|
||||
export const mihomoSmartGroupWeights = async (
|
||||
groupName: string
|
||||
|
||||
@ -434,11 +434,17 @@ export async function createWindow(): Promise<void> {
|
||||
}
|
||||
|
||||
export function triggerMainWindow(): void {
|
||||
if (mainWindow?.isVisible()) {
|
||||
if (mainWindow) {
|
||||
getAppConfig()
|
||||
.then(({ triggerMainWindowBehavior = 'show' }) => {
|
||||
if (triggerMainWindowBehavior === 'toggle' && mainWindow?.isVisible()) {
|
||||
closeMainWindow()
|
||||
} else {
|
||||
showMainWindow()
|
||||
}
|
||||
})
|
||||
.catch(showMainWindow)
|
||||
}
|
||||
}
|
||||
|
||||
export function showMainWindow(): void {
|
||||
|
||||
@ -16,6 +16,7 @@ import {
|
||||
mihomoUpgrade,
|
||||
mihomoUpgradeGeo,
|
||||
mihomoUpgradeUI,
|
||||
mihomoUpgradeConfig,
|
||||
mihomoVersion,
|
||||
patchMihomoConfig,
|
||||
mihomoSmartGroupWeights,
|
||||
@ -169,6 +170,7 @@ export function registerIpcMainHandlers(): void {
|
||||
ipcMain.handle('mihomoUpgradeGeo', ipcErrorWrapper(mihomoUpgradeGeo))
|
||||
ipcMain.handle('mihomoUpgrade', ipcErrorWrapper(mihomoUpgrade))
|
||||
ipcMain.handle('mihomoUpgradeUI', ipcErrorWrapper(mihomoUpgradeUI))
|
||||
ipcMain.handle('mihomoUpgradeConfig', ipcErrorWrapper(mihomoUpgradeConfig))
|
||||
ipcMain.handle('mihomoProxyDelay', (_e, proxy, url) =>
|
||||
ipcErrorWrapper(mihomoProxyDelay)(proxy, url)
|
||||
)
|
||||
|
||||
@ -26,6 +26,7 @@ export const defaultConfig: IAppConfig = {
|
||||
floatingWindowCompatMode: true,
|
||||
disableHardwareAcceleration: false,
|
||||
disableLoopbackDetector: false,
|
||||
hideConnectionCardWave: false,
|
||||
disableEmbedCA: false,
|
||||
disableSystemCA: false,
|
||||
skipSafePathCheck: false,
|
||||
@ -46,7 +47,8 @@ export const defaultConfig: IAppConfig = {
|
||||
'substore'
|
||||
],
|
||||
siderWidth: 250,
|
||||
sysProxy: { enable: false, mode: 'manual' }
|
||||
sysProxy: { enable: false, mode: 'manual' },
|
||||
triggerMainWindowBehavior: 'show' // 添加默认值
|
||||
}
|
||||
|
||||
export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
|
||||
|
||||
@ -63,7 +63,9 @@ const GeneralConfig: React.FC = () => {
|
||||
envType = [platform === 'win32' ? 'powershell' : 'bash'],
|
||||
autoCheckUpdate,
|
||||
appTheme = 'system',
|
||||
language = 'zh-CN'
|
||||
language = 'zh-CN',
|
||||
triggerMainWindowBehavior = 'show',
|
||||
hideConnectionCardWave = false
|
||||
} = appConfig || {}
|
||||
|
||||
useEffect(() => {
|
||||
@ -398,6 +400,28 @@ const GeneralConfig: React.FC = () => {
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title={t('settings.triggerMainWindowBehavior')} divider>
|
||||
<Tabs
|
||||
size="sm"
|
||||
color="primary"
|
||||
selectedKey={triggerMainWindowBehavior}
|
||||
onSelectionChange={(key) => {
|
||||
patchAppConfig({ triggerMainWindowBehavior: key as 'show' | 'toggle' })
|
||||
}}
|
||||
>
|
||||
<Tab key="show" title={t('settings.triggerMainWindowBehaviorShow')} />
|
||||
<Tab key="toggle" title={t('settings.triggerMainWindowBehaviorToggle')} />
|
||||
</Tabs>
|
||||
</SettingItem>
|
||||
<SettingItem title={t('settings.hideConnectionCardWave')} divider>
|
||||
<Switch
|
||||
size="sm"
|
||||
isSelected={hideConnectionCardWave}
|
||||
onValueChange={async (v) => {
|
||||
await patchAppConfig({ hideConnectionCardWave: v })
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem
|
||||
title={t('settings.disableHardwareAcceleration')}
|
||||
actions={
|
||||
|
||||
@ -36,7 +36,7 @@ interface Props {
|
||||
const ConnCard: React.FC<Props> = (props) => {
|
||||
const { iconOnly } = props
|
||||
const { appConfig } = useAppConfig()
|
||||
const { showTraffic = false, connectionCardStatus = 'col-span-2', disableAnimations = false } = appConfig || {}
|
||||
const { showTraffic = false, connectionCardStatus = 'col-span-2', disableAnimations = false, hideConnectionCardWave = false } = appConfig || {}
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const match = location.pathname.includes('/connections')
|
||||
@ -224,9 +224,11 @@ const ConnCard: React.FC<Props> = (props) => {
|
||||
</h3>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
{!hideConnectionCardWave && (
|
||||
<div className="w-full h-full absolute top-0 left-0 pointer-events-none overflow-hidden rounded-[14px]">
|
||||
<Line data={chartData} options={chartOptions} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<Card
|
||||
|
||||
@ -69,8 +69,12 @@
|
||||
"settings.disableAnimations": "Disable Animation Effects",
|
||||
"settings.showTraffic_windows": "Show Network Speed in Taskbar",
|
||||
"settings.showTraffic_mac": "Show Network Speed in Status Bar",
|
||||
"settings.hideConnectionCardWave": "Connection Card Pure Number Display",
|
||||
"settings.showDockIcon": "Show Dock Icon",
|
||||
"settings.useWindowFrame": "Use System Title Bar",
|
||||
"settings.triggerMainWindowBehavior": "Window Trigger Behavior",
|
||||
"settings.triggerMainWindowBehaviorShow": "Always Show",
|
||||
"settings.triggerMainWindowBehaviorToggle": "Toggle Show/Hide",
|
||||
"settings.disableHardwareAcceleration": "Disable Hardware Acceleration",
|
||||
"settings.disableHardwareAccelerationTooltip": "Disabling hardware acceleration can resolve rendering issues or crashes caused by graphics driver problems, but may reduce performance. Requires app restart to take effect",
|
||||
"settings.hardwareAcceleration.confirm.title": "Confirm App Restart",
|
||||
|
||||
@ -69,8 +69,12 @@
|
||||
"settings.disableAnimations": "禁用动画效果",
|
||||
"settings.showTraffic_windows": "在任务栏显示网速",
|
||||
"settings.showTraffic_mac": "在状态栏显示网速",
|
||||
"settings.hideConnectionCardWave": "连接卡片纯数字显示",
|
||||
"settings.showDockIcon": "显示 Dock 图标",
|
||||
"settings.useWindowFrame": "使用系统标题栏",
|
||||
"settings.triggerMainWindowBehavior": "窗口触发行为",
|
||||
"settings.triggerMainWindowBehaviorShow": "总是显示",
|
||||
"settings.triggerMainWindowBehaviorToggle": "切换显示/隐藏",
|
||||
"settings.disableHardwareAcceleration": "禁用硬件加速",
|
||||
"settings.disableHardwareAccelerationTooltip": "禁用硬件加速可以解决某些显卡驱动问题导致的渲染异常或崩溃,但可能会降低性能。修改后需要重启应用生效",
|
||||
"settings.hardwareAcceleration.confirm.title": "确认重启应用",
|
||||
|
||||
@ -88,6 +88,10 @@ export async function mihomoUpgradeUI(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoUpgradeUI'))
|
||||
}
|
||||
|
||||
export async function mihomoUpgradeConfig(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoUpgradeConfig'))
|
||||
}
|
||||
|
||||
export async function mihomoProxyDelay(proxy: string, url?: string): Promise<IMihomoDelay> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoProxyDelay', proxy, url))
|
||||
}
|
||||
|
||||
2
src/shared/types.d.ts
vendored
2
src/shared/types.d.ts
vendored
@ -242,6 +242,7 @@ interface IAppConfig {
|
||||
connectionCardStatus?: CardStatus
|
||||
dnsCardStatus?: CardStatus
|
||||
logCardStatus?: CardStatus
|
||||
hideConnectionCardWave?: boolean
|
||||
pauseSSID?: string[]
|
||||
mihomoCoreCardStatus?: CardStatus
|
||||
overrideCardStatus?: CardStatus
|
||||
@ -309,6 +310,7 @@ interface IAppConfig {
|
||||
restartAppShortcut?: string
|
||||
quitWithoutCoreShortcut?: string
|
||||
language?: 'zh-CN' | 'en-US' | 'ru-RU' | 'fa-IR'
|
||||
triggerMainWindowBehavior?: 'show' | 'toggle'
|
||||
}
|
||||
|
||||
interface IMihomoTunConfig {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user