diff --git a/src/electron/utils.ts b/src/electron/utils.ts new file mode 100644 index 0000000..b97e765 --- /dev/null +++ b/src/electron/utils.ts @@ -0,0 +1,20 @@ +export const getIsMac = async () => { + // @ts-ignore + const userAgentData = navigator.userAgentData; + if (userAgentData) { + const ua = await userAgentData.getHighEntropyValues(['platform']); + console.log('ua', ua); + if (ua.platform === 'macOS') { + return true; + } + } + return false; +}; +export const getIsElectron = () => { + // 检查 window.process 和 navigator.userAgent 中是否包含 Electron 信息 + return ( + // @ts-ignore + (typeof window !== 'undefined' && typeof window.process !== 'undefined' && window.process.type === 'renderer') || + (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) + ); +}; diff --git a/src/globals.css b/src/globals.css index a7b1696..bb3a730 100644 --- a/src/globals.css +++ b/src/globals.css @@ -56,6 +56,9 @@ @apply bg-gray-900 p-2 text-white flex justify-between h-12; -webkit-app-region: drag; } + .no-drag { + -webkit-app-region: no-drag; + } .bg-custom-blue { background-color: #3490dc; } diff --git a/src/modules/layout/LayoutUser.tsx b/src/modules/layout/LayoutUser.tsx index 350bfbe..b21e28f 100644 --- a/src/modules/layout/LayoutUser.tsx +++ b/src/modules/layout/LayoutUser.tsx @@ -57,14 +57,14 @@ export const LayoutUser = () => { }); }, [store.me]); return ( -
+
{ setOpen(false); }}>
-
+
User: {store.me?.username}
{items.length > 0 && ( diff --git a/src/modules/layout/Menu.tsx b/src/modules/layout/Menu.tsx index 4fafaeb..2ee8feb 100644 --- a/src/modules/layout/Menu.tsx +++ b/src/modules/layout/Menu.tsx @@ -71,14 +71,14 @@ export const LayoutMenu = () => { const { open, setOpen } = useLayoutStore(useShallow((state) => ({ open: state.open, setOpen: state.setOpen }))); const navigate = useNewNavigate(); return ( -
+
{ setOpen(false); }}>
-
+
Envision
diff --git a/src/modules/layout/index.tsx b/src/modules/layout/index.tsx index ff2aa0e..20f9fd3 100644 --- a/src/modules/layout/index.tsx +++ b/src/modules/layout/index.tsx @@ -3,9 +3,9 @@ import { MenuOutlined, SwapOutlined } from '@ant-design/icons'; import { Button, Tooltip } from 'antd'; import { Outlet } from 'react-router-dom'; import { LayoutMenu } from './Menu'; -import { useLayoutStore } from './store'; +import { useLayoutStore, usePlatformStore } from './store'; import { useShallow } from 'zustand/react/shallow'; -import { useEffect } from 'react'; +import { useEffect, useLayoutEffect, useState } from 'react'; import { LayoutUser } from './LayoutUser'; import PandaPNG from '@/assets/panda.png'; import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels'; @@ -28,27 +28,46 @@ export const LayoutMain = (props: LayoutMainProps) => { }; }), ); + const platformStore = usePlatformStore( + useShallow((state) => { + return { + isMac: state.isMac, + mount: state.mount, + isElectron: state.isElectron, + init: state.init, + }; + }), + ); + const { isMac, mount, isElectron } = platformStore; const aiStore = useAiStore( useShallow((state) => { return { open: state.open }; }), ); + useLayoutEffect(() => { + platformStore.init(); + }, []); + useEffect(() => { menuStore.getMe(); }, []); return (
-
+
{props.title} -
+
{menuStore.me?.type === 'org' && (
diff --git a/src/modules/layout/store/index.ts b/src/modules/layout/store/index.ts index fc82606..cdfeffa 100644 --- a/src/modules/layout/store/index.ts +++ b/src/modules/layout/store/index.ts @@ -1,6 +1,47 @@ import { query } from '@/modules/query'; import { message } from 'antd'; import { create } from 'zustand'; +export const getIsMac = async () => { + // @ts-ignore + const userAgentData = navigator.userAgentData; + if (userAgentData) { + const ua = await userAgentData.getHighEntropyValues(['platform']); + if (ua.platform === 'macOS') { + return true; + } + } + return false; +}; +export const getIsElectron = () => { + // 检查 window.process 和 navigator.userAgent 中是否包含 Electron 信息 + return ( + // @ts-ignore + (typeof window !== 'undefined' && typeof window.process !== 'undefined' && window.process.type === 'renderer') || + (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) + ); +}; + +type PlatfromStore = { + isMac: boolean; + setIsMac: (mac: boolean) => void; + mount: boolean; + isElectron: boolean; + init: () => Promise; +}; +export const usePlatformStore = create((set) => { + return { + isMac: false, + mount: false, + isElectron: false, + setIsMac: (mac) => set({ isMac: mac }), + init: async () => { + const mac = await getIsMac(); + // @ts-ignore + const isElectron = getIsElectron() + set({ isMac: isElectron && mac, isElectron: isElectron, mount: true }); + }, + }; +}); type Me = { id?: string; diff --git a/vite.config.ts b/vite.config.ts index dfbc199..c741e4c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,10 +4,23 @@ import tailwindcss from 'tailwindcss'; import autoprefixer from 'autoprefixer'; import path from 'path'; import nesting from 'tailwindcss/nesting'; - +const isDev = process.env.NODE_ENV === 'development'; +const unamiPlugin = { + name: 'html-transform', + transformIndexHtml(html: string) { + return html.replace( + '', + ``, + ); + }, +}; +const plugins = []; +if (!isDev) { + plugins.push(unamiPlugin); +} // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react()], + plugins: [react(), ...plugins], css: { postcss: {