-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export enum OperatingSystem { | ||
Windows = "Windows", | ||
MacOS = "MacOS", | ||
UNIX = "UNIX", | ||
Linux = "Linux", | ||
Unknown = "Unknown", | ||
} | ||
|
||
export type OS = keyof typeof OperatingSystem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { OS } from "@celeris/constants"; | ||
import { OperatingSystem } from "@celeris/constants"; | ||
|
||
/** | ||
* Retrieves the operating system (OS) of the current environment based on the user agent. | ||
* 基于用户代理检索当前环境的操作系统(OS)。 | ||
* | ||
* @returns {OS} The operating system of the current environment. | ||
* 当前环境的操作系统。 | ||
*/ | ||
export function detectOperatingSystem(): OS { | ||
const { userAgent } = navigator; | ||
if (userAgent.includes("Win")) { | ||
return OperatingSystem.Windows; | ||
} | ||
if (userAgent.includes("Mac")) { | ||
return OperatingSystem.MacOS; | ||
} | ||
if (userAgent.includes("X11")) { | ||
return OperatingSystem.UNIX; | ||
} | ||
if (userAgent.includes("Linux")) { | ||
return OperatingSystem.Linux; | ||
} | ||
|
||
return OperatingSystem.Unknown; | ||
} | ||
|
||
/** | ||
* Checks if the current environment is Windows. | ||
* 检查当前环境是否为 Windows。 | ||
* | ||
* @returns {boolean} Returns true if the current environment is Windows, otherwise returns false. | ||
* 如果当前环境为 Windows,则返回 true;否则返回 false。 | ||
*/ | ||
export function isWindows(): boolean { | ||
return detectOperatingSystem() === OperatingSystem.Windows; | ||
} | ||
|
||
/** | ||
* Checks if the current environment is MacOS. | ||
* 检查当前环境是否为 MacOS。 | ||
* | ||
* @returns {boolean} Returns true if the current environment is MacOS, otherwise returns false. | ||
* 如果当前环境为 MacOS,则返回 true;否则返回 false。 | ||
*/ | ||
export function isMacOS(): boolean { | ||
return detectOperatingSystem() === OperatingSystem.MacOS; | ||
} | ||
|
||
/** | ||
* Checks if the current environment is UNIX-based. | ||
* 检查当前环境是否为基于 UNIX 的系统。 | ||
* | ||
* @returns {boolean} Returns true if the current environment is UNIX-based, otherwise returns false. | ||
* 如果当前环境为基于 UNIX 的系统,则返回 true;否则返回 false。 | ||
*/ | ||
export function isUnix(): boolean { | ||
return detectOperatingSystem() === OperatingSystem.UNIX; | ||
} | ||
|
||
/** | ||
* Checks if the current environment is Linux. | ||
* 检查当前环境是否为 Linux。 | ||
* | ||
* @returns {boolean} Returns true if the current environment is Linux, otherwise returns false. | ||
* 如果当前环境为 Linux,则返回 true;否则返回 false。 | ||
*/ | ||
export function isLinux(): boolean { | ||
return detectOperatingSystem() === OperatingSystem.Linux; | ||
} |
3c62595
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
celeris-web – ./apps/admin
celeris-web-git-master-kirklin.vercel.app
celeris-web-kirklin.vercel.app
celeris-web.vercel.app
3c62595
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
celeris-web-api – ./services/admin
celeris-web-api-git-master-kirklin.vercel.app
celeris-web-api.vercel.app
celeris-web-api-kirklin.vercel.app