-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23c1754
commit ab971e8
Showing
14 changed files
with
252 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
### Breaking Changes | ||
|
||
- 此版本修改了应用的显示名称,macOS用户可能无法自动更新,需要手动删除 `/Applications/mihomo-party.app` | ||
|
||
### New Features | ||
|
||
- 允许切换订阅卡片显示过期时间还是更新时间 | ||
- 添加悬浮窗功能,可以在设置中开启 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { is } from '@electron-toolkit/utils' | ||
import { BrowserWindow } from 'electron' | ||
import windowStateKeeper from 'electron-window-state' | ||
import { join } from 'path' | ||
import { getAppConfig } from '../config' | ||
import { applyTheme } from './theme' | ||
import { buildContextMenu } 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: 126, | ||
height: 50, | ||
x: floatingWindowState.x, | ||
y: floatingWindowState.y, | ||
show: false, | ||
frame: false, | ||
alwaysOnTop: true, | ||
resizable: false, | ||
transparent: true, | ||
skipTaskbar: true, | ||
minimizable: false, | ||
maximizable: false, | ||
webPreferences: { | ||
preload: join(__dirname, '../preload/index.js'), | ||
spellcheck: false, | ||
sandbox: false | ||
} | ||
}) | ||
floatingWindowState.manage(floatingWindow) | ||
floatingWindow.on('ready-to-show', () => { | ||
applyTheme(customTheme) | ||
floatingWindow?.show() | ||
}) | ||
floatingWindow.on('moved', () => { | ||
if (floatingWindow) floatingWindowState.saveState(floatingWindow) | ||
}) | ||
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')) | ||
} | ||
} | ||
export function showFloatingWindow(): void { | ||
if (floatingWindow) { | ||
floatingWindow.show() | ||
} else { | ||
createFloatingWindow() | ||
} | ||
} | ||
|
||
export function closeFloatingWindow(): void { | ||
if (floatingWindow) { | ||
floatingWindow.close() | ||
floatingWindow.destroy() | ||
floatingWindow = null | ||
} | ||
} | ||
|
||
export async function showContextMenu(): Promise<void> { | ||
const menu = await buildContextMenu() | ||
menu.popup() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" lang="zh" /> | ||
<title>Mihomo Party</title> | ||
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | ||
<meta | ||
http-equiv="Content-Security-Policy" | ||
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src * data:; frame-src http://127.0.0.1:*;" | ||
/> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/floating.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useEffect, useState } from 'react' | ||
import MihomoIcon from './components/base/mihomo-icon' | ||
import { calcTraffic } from './utils/calc' | ||
import { showContextMenu, showMainWindow } from './utils/ipc' | ||
|
||
const FloatingApp: React.FC = () => { | ||
const [upload, setUpload] = useState(0) | ||
const [download, setDownload] = useState(0) | ||
useEffect(() => { | ||
window.electron.ipcRenderer.on('mihomoTraffic', async (_e, info: IMihomoTrafficInfo) => { | ||
setUpload(info.up) | ||
setDownload(info.down) | ||
}) | ||
return (): void => { | ||
window.electron.ipcRenderer.removeAllListeners('mihomoTraffic') | ||
} | ||
}, []) | ||
return ( | ||
<div className="app-drag p-[4px] h-[100vh]"> | ||
<div className="floating-bg shadow-md flex rounded-[calc(calc(100vh-8px)/2)] bg-content1 h-[calc(100vh-8px)] w-[calc(100vw-8px)]"> | ||
<div className="flex justify-center items-center h-full w-[calc(100vh-8px)]"> | ||
<div | ||
onContextMenu={(e) => { | ||
e.preventDefault() | ||
showContextMenu() | ||
}} | ||
onClick={() => { | ||
showMainWindow() | ||
}} | ||
className="app-nodrag cursor-pointer floating-thumb bg-primary hover:opacity-hover rounded-full h-[calc(100vh-14px)] w-[calc(100vh-14px)]" | ||
> | ||
<MihomoIcon className="floating-icon text-primary-foreground h-full leading-full text-[22px] mx-auto" /> | ||
</div> | ||
</div> | ||
<div className="flex flex-col justify-center w-[calc(100%-42px)]"> | ||
<div className="flex justify-end"> | ||
<div className="floating-text whitespace-nowrap overflow-hidden text-[12px] mr-[10px] font-bold"> | ||
{calcTraffic(upload)}/s | ||
</div> | ||
</div> | ||
<div className="w-full flex justify-end"> | ||
<div className="floating-text whitespace-nowrap overflow-hidden text-[12px] mr-[10px] font-bold"> | ||
{calcTraffic(download)}/s | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default FloatingApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
html { | ||
background-color: transparent !important; | ||
} | ||
|
||
.app-nodrag { | ||
-webkit-app-region: none; | ||
} | ||
|
||
.app-drag { | ||
-webkit-app-region: drag; | ||
} | ||
|
||
* { | ||
user-select: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import { ThemeProvider as NextThemesProvider } from 'next-themes' | ||
import { NextUIProvider } from '@nextui-org/react' | ||
import '@renderer/assets/floating.css' | ||
import FloatingApp from '@renderer/FloatingApp' | ||
import BaseErrorBoundary from './components/base/base-error-boundary' | ||
|
||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<React.StrictMode> | ||
<NextUIProvider> | ||
<NextThemesProvider attribute="class" enableSystem defaultTheme="dark"> | ||
<BaseErrorBoundary> | ||
<FloatingApp /> | ||
</BaseErrorBoundary> | ||
</NextThemesProvider> | ||
</NextUIProvider> | ||
</React.StrictMode> | ||
) |
Oops, something went wrong.