mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 03:32:17 +08:00
allow disable tray icon while floating window is open
Some checks are pending
Build / windows (arm64) (push) Waiting to run
Build / windows (ia32) (push) Waiting to run
Build / windows (x64) (push) Waiting to run
Build / windows7 (ia32) (push) Waiting to run
Build / windows7 (x64) (push) Waiting to run
Build / linux (arm64) (push) Waiting to run
Build / linux (x64) (push) Waiting to run
Build / macos (arm64) (push) Waiting to run
Build / macos (x64) (push) Waiting to run
Build / updater (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-bin) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron-bin) (push) Blocked by required conditions
Build / aur-git-updater (push) Waiting to run
Build / Update WinGet Package (push) Blocked by required conditions
Build / Update Homebrew cask (push) Blocked by required conditions
Some checks are pending
Build / windows (arm64) (push) Waiting to run
Build / windows (ia32) (push) Waiting to run
Build / windows (x64) (push) Waiting to run
Build / windows7 (ia32) (push) Waiting to run
Build / windows7 (x64) (push) Waiting to run
Build / linux (arm64) (push) Waiting to run
Build / linux (x64) (push) Waiting to run
Build / macos (arm64) (push) Waiting to run
Build / macos (x64) (push) Waiting to run
Build / updater (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-bin) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron-bin) (push) Blocked by required conditions
Build / aur-git-updater (push) Waiting to run
Build / Update WinGet Package (push) Blocked by required conditions
Build / Update Homebrew cask (push) Blocked by required conditions
This commit is contained in:
parent
1c6853819d
commit
a5d187bd05
|
@ -1,3 +1,7 @@
|
|||
### New Features
|
||||
|
||||
- 允许在开启悬浮窗的情况下禁用托盘图标
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- 修复开启轻量模式后 TrafficMonitor 重复启动的问题
|
||||
|
|
|
@ -150,13 +150,15 @@ app.whenReady().then(async () => {
|
|||
app.on('browser-window-created', (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
const { showFloatingWindow: showFloating = false } = await getAppConfig()
|
||||
const { showFloatingWindow: showFloating = false, disableTray = false } = await getAppConfig()
|
||||
registerIpcMainHandlers()
|
||||
await createWindow()
|
||||
if (showFloating) {
|
||||
showFloatingWindow()
|
||||
}
|
||||
if (!disableTray) {
|
||||
await createTray()
|
||||
}
|
||||
await initShortcut()
|
||||
app.on('activate', function () {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
|
|
|
@ -4,7 +4,7 @@ import windowStateKeeper from 'electron-window-state'
|
|||
import { join } from 'path'
|
||||
import { getAppConfig, patchAppConfig } from '../config'
|
||||
import { applyTheme } from './theme'
|
||||
import { buildContextMenu } from './tray'
|
||||
import { buildContextMenu, showTrayIcon } from './tray'
|
||||
|
||||
export let floatingWindow: BrowserWindow | null = null
|
||||
|
||||
|
@ -55,7 +55,7 @@ async function createFloatingWindow(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
export function showFloatingWindow(): void {
|
||||
export async function showFloatingWindow(): Promise<void> {
|
||||
if (floatingWindow) {
|
||||
floatingWindow.show()
|
||||
} else {
|
||||
|
@ -66,19 +66,21 @@ export function showFloatingWindow(): void {
|
|||
export async function triggerFloatingWindow(): Promise<void> {
|
||||
if (floatingWindow?.isVisible()) {
|
||||
await patchAppConfig({ showFloatingWindow: false })
|
||||
closeFloatingWindow()
|
||||
await closeFloatingWindow()
|
||||
} else {
|
||||
await patchAppConfig({ showFloatingWindow: true })
|
||||
showFloatingWindow()
|
||||
await showFloatingWindow()
|
||||
}
|
||||
}
|
||||
|
||||
export function closeFloatingWindow(): void {
|
||||
export async function closeFloatingWindow(): Promise<void> {
|
||||
if (floatingWindow) {
|
||||
floatingWindow.close()
|
||||
floatingWindow.destroy()
|
||||
floatingWindow = null
|
||||
}
|
||||
await showTrayIcon()
|
||||
await patchAppConfig({ disableTray: false })
|
||||
}
|
||||
|
||||
export async function showContextMenu(): Promise<void> {
|
||||
|
|
|
@ -365,3 +365,16 @@ export async function copyEnv(type: 'bash' | 'cmd' | 'powershell'): Promise<void
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function showTrayIcon(): Promise<void> {
|
||||
if (!tray) {
|
||||
await createTray()
|
||||
}
|
||||
}
|
||||
|
||||
export async function closeTrayIcon(): Promise<void> {
|
||||
if (tray) {
|
||||
tray.destroy()
|
||||
}
|
||||
tray = null
|
||||
}
|
||||
|
|
|
@ -148,7 +148,9 @@ async function migration(): Promise<void> {
|
|||
],
|
||||
appTheme = 'system',
|
||||
envType = [process.platform === 'win32' ? 'powershell' : 'bash'],
|
||||
useSubStore = true
|
||||
useSubStore = true,
|
||||
showFloatingWindow = false,
|
||||
disableTray = false
|
||||
} = await getAppConfig()
|
||||
const {
|
||||
'external-controller-pipe': externalControllerPipe,
|
||||
|
@ -208,6 +210,9 @@ async function migration(): Promise<void> {
|
|||
if (externalController === undefined) {
|
||||
await patchControledMihomoConfig({ 'external-controller': '' })
|
||||
}
|
||||
if (!showFloatingWindow && disableTray) {
|
||||
await patchAppConfig({ disableTray: false })
|
||||
}
|
||||
}
|
||||
|
||||
function initDeeplink(): void {
|
||||
|
|
|
@ -63,7 +63,7 @@ import {
|
|||
import { getRuntimeConfig, getRuntimeConfigStr } from '../core/factory'
|
||||
import { listWebdavBackups, webdavBackup, webdavDelete, webdavRestore } from '../resolve/backup'
|
||||
import { getInterfaces } from '../sys/interface'
|
||||
import { copyEnv } from '../resolve/tray'
|
||||
import { closeTrayIcon, copyEnv, showTrayIcon } from '../resolve/tray'
|
||||
import { registerShortcut } from '../resolve/shortcut'
|
||||
import { closeMainWindow, mainWindow, showMainWindow, triggerMainWindow } from '..'
|
||||
import {
|
||||
|
@ -210,11 +210,13 @@ export function registerIpcMainHandlers(): void {
|
|||
ipcMain.handle('isAlwaysOnTop', () => {
|
||||
return mainWindow?.isAlwaysOnTop()
|
||||
})
|
||||
ipcMain.handle('showTrayIcon', () => ipcErrorWrapper(showTrayIcon)())
|
||||
ipcMain.handle('closeTrayIcon', () => ipcErrorWrapper(closeTrayIcon)())
|
||||
ipcMain.handle('showMainWindow', showMainWindow)
|
||||
ipcMain.handle('closeMainWindow', closeMainWindow)
|
||||
ipcMain.handle('triggerMainWindow', triggerMainWindow)
|
||||
ipcMain.handle('showFloatingWindow', showFloatingWindow)
|
||||
ipcMain.handle('closeFloatingWindow', closeFloatingWindow)
|
||||
ipcMain.handle('showFloatingWindow', () => ipcErrorWrapper(showFloatingWindow)())
|
||||
ipcMain.handle('closeFloatingWindow', () => ipcErrorWrapper(closeFloatingWindow)())
|
||||
ipcMain.handle('showContextMenu', () => ipcErrorWrapper(showContextMenu)())
|
||||
ipcMain.handle('openFile', (_e, type, id, ext) => openFile(type, id, ext))
|
||||
ipcMain.handle('openDevTools', () => {
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
applyTheme,
|
||||
checkAutoRun,
|
||||
closeFloatingWindow,
|
||||
closeTrayIcon,
|
||||
copyEnv,
|
||||
disableAutoRun,
|
||||
enableAutoRun,
|
||||
|
@ -17,6 +18,7 @@ import {
|
|||
relaunchApp,
|
||||
resolveThemes,
|
||||
showFloatingWindow,
|
||||
showTrayIcon,
|
||||
startMonitor,
|
||||
writeTheme
|
||||
} from '@renderer/utils/ipc'
|
||||
|
@ -39,6 +41,7 @@ const GeneralConfig: React.FC = () => {
|
|||
useDockIcon = true,
|
||||
showTraffic = true,
|
||||
proxyInTray = true,
|
||||
disableTray = false,
|
||||
showFloatingWindow: showFloating = false,
|
||||
useWindowFrame = false,
|
||||
autoQuitWithoutCore = false,
|
||||
|
@ -192,6 +195,22 @@ const GeneralConfig: React.FC = () => {
|
|||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
{showFloating && (
|
||||
<SettingItem title="禁用托盘图标" divider>
|
||||
<Switch
|
||||
size="sm"
|
||||
isSelected={disableTray}
|
||||
onValueChange={async (v) => {
|
||||
await patchAppConfig({ disableTray: v })
|
||||
if (v) {
|
||||
closeTrayIcon()
|
||||
} else {
|
||||
showTrayIcon()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
)}
|
||||
{platform !== 'linux' && (
|
||||
<>
|
||||
<SettingItem title="托盘菜单显示节点信息" divider>
|
||||
|
|
|
@ -327,6 +327,14 @@ export async function subStoreCollections(): Promise<ISubStoreSub[]> {
|
|||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('subStoreCollections'))
|
||||
}
|
||||
|
||||
export async function showTrayIcon(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('showTrayIcon'))
|
||||
}
|
||||
|
||||
export async function closeTrayIcon(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('closeTrayIcon'))
|
||||
}
|
||||
|
||||
export async function showMainWindow(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('showMainWindow'))
|
||||
}
|
||||
|
|
1
src/shared/types.d.ts
vendored
1
src/shared/types.d.ts
vendored
|
@ -212,6 +212,7 @@ interface IAppConfig {
|
|||
proxyCols: 'auto' | '1' | '2' | '3' | '4'
|
||||
connectionDirection: 'asc' | 'desc'
|
||||
connectionOrderBy: 'time' | 'upload' | 'download' | 'uploadSpeed' | 'downloadSpeed'
|
||||
disableTray?: boolean
|
||||
showFloatingWindow?: boolean
|
||||
connectionCardStatus?: CardStatus
|
||||
dnsCardStatus?: CardStatus
|
||||
|
|
Loading…
Reference in New Issue
Block a user