Compare commits

..

No commits in common. "6172cadca8244efbf3f476897a2393dc063e7441" and "294dd75b4886c475ec097cd771ca0cb8909d24ac" have entirely different histories.

4 changed files with 59 additions and 186 deletions

View File

@ -67,18 +67,6 @@ jobs:
dist/*portable.7z dist/*portable.7z
body_path: changelog.md body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }} 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: windows7:
strategy: strategy:
@ -136,18 +124,6 @@ jobs:
dist/*portable.7z dist/*portable.7z
body_path: changelog.md body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }} 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: linux:
strategy: strategy:
@ -198,18 +174,6 @@ jobs:
dist/*.rpm dist/*.rpm
body_path: changelog.md body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }} 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: macos:
strategy: strategy:
@ -283,17 +247,6 @@ jobs:
dist/*.pkg dist/*.pkg
body_path: changelog.md body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }} 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: macos10:
strategy: strategy:
@ -369,20 +322,9 @@ jobs:
dist/*.pkg dist/*.pkg
body_path: changelog.md body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }} 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: updater:
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' if: startsWith(github.ref, 'refs/tags/v')
needs: [windows, macos, windows7, macos10] needs: [windows, macos, windows7, macos10]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -393,28 +335,17 @@ jobs:
- name: Install Dependencies - name: Install Dependencies
run: pnpm install run: pnpm install
- name: Telegram Notification - name: Telegram Notification
if: startsWith(github.ref, 'refs/tags/v')
env: env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
run: pnpm telegram run: pnpm telegram
- name: Generate latest.yml - name: Generate latest.yml
run: pnpm updater run: pnpm updater
- name: Publish Release - name: Publish Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:
files: latest.yml files: latest.yml
body_path: changelog.md body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }} 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: aur-release-updater:
strategy: strategy:

View File

@ -458,37 +458,19 @@ export async function checkAdminRestartForTun(): Promise<void> {
} catch (error) { } catch (error) {
console.error('Failed to auto-enable TUN after admin restart:', error) console.error('Failed to auto-enable TUN after admin restart:', error)
} }
} else { } else if (process.platform === 'win32') {
// 检查TUN配置与权限的匹配 try {
await validateTunPermissionsOnStartup() const hasAdminPrivileges = await checkAdminPrivileges()
} const { tun } = await getControledMihomoConfig()
}
export async function validateTunPermissionsOnStartup(): Promise<void> { if (hasAdminPrivileges && !tun?.enable) {
try { console.log('Running with admin privileges but TUN is disabled')
const { tun } = await getControledMihomoConfig() const { mainWindow } = await import('../index')
mainWindow?.webContents.send('adminPrivilegesDetected', { tunEnabled: false })
if (!tun?.enable) { }
return } catch (error) {
console.error('Failed to check admin privileges on startup:', error)
} }
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)
} }
} }

View File

@ -195,11 +195,7 @@ app.whenReady().then(async () => {
registerIpcMainHandlers() registerIpcMainHandlers()
await createWindow() await createWindow()
if (showFloating) { if (showFloating) {
try { showFloatingWindow()
await showFloatingWindow()
} catch (error) {
console.error('Failed to create floating window on startup:', error)
}
} }
if (!disableTray) { if (!disableTray) {
await createTray() await createTray()

View File

@ -9,94 +9,58 @@ import { buildContextMenu, showTrayIcon } from './tray'
export let floatingWindow: BrowserWindow | null = null export let floatingWindow: BrowserWindow | null = null
async function createFloatingWindow(): Promise<void> { async function createFloatingWindow(): Promise<void> {
try { const floatingWindowState = windowStateKeeper({
const floatingWindowState = windowStateKeeper({ file: 'floating-window-state.json'
file: 'floating-window-state.json' })
}) const { customTheme = 'default.css' } = await getAppConfig()
const { customTheme = 'default.css' } = await getAppConfig() floatingWindow = new BrowserWindow({
width: 120,
const windowOptions: Electron.BrowserWindowConstructorOptions = { height: 42,
width: 120, x: floatingWindowState.x,
height: 42, y: floatingWindowState.y,
x: floatingWindowState.x, show: false,
y: floatingWindowState.y, frame: false,
show: false, alwaysOnTop: true,
frame: false, resizable: false,
alwaysOnTop: true, transparent: true,
resizable: false, skipTaskbar: true,
transparent: true, minimizable: false,
skipTaskbar: true, maximizable: false,
minimizable: false, fullscreenable: false,
maximizable: false, closable: false,
fullscreenable: false, webPreferences: {
closable: false, preload: join(__dirname, '../preload/index.js'),
backgroundColor: '#00000000', spellcheck: false,
webPreferences: { sandbox: false
preload: join(__dirname, '../preload/index.js'),
spellcheck: false,
sandbox: false,
nodeIntegration: false,
contextIsolation: true
}
} }
})
// windows 添加兼容性处理 floatingWindowState.manage(floatingWindow)
if (process.platform === 'win32') { floatingWindow.on('ready-to-show', () => {
windowOptions.hasShadow = false applyTheme(customTheme)
windowOptions.webPreferences!.offscreen = false 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')
} }
})
floatingWindow = new BrowserWindow(windowOptions) if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
floatingWindowState.manage(floatingWindow) floatingWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/floating.html`)
} else {
floatingWindow.webContents.on('render-process-gone', (_, details) => { floatingWindow.loadFile(join(__dirname, '../renderer/floating.html'))
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> { export async function showFloatingWindow(): Promise<void> {
try { if (floatingWindow) {
if (floatingWindow && !floatingWindow.isDestroyed()) { floatingWindow.show()
floatingWindow.show() } else {
} else { createFloatingWindow()
await createFloatingWindow()
}
} catch (error) {
console.error('Failed to show floating window:', error)
await patchAppConfig({ showFloatingWindow: false })
throw error
} }
} }