Skip to content

Commit

Permalink
fix: add os platform value
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzgydi committed Jan 14, 2023
1 parent 453c230 commit 1b44ae0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/pages/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import useCustomTheme from "@/components/layout/use-custom-theme";
import getSystem from "@/utils/get-system";
import "dayjs/locale/zh-cn";

declare global {
const WIN_PORTABLE: boolean;
}

dayjs.extend(relativeTime);

const OS = getSystem();
Expand Down
19 changes: 19 additions & 0 deletions src/services/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
type Platform =
| "aix"
| "android"
| "darwin"
| "freebsd"
| "haiku"
| "linux"
| "openbsd"
| "sunos"
| "win32"
| "cygwin"
| "netbsd";

/**
* defines in `vite.config.ts`
*/
declare const WIN_PORTABLE: boolean;
declare const OS_PLATFORM: Platform;

/**
* Some interface for clash api
*/
Expand Down
5 changes: 3 additions & 2 deletions src/utils/get-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// according to UA
export default function getSystem() {
const ua = navigator.userAgent;
const platform = OS_PLATFORM;

if (ua.includes("Mac OS X")) return "macos";
if (ua.includes("Mac OS X") || platform === "darwin") return "macos";

if (/win64|win32/i.test(ua)) return "windows";
if (/win64|win32/i.test(ua) || platform === "win32") return "windows";

if (/linux/i.test(ua)) return "linux";

Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineConfig({
},
},
define: {
OS_PLATFORM: `"${process.platform}"`,
WIN_PORTABLE: !!process.env.VITE_WIN_PORTABLE,
},
});

0 comments on commit 1b44ae0

Please sign in to comment.