mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 03:32:17 +08:00
adjust the open and close window events.
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
37466b2798
commit
da35f34d7b
|
@ -284,6 +284,14 @@ export async function createWindow(): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function triggerMainWindow(): void {
|
||||||
|
if (mainWindow?.isVisible()) {
|
||||||
|
closeMainWindow()
|
||||||
|
} else {
|
||||||
|
showMainWindow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function showMainWindow(): void {
|
export function showMainWindow(): void {
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
if (quitTimeout) {
|
if (quitTimeout) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { is } from '@electron-toolkit/utils'
|
||||||
import { BrowserWindow, ipcMain } from 'electron'
|
import { BrowserWindow, ipcMain } from 'electron'
|
||||||
import windowStateKeeper from 'electron-window-state'
|
import windowStateKeeper from 'electron-window-state'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { getAppConfig } from '../config'
|
import { getAppConfig, patchAppConfig } from '../config'
|
||||||
import { applyTheme } from './theme'
|
import { applyTheme } from './theme'
|
||||||
import { buildContextMenu } from './tray'
|
import { buildContextMenu } from './tray'
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ async function createFloatingWindow(): Promise<void> {
|
||||||
floatingWindow.loadFile(join(__dirname, '../renderer/floating.html'))
|
floatingWindow.loadFile(join(__dirname, '../renderer/floating.html'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showFloatingWindow(): void {
|
export function showFloatingWindow(): void {
|
||||||
if (floatingWindow) {
|
if (floatingWindow) {
|
||||||
floatingWindow.show()
|
floatingWindow.show()
|
||||||
|
@ -61,6 +62,16 @@ export function showFloatingWindow(): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function triggerFloatingWindow(): Promise<void> {
|
||||||
|
if (floatingWindow?.isVisible()) {
|
||||||
|
await patchAppConfig({ showFloatingWindow: false })
|
||||||
|
closeFloatingWindow()
|
||||||
|
} else {
|
||||||
|
await patchAppConfig({ showFloatingWindow: true })
|
||||||
|
showFloatingWindow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function closeFloatingWindow(): void {
|
export function closeFloatingWindow(): void {
|
||||||
if (floatingWindow) {
|
if (floatingWindow) {
|
||||||
floatingWindow.close()
|
floatingWindow.close()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { app, globalShortcut, ipcMain, Notification } from 'electron'
|
import { app, globalShortcut, ipcMain, Notification } from 'electron'
|
||||||
import { mainWindow, showMainWindow } from '..'
|
import { mainWindow, triggerMainWindow } from '..'
|
||||||
import {
|
import {
|
||||||
getAppConfig,
|
getAppConfig,
|
||||||
getControledMihomoConfig,
|
getControledMihomoConfig,
|
||||||
|
@ -9,7 +9,7 @@ import {
|
||||||
import { triggerSysProxy } from '../sys/sysproxy'
|
import { triggerSysProxy } from '../sys/sysproxy'
|
||||||
import { patchMihomoConfig } from '../core/mihomoApi'
|
import { patchMihomoConfig } from '../core/mihomoApi'
|
||||||
import { quitWithoutCore, restartCore } from '../core/manager'
|
import { quitWithoutCore, restartCore } from '../core/manager'
|
||||||
import { closeFloatingWindow, floatingWindow, showFloatingWindow } from './floatingWindow'
|
import { floatingWindow, triggerFloatingWindow } from './floatingWindow'
|
||||||
|
|
||||||
export async function registerShortcut(
|
export async function registerShortcut(
|
||||||
oldShortcut: string,
|
oldShortcut: string,
|
||||||
|
@ -25,22 +25,12 @@ export async function registerShortcut(
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'showWindowShortcut': {
|
case 'showWindowShortcut': {
|
||||||
return globalShortcut.register(newShortcut, () => {
|
return globalShortcut.register(newShortcut, () => {
|
||||||
if (mainWindow?.isVisible()) {
|
triggerMainWindow()
|
||||||
mainWindow?.close()
|
|
||||||
} else {
|
|
||||||
showMainWindow()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case 'showFloatingWindowShortcut': {
|
case 'showFloatingWindowShortcut': {
|
||||||
return globalShortcut.register(newShortcut, async () => {
|
return globalShortcut.register(newShortcut, async () => {
|
||||||
if (floatingWindow) {
|
await triggerFloatingWindow()
|
||||||
await patchAppConfig({ showFloatingWindow: false })
|
|
||||||
closeFloatingWindow()
|
|
||||||
} else {
|
|
||||||
await patchAppConfig({ showFloatingWindow: true })
|
|
||||||
showFloatingWindow()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case 'triggerSysProxyShortcut': {
|
case 'triggerSysProxyShortcut': {
|
||||||
|
|
|
@ -15,12 +15,12 @@ import {
|
||||||
mihomoGroups,
|
mihomoGroups,
|
||||||
patchMihomoConfig
|
patchMihomoConfig
|
||||||
} from '../core/mihomoApi'
|
} from '../core/mihomoApi'
|
||||||
import { closeMainWindow, mainWindow, showMainWindow } from '..'
|
import { mainWindow, showMainWindow, triggerMainWindow } from '..'
|
||||||
import { app, clipboard, ipcMain, Menu, nativeImage, shell, Tray } from 'electron'
|
import { app, clipboard, ipcMain, Menu, nativeImage, shell, Tray } from 'electron'
|
||||||
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
|
import { dataDir, logDir, mihomoCoreDir, mihomoWorkDir } from '../utils/dirs'
|
||||||
import { triggerSysProxy } from '../sys/sysproxy'
|
import { triggerSysProxy } from '../sys/sysproxy'
|
||||||
import { quitWithoutCore, restartCore } from '../core/manager'
|
import { quitWithoutCore, restartCore } from '../core/manager'
|
||||||
import { closeFloatingWindow, floatingWindow, showFloatingWindow } from './floatingWindow'
|
import { floatingWindow, triggerFloatingWindow } from './floatingWindow'
|
||||||
|
|
||||||
export let tray: Tray | null = null
|
export let tray: Tray | null = null
|
||||||
|
|
||||||
|
@ -98,13 +98,7 @@ export const buildContextMenu = async (): Promise<Menu> => {
|
||||||
label: floatingWindow?.isVisible() ? '关闭悬浮窗' : '显示悬浮窗',
|
label: floatingWindow?.isVisible() ? '关闭悬浮窗' : '显示悬浮窗',
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
click: async (): Promise<void> => {
|
click: async (): Promise<void> => {
|
||||||
if (floatingWindow) {
|
await triggerFloatingWindow()
|
||||||
await patchAppConfig({ showFloatingWindow: false })
|
|
||||||
closeFloatingWindow()
|
|
||||||
} else {
|
|
||||||
await patchAppConfig({ showFloatingWindow: true })
|
|
||||||
showFloatingWindow()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -314,11 +308,7 @@ export async function createTray(): Promise<void> {
|
||||||
tray?.setImage(image)
|
tray?.setImage(image)
|
||||||
})
|
})
|
||||||
tray?.addListener('right-click', async () => {
|
tray?.addListener('right-click', async () => {
|
||||||
if (mainWindow?.isVisible()) {
|
triggerMainWindow()
|
||||||
closeMainWindow()
|
|
||||||
} else {
|
|
||||||
showMainWindow()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
tray?.addListener('click', async () => {
|
tray?.addListener('click', async () => {
|
||||||
await updateTrayMenu()
|
await updateTrayMenu()
|
||||||
|
@ -326,11 +316,7 @@ export async function createTray(): Promise<void> {
|
||||||
}
|
}
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
tray?.addListener('click', () => {
|
tray?.addListener('click', () => {
|
||||||
if (mainWindow?.isVisible()) {
|
triggerMainWindow()
|
||||||
closeMainWindow()
|
|
||||||
} else {
|
|
||||||
showMainWindow()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
tray?.addListener('right-click', async () => {
|
tray?.addListener('right-click', async () => {
|
||||||
await updateTrayMenu()
|
await updateTrayMenu()
|
||||||
|
@ -338,11 +324,7 @@ export async function createTray(): Promise<void> {
|
||||||
}
|
}
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
tray?.addListener('click', () => {
|
tray?.addListener('click', () => {
|
||||||
if (mainWindow?.isVisible()) {
|
triggerMainWindow()
|
||||||
closeMainWindow()
|
|
||||||
} else {
|
|
||||||
showMainWindow()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
ipcMain.on('updateTrayMenu', async () => {
|
ipcMain.on('updateTrayMenu', async () => {
|
||||||
await updateTrayMenu()
|
await updateTrayMenu()
|
||||||
|
|
|
@ -65,7 +65,7 @@ import { listWebdavBackups, webdavBackup, webdavDelete, webdavRestore } from '..
|
||||||
import { getInterfaces } from '../sys/interface'
|
import { getInterfaces } from '../sys/interface'
|
||||||
import { copyEnv } from '../resolve/tray'
|
import { copyEnv } from '../resolve/tray'
|
||||||
import { registerShortcut } from '../resolve/shortcut'
|
import { registerShortcut } from '../resolve/shortcut'
|
||||||
import { closeMainWindow, mainWindow, showMainWindow } from '..'
|
import { closeMainWindow, mainWindow, showMainWindow, triggerMainWindow } from '..'
|
||||||
import {
|
import {
|
||||||
applyTheme,
|
applyTheme,
|
||||||
fetchThemes,
|
fetchThemes,
|
||||||
|
@ -212,6 +212,7 @@ export function registerIpcMainHandlers(): void {
|
||||||
})
|
})
|
||||||
ipcMain.handle('showMainWindow', showMainWindow)
|
ipcMain.handle('showMainWindow', showMainWindow)
|
||||||
ipcMain.handle('closeMainWindow', closeMainWindow)
|
ipcMain.handle('closeMainWindow', closeMainWindow)
|
||||||
|
ipcMain.handle('triggerMainWindow', triggerMainWindow)
|
||||||
ipcMain.handle('showFloatingWindow', showFloatingWindow)
|
ipcMain.handle('showFloatingWindow', showFloatingWindow)
|
||||||
ipcMain.handle('closeFloatingWindow', closeFloatingWindow)
|
ipcMain.handle('closeFloatingWindow', closeFloatingWindow)
|
||||||
ipcMain.handle('showContextMenu', () => ipcErrorWrapper(showContextMenu)())
|
ipcMain.handle('showContextMenu', () => ipcErrorWrapper(showContextMenu)())
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import MihomoIcon from './components/base/mihomo-icon'
|
import MihomoIcon from './components/base/mihomo-icon'
|
||||||
import { calcTraffic } from './utils/calc'
|
import { calcTraffic } from './utils/calc'
|
||||||
import { showContextMenu, showMainWindow } from './utils/ipc'
|
import { showContextMenu, triggerMainWindow } from './utils/ipc'
|
||||||
import { useAppConfig } from './hooks/use-app-config'
|
import { useAppConfig } from './hooks/use-app-config'
|
||||||
import { useControledMihomoConfig } from './hooks/use-controled-mihomo-config'
|
import { useControledMihomoConfig } from './hooks/use-controled-mihomo-config'
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ const FloatingApp: React.FC = () => {
|
||||||
showContextMenu()
|
showContextMenu()
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
showMainWindow()
|
triggerMainWindow()
|
||||||
}}
|
}}
|
||||||
className={`app-nodrag cursor-pointer floating-thumb ${tunEnabled ? 'bg-secondary' : sysProxyEnabled ? 'bg-primary' : 'bg-default'} hover:opacity-hover rounded-full h-[calc(100vh-14px)] w-[calc(100vh-14px)]`}
|
className={`app-nodrag cursor-pointer floating-thumb ${tunEnabled ? 'bg-secondary' : sysProxyEnabled ? 'bg-primary' : 'bg-default'} hover:opacity-hover rounded-full h-[calc(100vh-14px)] w-[calc(100vh-14px)]`}
|
||||||
>
|
>
|
||||||
|
|
|
@ -335,6 +335,10 @@ export async function closeMainWindow(): Promise<void> {
|
||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('closeMainWindow'))
|
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('closeMainWindow'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function triggerMainWindow(): Promise<void> {
|
||||||
|
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('triggerMainWindow'))
|
||||||
|
}
|
||||||
|
|
||||||
export async function showFloatingWindow(): Promise<void> {
|
export async function showFloatingWindow(): Promise<void> {
|
||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('showFloatingWindow'))
|
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('showFloatingWindow'))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user