Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"rehype-highlight": "^7.0.2",
"remark-gfm": "^4.0.0",
"remark-typescript-code-import": "^1.0.1",
"sass": "^1.83.4",
"ua-parser-js": "^2.0.1"
"sass": "^1.83.4"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.7.0",
Expand All @@ -44,7 +43,6 @@
"@mdx-js/typescript-plugin": "^0.0.8",
"@types/eslint": "^9.6.1",
"@types/eslint-config-prettier": "^6.11.3",
"@types/ua-parser-js": "^0.7.39",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-mdx": "^3.1.5",
Expand Down
31 changes: 16 additions & 15 deletions docs/src/components/platformcontext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import BrowserOnly from "@docusaurus/BrowserOnly";
import { createContext, ReactNode, useCallback, useContext, useState } from "react";
import { UAParser } from "ua-parser-js";

import clsx from "clsx";
import "./platformcontext.css";
Expand All @@ -14,24 +13,26 @@ interface PlatformContextProps {

export const PlatformContext = createContext<PlatformContextProps | undefined>(undefined);

const detectPlatform = (): Platform => {
const savedPlatform = localStorage.getItem("platform") as Platform | null;
if (savedPlatform) {
return savedPlatform;
}
const { os } = UAParser(navigator.userAgent);

if (/Windows/.test(os.name)) {
return "windows";
} else if (/Mac OS|iOS/.test(os.name)) {
return "mac";
function getOS(): Platform {
var platform = window.navigator.platform,
macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"],
windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"],
iosPlatforms = ["iPhone", "iPad", "iPod"],
os: Platform = null;

if (macosPlatforms.indexOf(platform) !== -1 || iosPlatforms.indexOf(platform) !== -1) {
os = "mac";
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = "windows";
} else {
return "linux";
os = "linux";
}
};

return os;
}

const PlatformProviderInternal = ({ children }: { children: ReactNode }) => {
const [platform, setPlatform] = useState<Platform>(detectPlatform());
const [platform, setPlatform] = useState<Platform>(getOS());

const setPlatformCallback = useCallback((newPlatform: Platform) => {
setPlatform(newPlatform);
Expand Down
43 changes: 0 additions & 43 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6603,13 +6603,6 @@ __metadata:
languageName: node
linkType: hard

"@types/ua-parser-js@npm:^0.7.39":
version: 0.7.39
resolution: "@types/ua-parser-js@npm:0.7.39"
checksum: 10c0/fea522f42dfc2854d9c93144a13c3db3bbe1c791458451db06d46bec7e1dbbe945d1542e02bb38378e39a04bdb7810b43e2ead26f9e6c250832e187312522708
languageName: node
linkType: hard

"@types/unist@npm:*, @types/unist@npm:^3.0.0":
version: 3.0.3
resolution: "@types/unist@npm:3.0.3"
Expand Down Expand Up @@ -9973,13 +9966,6 @@ __metadata:
languageName: node
linkType: hard

"detect-europe-js@npm:^0.1.2":
version: 0.1.2
resolution: "detect-europe-js@npm:0.1.2"
checksum: 10c0/46fccf2a9ddeec8ecb7a369be1452f84856cbd0ccdeb3c47e41fe6c9d69f63d6bd75f91b5aa1ae310e56d8fbcbff0e802b1504cdcc3a92f3327c94408e6d07a2
languageName: node
linkType: hard

"detect-libc@npm:^1.0.3":
version: 1.0.3
resolution: "detect-libc@npm:1.0.3"
Expand Down Expand Up @@ -13474,13 +13460,6 @@ __metadata:
languageName: node
linkType: hard

"is-standalone-pwa@npm:^0.1.1":
version: 0.1.1
resolution: "is-standalone-pwa@npm:0.1.1"
checksum: 10c0/af1a11edef4a8f00c24014576285070fb73eebb3583cae790c0a825e338e19f05048a26e5fd5ef10f6056032d6a4520054ff824532c15df784933c0fcc5e13fd
languageName: node
linkType: hard

"is-stream@npm:^2.0.0":
version: 2.0.1
resolution: "is-stream@npm:2.0.1"
Expand Down Expand Up @@ -21211,26 +21190,6 @@ __metadata:
languageName: node
linkType: hard

"ua-is-frozen@npm:^0.1.2":
version: 0.1.2
resolution: "ua-is-frozen@npm:0.1.2"
checksum: 10c0/fb41929bd4924c9676391e6d7197d30580749a96697a83c8b6e77fb137e3ff8492dcd1e6f871f6a9517848651a93af37bfefb25385f16d90e19678ade22d30b7
languageName: node
linkType: hard

"ua-parser-js@npm:^2.0.1":
version: 2.0.1
resolution: "ua-parser-js@npm:2.0.1"
dependencies:
detect-europe-js: "npm:^0.1.2"
is-standalone-pwa: "npm:^0.1.1"
ua-is-frozen: "npm:^0.1.2"
bin:
ua-parser-js: script/cli.js
checksum: 10c0/099d634bfd866ecc8e1c51a5952bf27d286f115f6abe5d6af4a76b4fbda3f75a91b31634f77faee7d44466d8c12b50c66baf42ec7a41f8f8cef218a5895742f7
languageName: node
linkType: hard

"undici-types@npm:~6.19.2, undici-types@npm:~6.19.8":
version: 6.19.8
resolution: "undici-types@npm:6.19.8"
Expand Down Expand Up @@ -22093,7 +22052,6 @@ __metadata:
"@mdx-js/typescript-plugin": "npm:^0.0.8"
"@types/eslint": "npm:^9.6.1"
"@types/eslint-config-prettier": "npm:^6.11.3"
"@types/ua-parser-js": "npm:^0.7.39"
"@waveterm/docusaurus-og": "https://github.com/wavetermdev/docusaurus-og.git"
clsx: "npm:^2.1.1"
docusaurus-plugin-sass: "npm:^0.2.6"
Expand All @@ -22117,7 +22075,6 @@ __metadata:
sass: "npm:^1.83.4"
typescript: "npm:^5.7.3"
typescript-eslint: "npm:^8.22.0"
ua-parser-js: "npm:^2.0.1"
languageName: unknown
linkType: soft

Expand Down
Loading