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
294dd75b48
...
6172cadca8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6172cadca8 | ||
|
|
b5ee701530 | ||
|
|
58732ce653 |
71
.github/workflows/build.yml
vendored
71
.github/workflows/build.yml
vendored
@ -67,6 +67,18 @@ jobs:
|
||||
dist/*portable.7z
|
||||
body_path: changelog.md
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Publish Dev Release
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: dev
|
||||
files: |
|
||||
dist/*.sha256
|
||||
dist/*setup.exe
|
||||
dist/*portable.7z
|
||||
body: "Development build from ${{ github.sha }}"
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
windows7:
|
||||
strategy:
|
||||
@ -124,6 +136,18 @@ jobs:
|
||||
dist/*portable.7z
|
||||
body_path: changelog.md
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Publish Dev Release
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: dev
|
||||
files: |
|
||||
dist/*.sha256
|
||||
dist/*setup.exe
|
||||
dist/*portable.7z
|
||||
body: "Development build from ${{ github.sha }}"
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
linux:
|
||||
strategy:
|
||||
@ -174,6 +198,18 @@ jobs:
|
||||
dist/*.rpm
|
||||
body_path: changelog.md
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Publish Dev Release
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: dev
|
||||
files: |
|
||||
dist/*.sha256
|
||||
dist/*.deb
|
||||
dist/*.rpm
|
||||
body: "Development build from ${{ github.sha }}"
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
macos:
|
||||
strategy:
|
||||
@ -247,6 +283,17 @@ jobs:
|
||||
dist/*.pkg
|
||||
body_path: changelog.md
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Publish Dev Release
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: dev
|
||||
files: |
|
||||
dist/*.sha256
|
||||
dist/*.pkg
|
||||
body: "Development build from ${{ github.sha }}"
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
macos10:
|
||||
strategy:
|
||||
@ -322,9 +369,20 @@ jobs:
|
||||
dist/*.pkg
|
||||
body_path: changelog.md
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Publish Dev Release
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: dev
|
||||
files: |
|
||||
dist/*.sha256
|
||||
dist/*.pkg
|
||||
body: "Development build from ${{ github.sha }}"
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
updater:
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
|
||||
needs: [windows, macos, windows7, macos10]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -335,17 +393,28 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: pnpm install
|
||||
- name: Telegram Notification
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
env:
|
||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||
run: pnpm telegram
|
||||
- name: Generate latest.yml
|
||||
run: pnpm updater
|
||||
- name: Publish Release
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: latest.yml
|
||||
body_path: changelog.md
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Publish Dev Release
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: dev
|
||||
files: latest.yml
|
||||
body: "Development build updater from ${{ github.sha }}"
|
||||
prerelease: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
aur-release-updater:
|
||||
strategy:
|
||||
|
||||
@ -458,19 +458,37 @@ export async function checkAdminRestartForTun(): Promise<void> {
|
||||
} catch (error) {
|
||||
console.error('Failed to auto-enable TUN after admin restart:', error)
|
||||
}
|
||||
} else if (process.platform === 'win32') {
|
||||
try {
|
||||
const hasAdminPrivileges = await checkAdminPrivileges()
|
||||
const { tun } = await getControledMihomoConfig()
|
||||
} else {
|
||||
// 检查TUN配置与权限的匹配
|
||||
await validateTunPermissionsOnStartup()
|
||||
}
|
||||
}
|
||||
|
||||
if (hasAdminPrivileges && !tun?.enable) {
|
||||
console.log('Running with admin privileges but TUN is disabled')
|
||||
const { mainWindow } = await import('../index')
|
||||
mainWindow?.webContents.send('adminPrivilegesDetected', { tunEnabled: false })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to check admin privileges on startup:', error)
|
||||
export async function validateTunPermissionsOnStartup(): Promise<void> {
|
||||
try {
|
||||
const { tun } = await getControledMihomoConfig()
|
||||
|
||||
if (!tun?.enable) {
|
||||
return
|
||||
}
|
||||
|
||||
const hasPermissions = await checkMihomoCorePermissions()
|
||||
|
||||
if (!hasPermissions) {
|
||||
console.warn('TUN is enabled but insufficient permissions detected, auto-disabling TUN...')
|
||||
|
||||
await patchControledMihomoConfig({ tun: { enable: false } })
|
||||
|
||||
const { mainWindow } = await import('../index')
|
||||
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||
ipcMain.emit('updateTrayMenu')
|
||||
|
||||
console.log('TUN auto-disabled due to insufficient permissions')
|
||||
} else {
|
||||
console.log('TUN permissions validated successfully')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to validate TUN permissions on startup:', error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -195,7 +195,11 @@ app.whenReady().then(async () => {
|
||||
registerIpcMainHandlers()
|
||||
await createWindow()
|
||||
if (showFloating) {
|
||||
showFloatingWindow()
|
||||
try {
|
||||
await showFloatingWindow()
|
||||
} catch (error) {
|
||||
console.error('Failed to create floating window on startup:', error)
|
||||
}
|
||||
}
|
||||
if (!disableTray) {
|
||||
await createTray()
|
||||
|
||||
@ -9,58 +9,94 @@ import { buildContextMenu, showTrayIcon } from './tray'
|
||||
export let floatingWindow: BrowserWindow | null = null
|
||||
|
||||
async function createFloatingWindow(): Promise<void> {
|
||||
const floatingWindowState = windowStateKeeper({
|
||||
file: 'floating-window-state.json'
|
||||
})
|
||||
const { customTheme = 'default.css' } = await getAppConfig()
|
||||
floatingWindow = new BrowserWindow({
|
||||
width: 120,
|
||||
height: 42,
|
||||
x: floatingWindowState.x,
|
||||
y: floatingWindowState.y,
|
||||
show: false,
|
||||
frame: false,
|
||||
alwaysOnTop: true,
|
||||
resizable: false,
|
||||
transparent: true,
|
||||
skipTaskbar: true,
|
||||
minimizable: false,
|
||||
maximizable: false,
|
||||
fullscreenable: false,
|
||||
closable: false,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
spellcheck: false,
|
||||
sandbox: false
|
||||
try {
|
||||
const floatingWindowState = windowStateKeeper({
|
||||
file: 'floating-window-state.json'
|
||||
})
|
||||
const { customTheme = 'default.css' } = await getAppConfig()
|
||||
|
||||
const windowOptions: Electron.BrowserWindowConstructorOptions = {
|
||||
width: 120,
|
||||
height: 42,
|
||||
x: floatingWindowState.x,
|
||||
y: floatingWindowState.y,
|
||||
show: false,
|
||||
frame: false,
|
||||
alwaysOnTop: true,
|
||||
resizable: false,
|
||||
transparent: true,
|
||||
skipTaskbar: true,
|
||||
minimizable: false,
|
||||
maximizable: false,
|
||||
fullscreenable: false,
|
||||
closable: false,
|
||||
backgroundColor: '#00000000',
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
spellcheck: false,
|
||||
sandbox: false,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true
|
||||
}
|
||||
}
|
||||
})
|
||||
floatingWindowState.manage(floatingWindow)
|
||||
floatingWindow.on('ready-to-show', () => {
|
||||
applyTheme(customTheme)
|
||||
floatingWindow?.show()
|
||||
floatingWindow?.setAlwaysOnTop(true, 'screen-saver')
|
||||
})
|
||||
floatingWindow.on('moved', () => {
|
||||
if (floatingWindow) floatingWindowState.saveState(floatingWindow)
|
||||
})
|
||||
ipcMain.on('updateFloatingWindow', () => {
|
||||
if (floatingWindow) {
|
||||
floatingWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||
floatingWindow?.webContents.send('appConfigUpdated')
|
||||
|
||||
// windows 添加兼容性处理
|
||||
if (process.platform === 'win32') {
|
||||
windowOptions.hasShadow = false
|
||||
windowOptions.webPreferences!.offscreen = false
|
||||
}
|
||||
})
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
floatingWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/floating.html`)
|
||||
} else {
|
||||
floatingWindow.loadFile(join(__dirname, '../renderer/floating.html'))
|
||||
|
||||
floatingWindow = new BrowserWindow(windowOptions)
|
||||
floatingWindowState.manage(floatingWindow)
|
||||
|
||||
floatingWindow.webContents.on('render-process-gone', (_, details) => {
|
||||
console.error('Floating window render process gone:', details.reason)
|
||||
floatingWindow = null
|
||||
})
|
||||
|
||||
floatingWindow.on('ready-to-show', () => {
|
||||
try {
|
||||
applyTheme(customTheme)
|
||||
floatingWindow?.show()
|
||||
floatingWindow?.setAlwaysOnTop(true, 'screen-saver')
|
||||
} catch (error) {
|
||||
console.error('Error in floating window ready-to-show:', error)
|
||||
}
|
||||
})
|
||||
|
||||
floatingWindow.on('moved', () => {
|
||||
if (floatingWindow) floatingWindowState.saveState(floatingWindow)
|
||||
})
|
||||
ipcMain.on('updateFloatingWindow', () => {
|
||||
if (floatingWindow) {
|
||||
floatingWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||
floatingWindow?.webContents.send('appConfigUpdated')
|
||||
}
|
||||
})
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
await floatingWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/floating.html`)
|
||||
} else {
|
||||
await floatingWindow.loadFile(join(__dirname, '../renderer/floating.html'))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to create floating window:', error)
|
||||
floatingWindow = null
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export async function showFloatingWindow(): Promise<void> {
|
||||
if (floatingWindow) {
|
||||
floatingWindow.show()
|
||||
} else {
|
||||
createFloatingWindow()
|
||||
try {
|
||||
if (floatingWindow && !floatingWindow.isDestroyed()) {
|
||||
floatingWindow.show()
|
||||
} else {
|
||||
await createFloatingWindow()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to show floating window:', error)
|
||||
await patchAppConfig({ showFloatingWindow: false })
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user