mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
feat: Add dynamic Dock icon visibility for macOS (#594)
Implemented `showDockIcon` and `hideDockIcon` to toggle the Dock icon visibility based on user preferences. Adjusted event handlers to respect the `useDockIcon` configuration setting, enhancing macOS-specific behavior and user experience.
This commit is contained in:
parent
d763e93984
commit
36746074da
@ -6,7 +6,7 @@ import { addProfileItem, getAppConfig, patchAppConfig } from './config'
|
|||||||
import { quitWithoutCore, startCore, stopCore } from './core/manager'
|
import { quitWithoutCore, startCore, stopCore } from './core/manager'
|
||||||
import { triggerSysProxy } from './sys/sysproxy'
|
import { triggerSysProxy } from './sys/sysproxy'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
import { createTray } from './resolve/tray'
|
import { createTray, hideDockIcon, showDockIcon } from './resolve/tray'
|
||||||
import { init } from './utils/init'
|
import { init } from './utils/init'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { initShortcut } from './resolve/shortcut'
|
import { initShortcut } from './resolve/shortcut'
|
||||||
@ -269,10 +269,21 @@ export async function createWindow(): Promise<void> {
|
|||||||
mainWindow?.webContents.reload()
|
mainWindow?.webContents.reload()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mainWindow.on('show', () => {
|
||||||
|
showDockIcon()
|
||||||
|
})
|
||||||
|
|
||||||
mainWindow.on('close', async (event) => {
|
mainWindow.on('close', async (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
mainWindow?.hide()
|
mainWindow?.hide()
|
||||||
const { autoQuitWithoutCore = false, autoQuitWithoutCoreDelay = 60 } = await getAppConfig()
|
const {
|
||||||
|
autoQuitWithoutCore = false,
|
||||||
|
autoQuitWithoutCoreDelay = 60,
|
||||||
|
useDockIcon = true
|
||||||
|
} = await getAppConfig()
|
||||||
|
if (!useDockIcon) {
|
||||||
|
hideDockIcon()
|
||||||
|
}
|
||||||
if (autoQuitWithoutCore) {
|
if (autoQuitWithoutCore) {
|
||||||
if (quitTimeout) {
|
if (quitTimeout) {
|
||||||
clearTimeout(quitTimeout)
|
clearTimeout(quitTimeout)
|
||||||
|
|||||||
@ -309,7 +309,7 @@ export async function createTray(): Promise<void> {
|
|||||||
tray?.setIgnoreDoubleClickEvents(true)
|
tray?.setIgnoreDoubleClickEvents(true)
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
if (!useDockIcon) {
|
if (!useDockIcon) {
|
||||||
app.dock.hide()
|
hideDockIcon()
|
||||||
}
|
}
|
||||||
ipcMain.on('trayIconUpdate', async (_, png: string) => {
|
ipcMain.on('trayIconUpdate', async (_, png: string) => {
|
||||||
const image = nativeImage.createFromDataURL(png).resize({ height: 16 })
|
const image = nativeImage.createFromDataURL(png).resize({ height: 16 })
|
||||||
@ -387,3 +387,15 @@ export async function closeTrayIcon(): Promise<void> {
|
|||||||
}
|
}
|
||||||
tray = null
|
tray = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function showDockIcon(): Promise<void> {
|
||||||
|
if (process.platform === 'darwin' && !app.dock.isVisible()) {
|
||||||
|
await app.dock.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function hideDockIcon(): Promise<void> {
|
||||||
|
if (process.platform === 'darwin' && app.dock.isVisible()) {
|
||||||
|
app.dock.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user