From c5d6dc56bcf2ff1aabeb1ab21ff681ffabc341c2 Mon Sep 17 00:00:00 2001 From: Sloaix Date: Thu, 10 Aug 2023 22:53:30 +0800 Subject: [PATCH] refactor: adapting AppBar for macOS --- electron/main/handler.ts | 7 +++++++ src/layouts/MainLayout/AppBar.tsx | 25 ++++++++++++++++++++++++- src/pages/TorrentGenerator.tsx | 1 + src/utils/common/index.ts | 8 ++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/electron/main/handler.ts b/electron/main/handler.ts index 94b57c6..f5f2e85 100644 --- a/electron/main/handler.ts +++ b/electron/main/handler.ts @@ -216,6 +216,13 @@ ipcMain.handle('get-desktop-path', async () => { return app.getPath('desktop') }) +/** + * 返回系统平台 + * @returns 'darwin' | 'linux'| 'win32' + */ +ipcMain.handle('get-platform', async () => { + return process.platform +}) /** * 返回Locale */ diff --git a/src/layouts/MainLayout/AppBar.tsx b/src/layouts/MainLayout/AppBar.tsx index addaa4a..dfc7d94 100644 --- a/src/layouts/MainLayout/AppBar.tsx +++ b/src/layouts/MainLayout/AppBar.tsx @@ -1,15 +1,38 @@ +import { getPlatform } from '@/utils/common' import classNames from 'classnames' +import { useEffect } from 'react' +import { create } from 'zustand' import { name } from '../../../package.json' +type Store = { + platform?: string + setPlatform: (platform: string) => void +} + +const useStore = create()((set) => ({ + setPlatform: (platform) => set({ platform }) +})) + export default ({ className }: { className?: string }) => { + const [platform, setPlatform] = useStore((state) => [state.platform, state.setPlatform]) + const isWindows = platform === 'win32' + const isMac = platform === 'darwin' + + useEffect(() => { + ;(async () => { + setPlatform(await getPlatform()) + })() + }, []) return (
+ {/* logo */}
diff --git a/src/pages/TorrentGenerator.tsx b/src/pages/TorrentGenerator.tsx index b240a23..9ab4cb6 100644 --- a/src/pages/TorrentGenerator.tsx +++ b/src/pages/TorrentGenerator.tsx @@ -310,6 +310,7 @@ export default () => { /> + {/* TODO 忽略隐藏文件 */} {/* TODO 分块对齐 */} {/* diff --git a/src/utils/common/index.ts b/src/utils/common/index.ts index cdac9aa..c77b7a5 100644 --- a/src/utils/common/index.ts +++ b/src/utils/common/index.ts @@ -1,4 +1,7 @@ // 为函数设置最短执行时间,例如: 为函数设置最短执行时间为 1000ms,如果函数执行了300ms,那么会等待700ms后再返回结果 + +import { ipcRenderer } from 'electron' + // 这样的目的是为了防止函数执行时间过短,导致加载动画一闪而过,给用户造成不好的体验 export function setMinExecuteTime(fn: Promise | Function, minTime: number = 1000): Promise { return new Promise(async (resolve) => { @@ -25,3 +28,8 @@ export function sleep(time: number): Promise { }, time) }) } + +// 获取当前系统平台 +export function getPlatform(): Promise { + return ipcRenderer.invoke('get-platform') +}