mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
adjust styles
This commit is contained in:
parent
2130cacdb6
commit
85db2d6510
@ -2,9 +2,7 @@ import {
|
|||||||
appConfigPath,
|
appConfigPath,
|
||||||
controledMihomoConfigPath,
|
controledMihomoConfigPath,
|
||||||
dataDir,
|
dataDir,
|
||||||
exePath,
|
|
||||||
logDir,
|
logDir,
|
||||||
mihomoCorePath,
|
|
||||||
mihomoTestDir,
|
mihomoTestDir,
|
||||||
mihomoWorkDir,
|
mihomoWorkDir,
|
||||||
profileConfigPath,
|
profileConfigPath,
|
||||||
@ -25,7 +23,6 @@ import { startPacServer } from './server'
|
|||||||
import { triggerSysProxy } from './sysproxy'
|
import { triggerSysProxy } from './sysproxy'
|
||||||
import { getAppConfig } from '../config'
|
import { getAppConfig } from '../config'
|
||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import { execSync } from 'child_process'
|
|
||||||
|
|
||||||
function initDirs(): void {
|
function initDirs(): void {
|
||||||
if (!fs.existsSync(dataDir)) {
|
if (!fs.existsSync(dataDir)) {
|
||||||
@ -85,38 +82,11 @@ function initDeeplink(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initFirewall(): void {
|
|
||||||
const removeCommand = `
|
|
||||||
Remove-NetFirewallRule -DisplayName "mihomo" -ErrorAction SilentlyContinue
|
|
||||||
Remove-NetFirewallRule -DisplayName "mihomo-alpha" -ErrorAction SilentlyContinue
|
|
||||||
Remove-NetFirewallRule -DisplayName "Mihomo Party" -ErrorAction SilentlyContinue
|
|
||||||
`
|
|
||||||
const createCommand = `
|
|
||||||
New-NetFirewallRule -DisplayName "mihomo" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
|
||||||
New-NetFirewallRule -DisplayName "mihomo-alpha" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo-alpha')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
|
||||||
New-NetFirewallRule -DisplayName "Mihomo Party" -Direction Inbound -Action Allow -Program "${exePath()}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
|
||||||
`
|
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
try {
|
|
||||||
execSync(removeCommand, { shell: 'powershell' })
|
|
||||||
} catch {
|
|
||||||
console.log('Remove-NetFirewallRule Failed')
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
execSync(createCommand, { shell: 'powershell' })
|
|
||||||
} catch {
|
|
||||||
console.log('New-NetFirewallRule Failed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function init(): void {
|
export function init(): void {
|
||||||
initDirs()
|
initDirs()
|
||||||
initConfig()
|
initConfig()
|
||||||
initFiles()
|
initFiles()
|
||||||
initDeeplink()
|
initDeeplink()
|
||||||
initFirewall()
|
|
||||||
startPacServer().then(() => {
|
startPacServer().then(() => {
|
||||||
triggerSysProxy(getAppConfig().sysProxy.enable)
|
triggerSysProxy(getAppConfig().sysProxy.enable)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { app, ipcMain, safeStorage } from 'electron'
|
import { app, dialog, ipcMain, safeStorage } from 'electron'
|
||||||
import {
|
import {
|
||||||
mihomoChangeProxy,
|
mihomoChangeProxy,
|
||||||
mihomoCloseAllConnections,
|
mihomoCloseAllConnections,
|
||||||
@ -33,6 +33,8 @@ import {
|
|||||||
import { isEncryptionAvailable, startCore } from '../core/manager'
|
import { isEncryptionAvailable, startCore } from '../core/manager'
|
||||||
import { triggerSysProxy } from '../resolve/sysproxy'
|
import { triggerSysProxy } from '../resolve/sysproxy'
|
||||||
import { checkUpdate } from '../resolve/autoUpdater'
|
import { checkUpdate } from '../resolve/autoUpdater'
|
||||||
|
import { exePath, mihomoCorePath } from './dirs'
|
||||||
|
import { execSync } from 'child_process'
|
||||||
|
|
||||||
export function registerIpcMainHandlers(): void {
|
export function registerIpcMainHandlers(): void {
|
||||||
ipcMain.handle('mihomoVersion', mihomoVersion)
|
ipcMain.handle('mihomoVersion', mihomoVersion)
|
||||||
@ -71,5 +73,37 @@ export function registerIpcMainHandlers(): void {
|
|||||||
ipcMain.handle('checkUpdate', () => checkUpdate())
|
ipcMain.handle('checkUpdate', () => checkUpdate())
|
||||||
ipcMain.handle('getVersion', () => app.getVersion())
|
ipcMain.handle('getVersion', () => app.getVersion())
|
||||||
ipcMain.handle('platform', () => process.platform)
|
ipcMain.handle('platform', () => process.platform)
|
||||||
|
ipcMain.handle('setupFirewall', setupFirewall)
|
||||||
ipcMain.handle('quitApp', () => app.quit())
|
ipcMain.handle('quitApp', () => app.quit())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function setupFirewall(): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const removeCommand = `
|
||||||
|
Remove-NetFirewallRule -DisplayName "mihomo" -ErrorAction SilentlyContinue
|
||||||
|
Remove-NetFirewallRule -DisplayName "mihomo-alpha" -ErrorAction SilentlyContinue
|
||||||
|
Remove-NetFirewallRule -DisplayName "Mihomo Party" -ErrorAction SilentlyContinue
|
||||||
|
`
|
||||||
|
const createCommand = `
|
||||||
|
New-NetFirewallRule -DisplayName "mihomo" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
||||||
|
New-NetFirewallRule -DisplayName "mihomo-alpha" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo-alpha')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
||||||
|
New-NetFirewallRule -DisplayName "Mihomo Party" -Direction Inbound -Action Allow -Program "${exePath()}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
||||||
|
`
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
try {
|
||||||
|
execSync(removeCommand, { shell: 'powershell' })
|
||||||
|
} catch {
|
||||||
|
console.log('Remove-NetFirewallRule Failed')
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
execSync(createCommand, { shell: 'powershell' })
|
||||||
|
} catch (e) {
|
||||||
|
dialog.showErrorBox('防火墙设置失败', `${e}`)
|
||||||
|
reject(e)
|
||||||
|
console.log('New-NetFirewallRule Failed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
import { Button, Divider } from '@nextui-org/react'
|
import { Divider } from '@nextui-org/react'
|
||||||
import { FaChevronRight } from 'react-icons/fa'
|
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onPress?: () => void
|
|
||||||
title: React.ReactNode
|
title: React.ReactNode
|
||||||
actions?: React.ReactNode
|
actions?: React.ReactNode
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
@ -11,20 +10,8 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SettingItem: React.FC<Props> = (props) => {
|
const SettingItem: React.FC<Props> = (props) => {
|
||||||
const { title, actions, children, divider = false, onPress } = props
|
const { title, actions, children, divider = false } = props
|
||||||
if (onPress) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="p-0 m-0 h-[32px] w-full flex justify-between">
|
|
||||||
<h4 className="h-full select-none text-md leading-[32px]">{title}</h4>
|
|
||||||
<Button size="sm" onPress={onPress}>
|
|
||||||
<FaChevronRight />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{divider && <Divider className="my-2" />}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="h-[32px] w-full flex justify-between">
|
<div className="h-[32px] w-full flex justify-between">
|
||||||
@ -38,6 +25,5 @@ const SettingItem: React.FC<Props> = (props) => {
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export default SettingItem
|
export default SettingItem
|
||||||
|
|||||||
@ -98,9 +98,9 @@ const Settings: React.FC = () => {
|
|||||||
</SettingItem>
|
</SettingItem>
|
||||||
</SettingCard>
|
</SettingCard>
|
||||||
<SettingCard>
|
<SettingCard>
|
||||||
<SettingItem
|
<SettingItem title="检查更新" divider>
|
||||||
title="检查更新"
|
<Button
|
||||||
divider
|
size="sm"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
checkUpdate().then((v) => {
|
checkUpdate().then((v) => {
|
||||||
if (v) {
|
if (v) {
|
||||||
@ -113,8 +113,15 @@ const Settings: React.FC = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
<SettingItem title="退出应用" onPress={quitApp} divider />
|
检查更新
|
||||||
|
</Button>
|
||||||
|
</SettingItem>
|
||||||
|
<SettingItem title="退出应用" divider>
|
||||||
|
<Button size="sm" onPress={quitApp}>
|
||||||
|
退出应用
|
||||||
|
</Button>
|
||||||
|
</SettingItem>
|
||||||
<SettingItem title="应用版本">
|
<SettingItem title="应用版本">
|
||||||
<div className="select-none">v{version}</div>
|
<div className="select-none">v{version}</div>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|||||||
@ -3,13 +3,14 @@ import BasePage from '@renderer/components/base/base-page'
|
|||||||
import SettingCard from '@renderer/components/base/base-setting-card'
|
import SettingCard from '@renderer/components/base/base-setting-card'
|
||||||
import SettingItem from '@renderer/components/base/base-setting-item'
|
import SettingItem from '@renderer/components/base/base-setting-item'
|
||||||
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
|
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
|
||||||
import { restartCore } from '@renderer/utils/ipc'
|
import { restartCore, setupFirewall } from '@renderer/utils/ipc'
|
||||||
import { platform } from '@renderer/utils/init'
|
import { platform } from '@renderer/utils/init'
|
||||||
import React, { Key, useState } from 'react'
|
import React, { Key, useState } from 'react'
|
||||||
|
|
||||||
const Tun: React.FC = () => {
|
const Tun: React.FC = () => {
|
||||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
||||||
const { tun } = controledMihomoConfig || {}
|
const { tun } = controledMihomoConfig || {}
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
const {
|
const {
|
||||||
device = 'Mihomo',
|
device = 'Mihomo',
|
||||||
stack = 'mixed',
|
stack = 'mixed',
|
||||||
@ -134,7 +135,7 @@ const Tun: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
<SettingItem title="DNS 劫持">
|
<SettingItem title="DNS 劫持" divider>
|
||||||
<Input
|
<Input
|
||||||
size="sm"
|
size="sm"
|
||||||
className="w-[50%]"
|
className="w-[50%]"
|
||||||
@ -144,6 +145,19 @@ const Tun: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
<SettingItem title="重设防火墙">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
isLoading={loading}
|
||||||
|
onPress={() => {
|
||||||
|
setLoading(true)
|
||||||
|
setupFirewall().finally(() => setLoading(false))
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重设防火墙
|
||||||
|
</Button>
|
||||||
|
</SettingItem>
|
||||||
</SettingCard>
|
</SettingCard>
|
||||||
</BasePage>
|
</BasePage>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -143,6 +143,10 @@ export async function getPlatform(): Promise<NodeJS.Platform> {
|
|||||||
return await window.electron.ipcRenderer.invoke('platform')
|
return await window.electron.ipcRenderer.invoke('platform')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function setupFirewall(): Promise<void> {
|
||||||
|
return await window.electron.ipcRenderer.invoke('setupFirewall')
|
||||||
|
}
|
||||||
|
|
||||||
export async function quitApp(): Promise<void> {
|
export async function quitApp(): Promise<void> {
|
||||||
return await window.electron.ipcRenderer.invoke('quitApp')
|
return await window.electron.ipcRenderer.invoke('quitApp')
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user