Skip to content

Commit

Permalink
Merge branch 'pompurin404:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 authored Aug 6, 2024
2 parents c27deec + 36b0142 commit 8c74875
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 56 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ jobs:
with:
version: 9
- name: Install Dependencies
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: |
pnpm install
pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: pnpm build:win --${{ matrix.arch }}
- name: Upload Artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -74,10 +80,16 @@ jobs:
with:
version: 9
- name: Install Dependencies
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: |
pnpm install
pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: pnpm build:linux --${{ matrix.arch }}
- name: Upload Artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -118,10 +130,16 @@ jobs:
with:
version: 9
- name: Install Dependencies
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: |
pnpm install
pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: pnpm build:mac --${{ matrix.arch }}
- name: Upload Artifacts
uses: actions/upload-artifact@v4
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
<a href="https://github.com/pompurin404/mihomo-party/releases">
<img src="https://img.shields.io/github/release/pompurin404/mihomo-party/all.svg">
</a>
<a href="https://t.me/mihomo_party">
<img src="https://img.shields.io/badge/Telegram-group-blue?logo=telegram">
</a>
</p>

<div align="center">
<img src="images/preview.png" alt="Mihomo Party" width="80%">
</div>
2 changes: 1 addition & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ linux:
maintainer: mihomo-party
category: Utility
artifactName: ${name}-linux-${version}-${arch}.${ext}
npmRebuild: false
npmRebuild: true
publish: []
Binary file added images/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mihomo-party",
"version": "0.1.1",
"version": "0.1.3",
"description": "Mihomo Party",
"main": "./out/main/index.js",
"author": "mihomo-party",
Expand Down
10 changes: 4 additions & 6 deletions src/main/resolve/autoRun.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { exec } from 'child_process'
import { exePath } from '../utils/dirs'
import { app } from 'electron'
import fs from 'fs'

// 获取应用的可执行文件路径
const exePath = app.getPath('exe')

const appName = 'mihomo-party'

