From bd0a959e18c74f4b62e6dfd90828937183389689 Mon Sep 17 00:00:00 2001
From: GyDi <segydi@foxmail.com>
Date: Tue, 22 Mar 2022 01:36:06 +0800
Subject: [PATCH] fix: windows style

---
 src/assets/styles/layout.scss | 10 +++++++---
 src/pages/_layout.tsx         |  9 +++++----
 src/utils/get-system.ts       | 13 +++++++++++++
 3 files changed, 25 insertions(+), 7 deletions(-)
 create mode 100644 src/utils/get-system.ts

diff --git a/src/assets/styles/layout.scss b/src/assets/styles/layout.scss
index 171a78c..3bf456f 100644
--- a/src/assets/styles/layout.scss
+++ b/src/assets/styles/layout.scss
@@ -80,8 +80,12 @@
   }
 }
 
-.windows.layout {
-  .layout__right .the-content {
-    top: 30px;
+.linux,
+.windows,
+.unknown {
+  &.layout {
+    .layout__right .the-content {
+      top: 30px;
+    }
   }
 }
diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx
index d22a41d..d2debc8 100644
--- a/src/pages/_layout.tsx
+++ b/src/pages/_layout.tsx
@@ -16,11 +16,12 @@ import LayoutItem from "../components/layout/layout-item";
 import LayoutControl from "../components/layout/layout-control";
 import LayoutTraffic from "../components/layout/layout-traffic";
 import UpdateButton from "../components/layout/update-button";
+import getSystem from "../utils/get-system";
 import "dayjs/locale/zh-cn";
 
 dayjs.extend(relativeTime);
 
-const isWinOs = /win64|win32/i.test(navigator.userAgent);
+const OS = getSystem();
 
 const Layout = () => {
   const { t } = useTranslation();
@@ -85,11 +86,11 @@ const Layout = () => {
         <Paper
           square
           elevation={0}
-          className={`${isWinOs ? "windows " : ""}layout`}
+          className={`${OS} layout`}
           onPointerDown={onDragging}
           onContextMenu={(e) => {
             // only prevent it on Windows
-            if (isWinOs) e.preventDefault();
+            if (OS === "windows") e.preventDefault();
           }}
           sx={[
             (theme) => ({
@@ -118,7 +119,7 @@ const Layout = () => {
           </div>
 
           <div className="layout__right" data-windrag>
-            {isWinOs && (
+            {OS === "windows" && (
               <div className="the-bar">
                 <LayoutControl />
               </div>
diff --git a/src/utils/get-system.ts b/src/utils/get-system.ts
new file mode 100644
index 0000000..8801617
--- /dev/null
+++ b/src/utils/get-system.ts
@@ -0,0 +1,13 @@
+// get the system os
+// according to UA
+export default function getSystem() {
+  const ua = navigator.userAgent;
+
+  if (ua.includes("Mac OS X")) return "macos";
+
+  if (/win64|win32/i.test(ua)) return "windows";
+
+  if (/linux/i.test(ua)) return "linux";
+
+  return "unknown";
+}
-- 
GitLab