temp: 适配mac桌面
This commit is contained in:
@@ -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<void>;
|
||||
};
|
||||
export const usePlatformStore = create<PlatfromStore>((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;
|
||||
|
||||
Reference in New Issue
Block a user