const taskXml = `
Expand Down Expand Up @@ -45,7 +43,7 @@ const taskXml = `
</Settings>
<Actions Context="Author">
<Exec>
<Command>${exePath}</Command>
<Command>${exePath()}</Command>
</Exec>
</Actions>
</Task>
Expand Down Expand Up @@ -80,14 +78,14 @@ export function enableAutoRun(): void {
if (process.platform === 'darwin') {
app.setLoginItemSettings({
openAtLogin: true,
path: exePath
path: exePath()
})
}
if (process.platform === 'linux') {
let desktop = `
[Desktop Entry]
Name=mihomo-party
Exec=${exePath} %U
Exec=${exePath()} %U
Terminal=false
Type=Application
Icon=mihomo-party
Expand Down
4 changes: 4 additions & 0 deletions src/main/utils/dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import path from 'path'

export const dataDir = app.getPath('userData')

export function exePath(): string {
return app.getPath('exe')
}

export function resourcesDir(): string {
if (is.dev) {
return path.join(__dirname, '../../resources')
Expand Down
36 changes: 35 additions & 1 deletion src/main/utils/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, ipcMain, safeStorage } from 'electron'
import { app, dialog, ipcMain, safeStorage } from 'electron'
import {
mihomoChangeProxy,
mihomoCloseAllConnections,
Expand Down Expand Up @@ -33,6 +33,8 @@ import {
import { isEncryptionAvailable, startCore } from '../core/manager'
import { triggerSysProxy } from '../resolve/sysproxy'
import { checkUpdate } from '../resolve/autoUpdater'
import { exePath, mihomoCorePath } from './dirs'
import { execSync } from 'child_process'

export function registerIpcMainHandlers(): void {
ipcMain.handle('mihomoVersion', mihomoVersion)
Expand Down Expand Up @@ -71,5 +73,37 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('checkUpdate', () => checkUpdate())
ipcMain.handle('getVersion', () => app.getVersion())
ipcMain.handle('platform', () => process.platform)
ipcMain.handle('setupFirewall', setupFirewall)
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()
})
}
42 changes: 14 additions & 28 deletions src/renderer/src/components/base/base-setting-item.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
import { Button, Divider } from '@nextui-org/react'
import { FaChevronRight } from 'react-icons/fa'
import { Divider } from '@nextui-org/react'

import React from 'react'

interface Props {
onPress?: () => void
title: React.ReactNode
actions?: React.ReactNode
children?: React.ReactNode
divider?: boolean
}

const SettingItem: React.FC<Props> = (props) => {
const { title, actions, children, divider = false, onPress } = props
if (onPress) {
return (
<>
<div className="p-0 m-0 h-[32px] w-full flex justify-between">
const { title, actions, children, divider = false } = props

return (
<>
<div className="h-[32px] w-full flex justify-between">
<div className="h-full flex items-center">
<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 (
<>
<div className="h-[32px] w-full flex justify-between">
<div className="h-full flex items-center">
<h4 className="h-full select-none text-md leading-[32px]">{title}</h4>
<div>{actions}</div>
</div>
{children}
<div>{actions}</div>
</div>
{divider && <Divider className="my-2" />}
</>
)
}
{children}
</div>
{divider && <Divider className="my-2" />}
</>
)
}

export default SettingItem
41 changes: 24 additions & 17 deletions src/renderer/src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,30 @@ const Settings: React.FC = () => {
</SettingItem>
</SettingCard>
<SettingCard>
<SettingItem
title="检查更新"
divider
onPress={() => {
checkUpdate().then((v) => {
if (v) {
new window.Notification(`v${v}版本已发布`, { body: '点击前往下载' }).onclick =
(): void => {
open(`https://github.com/pompurin404/mihomo-party/releases/tag/v${v}`)
}
} else {
new window.Notification('当前已是最新版本', { body: '无需更新' })
}
})
}}
/>
<SettingItem title="退出应用" onPress={quitApp} divider />
<SettingItem title="检查更新" divider>
<Button
size="sm"
onPress={() => {
checkUpdate().then((v) => {
if (v) {
new window.Notification(`v${v}版本已发布`, { body: '点击前往下载' }).onclick =
(): void => {
open(`https://github.com/pompurin404/mihomo-party/releases/tag/v${v}`)
}
} else {
new window.Notification('当前已是最新版本', { body: '无需更新' })
}
})
}}
>
检查更新
</Button>
</SettingItem>
<SettingItem title="退出应用" divider>
<Button size="sm" onPress={quitApp}>
退出应用
</Button>
</SettingItem>
<SettingItem title="应用版本">
<div className="select-none">v{version}</div>
</SettingItem>
Expand Down
22 changes: 20 additions & 2 deletions src/renderer/src/pages/tun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import BasePage from '@renderer/components/base/base-page'
import SettingCard from '@renderer/components/base/base-setting-card'
import SettingItem from '@renderer/components/base/base-setting-item'
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 React, { Key, useState } from 'react'

const Tun: React.FC = () => {
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const { tun } = controledMihomoConfig || {}
const [loading, setLoading] = useState(false)
const {
device = 'Mihomo',
stack = 'mixed',
Expand Down Expand Up @@ -134,7 +135,7 @@ const Tun: React.FC = () => {
}}
/>
</SettingItem>
<SettingItem title="DNS 劫持">
<SettingItem title="DNS 劫持" divider>
<Input
size="sm"
className="w-[50%]"
Expand All @@ -144,6 +145,23 @@ const Tun: React.FC = () => {
}}
/>
</SettingItem>
<SettingItem title="重设防火墙">
<Button
size="sm"
color="primary"
isLoading={loading}
onPress={() => {
setLoading(true)
setupFirewall()
.then(() => {
new Notification('防火墙重设成功')
})
.finally(() => setLoading(false))
}}
>
重设防火墙
</Button>
</SettingItem>
</SettingCard>
</BasePage>
)
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/src/utils/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export async function getPlatform(): Promise<NodeJS.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> {
return await window.electron.ipcRenderer.invoke('quitApp')
}

0 comments on commit 8c74875

Please sign in to comment.